-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit_conda_venv.sh
executable file
·39 lines (31 loc) · 1.4 KB
/
init_conda_venv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
if ! git rev-parse --git-dir > /dev/null 2>&1; then
: # This is not a valid git repository and will fail due to scm erroring, so tell the user
echo "You have not initialised a git repo. Please run ./init_git.sh first and try again"
exit
fi
_SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
pushd ${_SCRIPT_DIR} # cd to script directory
CONDA_OR_MAMBA=$(which mamba)
if [ -z $CONDA_OR_MAMBA ]; then
CONDA_OR_MAMBA=$(which conda)
fi
if [ -z $CONDA_OR_MAMBA ]; then
echo "No mamba or conda executable found."
exit
fi
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail
echo "Setting up virtualenv"
# Make sure to bypass a possible $PIP_REQUIRE_VIRTUALENV=true set by users
# This is because pip is unable to detect that it is inside conda's virtual environment - and would throw an error
env PIP_REQUIRE_VIRTUALENV=false ${CONDA_OR_MAMBA} env create -f environment.yml --prefix .venv
# temporary: former solution was to install pip-dependencies via conda-creation
# (this was specified in the environment file, but conda ignores constraint-argument this way,
# which leads to long build duration or even fails entirely.
env PIP_REQUIRE_VIRTUALENV=false ${CONDA_OR_MAMBA} \
run --prefix .venv \
pip install --no-cache-dir -e . \
--constraint pinned-versions.txt
popd # return to original directory
unset _SCRIPT_DIR