-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathactivate-env.sh
More file actions
executable file
·59 lines (46 loc) · 1.22 KB
/
activate-env.sh
File metadata and controls
executable file
·59 lines (46 loc) · 1.22 KB
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
#!/usr/bin/env bash
set -o nounset
set -o errexit
set -o pipefail
if [ "$#" -ne 1 ]; then
echo 'Invalid number of arguments'
echo "Usage: ./activate-env.sh <envTarball>"
exit 1
fi
_unpackEnv() {
local _envTarball=$1
local _envFolder=$2
if ! [[ -f $_envTarball ]]; then
echo "Environment tarball not found at '$_envTarball'"
return
fi
echo "--> Unpacking environment at $_envTarball..."
mkdir -p $_envFolder
tar -zxf "$_envTarball" -C $_envFolder
}
_activateEnv() {
local _envFolder=$1
local _activate="$_envFolder/bin/activate"
if ! [[ -f $_activate ]]; then
echo "Environment not found at '$_envFolder'"
return
fi
echo "--> Sourcing new environment at $_envFolder..."
# Need to disable unbound errors for activate
set +u
source $_activate 1> /dev/null
set -u
echo "--> Calling conda-unpack..."
conda-unpack 1> /dev/null
echo "--> Disabling user-installed packages..."
# https://github.com/conda/conda/issues/448#issuecomment-195848539
export PYTHONNOUSERSITE=True
}
_main() {
local _envTarball=$1
local _envName=$(basename "${_envTarball%.tar.gz}")
local _envFolder="./envs/$_envName"
_unpackEnv $_envTarball $_envFolder
_activateEnv $_envFolder
}
_main $1