forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate
91 lines (79 loc) · 2.63 KB
/
activate
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
#!/bin/bash
# Determine the directory containing this script
if [[ -n $BASH_VERSION ]]; then
_SCRIPT_LOCATION=${BASH_SOURCE[0]}
SHELL="bash"
elif [[ -n $ZSH_VERSION ]]; then
_SCRIPT_LOCATION=${funcstack[1]}
SHELL="zsh"
else
echo "Only bash and zsh are supported"
return 1
fi
_CONDA_DIR=$(dirname "$_SCRIPT_LOCATION")
if [ $# -gt 1 ]; then
(>&2 echo "Error: did not expect more than one argument.")
(>&2 echo " (Got $@)")
return 1
fi
case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*)
EXT=".exe"
;;
*)
EXT=""
;;
esac
# Export whatever PS setting we have, so it is available to Python subprocesses
export PS1
# Ensure that this script is sourced, not executed
# Also note that errors are ignored as `activate foo` doesn't generate a bad
# value for $0 which would cause errors.
if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "activate" ]]; then
(>&2 echo "Error: activate must be sourced. Run 'source activate envname'
instead of 'activate envname'.
")
"$_CONDA_DIR/conda" ..activate $SHELL$EXT -h
exit 1
fi
"$_CONDA_DIR/conda" ..checkenv $SHELL$EXT "$@"
if (( $? != 0 )); then
return 1
fi
# Ensure we deactivate any scripts from the old env
# Note: this empties $@. Preserve a copy.
args=$@
source "$_CONDA_DIR/deactivate"
_NEW_PATH=$("$_CONDA_DIR/conda" ..activate $SHELL$EXT "$args")
if (( $? == 0 )); then
export CONDA_PATH_BACKUP="$PATH"
# export this to restore it upon deactivation
export CONDA_OLD_PS1=$PS1
export PATH="$_NEW_PATH"
# Get first path (should be full path prefix of our env)
# inner string extraction pulls off first path
# outer string removes /bin if present (on Unix)
firstpath=${PATH%%:*}
export CONDA_DEFAULT_ENV="$(echo ${firstpath} | sed "s|/bin$||")" &>/dev/null
# Legacy support: CONDA_DEFAULT_ENV used to be either env name or full path if given as path.
# CONDA_DEFAULT_ENV is now always full path.
# Keep CONDA_ENV_PATH around, and have it mirror CONDA_DEFAULT_ENV.
# Last date of change: 2016-04-18
export CONDA_ENV_PATH=$CONDA_DEFAULT_ENV
export PS1="$( "$_CONDA_DIR/conda" ..setps1 $SHELL$EXT "$args" )"
# Load any of the scripts found $PREFIX/etc/conda/activate.d AFTER activation
_CONDA_D="${CONDA_DEFAULT_ENV}/etc/conda/activate.d"
if [[ -d "$_CONDA_D" ]]; then
IFS=$(echo -en "\n\b")&>/dev/null && for f in $(find "$_CONDA_D" -iname "*.sh"); do source "$f"; done
fi
else
return $?
fi
if [[ -n $BASH_VERSION ]]; then
hash -r
elif [[ -n $ZSH_VERSION ]]; then
rehash
else
echo "Only bash and zsh are supported"
return 1
fi