mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-14 06:23:52 -05:00
activate/deactivate anaconda/miniconda envs
This commit is contained in:
@@ -69,6 +69,29 @@ if ! pyenv-virtualenv-prefix "${versions}" 1>/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
shell="${PYENV_SHELL:-${SHELL##*/}}"
|
||||
prefix="$(pyenv-prefix "${versions}")"
|
||||
|
||||
unset conda_env
|
||||
|
||||
if [ -f "${prefix}/bin/conda" ]; then
|
||||
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
|
||||
case "$shell" in
|
||||
bash )
|
||||
conda_env="${prefix##*/envs/}"
|
||||
;;
|
||||
zsh )
|
||||
conda_env="${prefix##*/envs/}"
|
||||
;;
|
||||
* )
|
||||
echo "false"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Display setup instruction, if pyenv-virtualenv has not been initialized.
|
||||
# if 'pyenv virtualenv-init -' is not found in "$profile"
|
||||
@@ -94,20 +117,29 @@ if [ -z "$no_shell" ]; then
|
||||
esac
|
||||
fi
|
||||
|
||||
prefix="$(pyenv-prefix "${versions}")"
|
||||
case "$shell" in
|
||||
fish )
|
||||
if [ -n "${conda_env}" ]; then
|
||||
# anaconda/miniconda
|
||||
cat <<EOS
|
||||
unset PYENV_DEACTIVATE;
|
||||
export PYENV_ACTIVATE="${prefix}";
|
||||
. "${prefix%/envs/*}/bin/activate" "${versions##*/}"
|
||||
EOS
|
||||
else
|
||||
# virtualenv/pyvenv
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
set -e PYENV_DEACTIVATE;
|
||||
setenv PYENV_ACTIVATE "${prefix}";
|
||||
. "${prefix}/bin/activate.fish";
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
unset PYENV_DEACTIVATE;
|
||||
export PYENV_ACTIVATE="${prefix}";
|
||||
. "${prefix}/bin/activate";
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -28,17 +28,43 @@ while [ $# -gt 0 ]; do
|
||||
done
|
||||
|
||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "if functions -q deactivate;"
|
||||
;;
|
||||
* )
|
||||
echo "if declare -f deactivate 1>/dev/null 2>&1; then"
|
||||
;;
|
||||
esac
|
||||
|
||||
prefix="${PYENV_ACTIVATE:-${VIRTUAL_ENV}}"
|
||||
|
||||
unset conda_env
|
||||
|
||||
if [ -f "${prefix}/bin/conda" ]; then
|
||||
if [[ "${prefix}" != "${prefix%/envs/*}" ]]; then
|
||||
case "$shell" in
|
||||
bash )
|
||||
conda_env="${prefix##*/envs/}"
|
||||
;;
|
||||
zsh )
|
||||
conda_env="${prefix##*/envs/}"
|
||||
;;
|
||||
* )
|
||||
echo "false"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${conda_env}" ]; then
|
||||
echo "if [ -f \"${prefix%/envs/*}/bin/deactivate\" ]; then"
|
||||
else
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "if functions -q deactivate;"
|
||||
;;
|
||||
* )
|
||||
echo "if declare -f deactivate 1>/dev/null 2>&1; then"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;"
|
||||
fi
|
||||
@@ -57,24 +83,33 @@ if [ -n "${PYENV_ACTIVATE_SHELL}" ]; then
|
||||
esac
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
if [ -n "${conda_env}" ]; then
|
||||
cat <<EOS
|
||||
export PYENV_DEACTIVATE="$prefix";
|
||||
unset PYENV_ACTIVATE;
|
||||
. "${prefix%/envs/*}/bin/deactivate" "${prefix##*/envs/}";
|
||||
else
|
||||
EOS
|
||||
else
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
setenv PYENV_DEACTIVATE "$prefix";
|
||||
set -e PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else;
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
export PYENV_DEACTIVATE="$prefix";
|
||||
unset PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ -z "$NOERROR" ]; then
|
||||
echo " echo \"pyenv-virtualenv: no virtualenv has been activated.\" 1>&2;"
|
||||
|
||||
Reference in New Issue
Block a user