2015-12-19 00:45:17 +01:00
|
|
|
# Initialization: activate autoenv or report its absence
|
2015-10-02 01:29:59 +02:00
|
|
|
() {
|
2015-12-19 00:45:17 +01:00
|
|
|
local d autoenv_dir install_locations
|
2015-10-02 01:29:59 +02:00
|
|
|
if ! type autoenv_init >/dev/null; then
|
2015-12-19 00:45:17 +01:00
|
|
|
# Check if activate.sh is in $PATH
|
|
|
|
if (( $+commands[activate.sh] )); then
|
|
|
|
autoenv_dir="${commands[activate.sh]:h}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Locate autoenv installation
|
|
|
|
if [[ -z $autoenv_dir ]]; then
|
|
|
|
install_locations=(
|
|
|
|
~/.autoenv
|
|
|
|
~/.local/bin
|
|
|
|
/usr/local/opt/autoenv
|
|
|
|
/usr/local/bin
|
|
|
|
/usr/share/autoenv-git
|
|
|
|
~/Library/Python/bin
|
|
|
|
)
|
|
|
|
for d ( $install_locations ); do
|
|
|
|
if [[ -e $d/activate.sh ]]; then
|
|
|
|
autoenv_dir=$d
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Look for Homebrew path as a last resort
|
|
|
|
if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
|
|
|
|
d=$(brew --prefix)/opt/autoenv
|
2015-10-02 01:29:59 +02:00
|
|
|
if [[ -e $d/activate.sh ]]; then
|
|
|
|
autoenv_dir=$d
|
|
|
|
fi
|
2015-12-19 00:45:17 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Complain if autoenv is not installed
|
2015-10-02 01:29:59 +02:00
|
|
|
if [[ -z $autoenv_dir ]]; then
|
|
|
|
cat <<END >&2
|
|
|
|
-------- AUTOENV ---------
|
|
|
|
Could not locate autoenv installation.
|
|
|
|
Please check if autoenv is correctly installed.
|
|
|
|
In the meantime the autoenv plugin is DISABLED.
|
|
|
|
--------------------------
|
|
|
|
END
|
|
|
|
return 1
|
|
|
|
fi
|
2015-12-19 00:45:17 +01:00
|
|
|
# Load autoenv
|
2015-10-10 02:35:19 +02:00
|
|
|
source $autoenv_dir/activate.sh
|
2014-01-10 23:40:22 +01:00
|
|
|
fi
|
2015-10-02 01:29:59 +02:00
|
|
|
}
|
|
|
|
[[ $? != 0 ]] && return $?
|
2014-01-10 23:40:22 +01:00
|
|
|
|
2013-01-25 11:58:55 +01:00
|
|
|
# The use_env call below is a reusable command to activate/create a new Python
|
|
|
|
# virtualenv, requiring only a single declarative line of code in your .env files.
|
|
|
|
# It only performs an action if the requested virtualenv is not the current one.
|
2014-01-10 23:40:22 +01:00
|
|
|
|
2013-01-25 11:58:55 +01:00
|
|
|
use_env() {
|
2015-12-19 00:45:17 +01:00
|
|
|
local venv
|
|
|
|
venv="$1"
|
|
|
|
if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
|
|
|
|
if workon | grep -q "$venv"; then
|
|
|
|
workon "$venv"
|
|
|
|
else
|
|
|
|
echo -n "Create virtualenv $venv now? (Yn) "
|
|
|
|
read answer
|
|
|
|
if [[ "$answer" == "Y" ]]; then
|
|
|
|
mkvirtualenv "$venv"
|
|
|
|
fi
|
2013-01-25 11:58:55 +01:00
|
|
|
fi
|
2015-12-19 00:45:17 +01:00
|
|
|
fi
|
2013-01-25 11:58:55 +01:00
|
|
|
}
|