forked from sjain-stanford/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivate
More file actions
98 lines (85 loc) · 3.27 KB
/
Copy pathactivate
File metadata and controls
98 lines (85 loc) · 3.27 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
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
92
93
94
95
96
97
98
# This file must be used with "source bin/activate" *from bash*
# You cannot run it directly
# Variable passed to `bin/activate` by install command written into .bashrc during
# cache creation. Remove trailing slash from path for consistent path comparisons.
DOCKER_CACHE_BASE_DIR="$(realpath "$1")"
# Check if already activated to avoid double patching
if [ -n "${VIRTUAL_ENV:-}" ] && [ "${VIRTUAL_ENV}" = "${DOCKER_CACHE_BASE_DIR}/.cache/docker/venv" ]; then
# Already activated: skip overriding env variables and early return
# `return 0` tries to return from the script — this only works if the script is being sourced.
# `2>/dev/null` suppresses errors in case return is invalid (e.g., script is run, not sourced).
# If return fails, it falls back to `exit 0` to exit the script gracefully.
return 0 2>/dev/null || exit 0
fi
echo "[activate] Activating VENV from docker cache at '${DOCKER_CACHE_BASE_DIR}/.cache/docker'..."
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
if [ -n "${_OLD_VIRTUAL_LD_LIBRARY_PATH:-}" ] ; then
LD_LIBRARY_PATH="${_OLD_VIRTUAL_LD_LIBRARY_PATH:-}"
export LD_LIBRARY_PATH
unset _OLD_VIRTUAL_LD_LIBRARY_PATH
else
unset LD_LIBRARY_PATH
fi
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null
unset DOCKER_CACHE_DIR
unset THEROCK_DIR
unset VIRTUAL_ENV
unset VIRTUAL_ENV_PROMPT
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
# CAUTION: These directories need to be kept in sync with the `entrypoint.sh` script!!
export DOCKER_CACHE_DIR=${DOCKER_CACHE_BASE_DIR}/.cache/docker
export THEROCK_DIR=${DOCKER_CACHE_DIR}/therock
export VIRTUAL_ENV=${DOCKER_CACHE_DIR}/venv
# save old PATH and re-export
_OLD_VIRTUAL_PATH="${PATH}"
PATH="${VIRTUAL_ENV}/bin:${THEROCK_DIR}/bin:${PATH}"
export PATH
# save old LD_LIBRARY_PATH and re-export
if [ -n "${LD_LIBRARY_PATH:-}" ] ; then
_OLD_VIRTUAL_LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}"
LD_LIBRARY_PATH="${THEROCK_DIR}/lib:${LD_LIBRARY_PATH:-}"
else
LD_LIBRARY_PATH="${THEROCK_DIR}/lib"
fi
export LD_LIBRARY_PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1='(venv) '"${PS1:-}"
export PS1
VIRTUAL_ENV_PROMPT='(venv) '
export VIRTUAL_ENV_PROMPT
fi
# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null