-
Notifications
You must be signed in to change notification settings - Fork 11
/
.envrc
91 lines (73 loc) · 2.28 KB
/
.envrc
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Handy script for activating the local venv
# Can be sourced manually from a bash shell, or used with direnv ( https://direnv.net/ )
echo "Configuring shell for molflux:"
if [ -n "$ZSH_VERSION" ]; then
_SOURCE_SHELL=zsh
_SCRIPT_DIR="$( cd "$( dirname "${(%):-%N}" )" &> /dev/null && pwd )"
elif [ -n "$BASH_VERSION" ]; then
_SOURCE_SHELL=bash
_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
else
echo "Unsupported shell"
exit 1
fi
_VENV_DIR=${_SCRIPT_DIR}/.venv
echo "Detected $_SOURCE_SHELL"
echo "_VENV_DIR=$_VENV_DIR"
if [ -z "$CI" ]; then
: # no-op
else
echo "[!] Running in a CI pipeline - no virtual environment needed."
return
fi
if [ -d "${_VENV_DIR}" ]; then
echo "[+] Found virtual environment: ${_VENV_DIR}"
else
echo "[!] Virtual environment not found: ${_VENV_DIR}"
echo "[?] Have you tried running a init_{python,conda}_venv.sh script first?"
return
fi
if [ -z "$CONDA_DEFAULT_ENV" ]; then
echo "[+] Detected base python distribution"
_PYTHON=1
else
echo "[+] Detected base anaconda python distribution"
export PIP_REQUIRE_VIRTUALENV=false
_CONDA=1
fi
if [ "$_PYTHON" ]; then
if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "darwin"* ]]; then
_ACTIVATE="${_VENV_DIR}/bin/activate"
elif [[ "$OSTYPE" == "msys" ]]; then
_ACTIVATE="${_VENV_DIR}/Scripts/activate"
fi
if [ -f "${_ACTIVATE}" ]; then
echo "[+] Activating virtual environment..."
source "${_ACTIVATE}"
else
echo "[!] Could not find virtual environment activation script: ${_ACTIVATE}"
fi
fi
if [ "$_CONDA" ]; then
echo "[+] Activating virtual environment..."
# https://github.com/conda/conda/issues/7980
_CONDA_PATH=$(conda info | grep -i 'base environment' | awk '{print $4}')
source "${_CONDA_PATH}/etc/profile.d/conda.sh"
conda activate "${_VENV_DIR}"
fi
# Activate nox autocompletion
echo "[+] Activating shell autocompletions..."
if [[ "$_SOURCE_SHELL" == "zsh" ]]; then
eval "$(pip completion --zsh)"
else
eval "$(pip completion --bash)"
eval "$(register-python-argcomplete nox)"
fi
echo "Default Python is now $(which python)"
unset _SCRIPT_DIR
unset _VENV_DIR
unset _PYTHON
unset _CONDA
unset _CONDA_PATH
unset _ACTIVATE
unset _SOURCE_SHELL