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
|
fi
|
||||||
|
|
||||||
shell="${PYENV_SHELL:-${SHELL##*/}}"
|
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.
|
# Display setup instruction, if pyenv-virtualenv has not been initialized.
|
||||||
# if 'pyenv virtualenv-init -' is not found in "$profile"
|
# if 'pyenv virtualenv-init -' is not found in "$profile"
|
||||||
@@ -94,20 +117,29 @@ if [ -z "$no_shell" ]; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prefix="$(pyenv-prefix "${versions}")"
|
if [ -n "${conda_env}" ]; then
|
||||||
case "$shell" in
|
# anaconda/miniconda
|
||||||
fish )
|
|
||||||
cat <<EOS
|
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;
|
set -e PYENV_DEACTIVATE;
|
||||||
setenv PYENV_ACTIVATE "${prefix}";
|
setenv PYENV_ACTIVATE "${prefix}";
|
||||||
. "${prefix}/bin/activate.fish";
|
. "${prefix}/bin/activate.fish";
|
||||||
EOS
|
EOS
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
unset PYENV_DEACTIVATE;
|
unset PYENV_DEACTIVATE;
|
||||||
export PYENV_ACTIVATE="${prefix}";
|
export PYENV_ACTIVATE="${prefix}";
|
||||||
. "${prefix}/bin/activate";
|
. "${prefix}/bin/activate";
|
||||||
EOS
|
EOS
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
fi
|
||||||
|
|||||||
@@ -28,17 +28,43 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
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}}"
|
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
|
if [ -n "$VERBOSE" ]; then
|
||||||
echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;"
|
echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;"
|
||||||
fi
|
fi
|
||||||
@@ -57,24 +83,33 @@ if [ -n "${PYENV_ACTIVATE_SHELL}" ]; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$shell" in
|
if [ -n "${conda_env}" ]; then
|
||||||
fish )
|
|
||||||
cat <<EOS
|
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";
|
setenv PYENV_DEACTIVATE "$prefix";
|
||||||
set -e PYENV_ACTIVATE;
|
set -e PYENV_ACTIVATE;
|
||||||
deactivate;
|
deactivate;
|
||||||
else;
|
else;
|
||||||
EOS
|
EOS
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
export PYENV_DEACTIVATE="$prefix";
|
export PYENV_DEACTIVATE="$prefix";
|
||||||
unset PYENV_ACTIVATE;
|
unset PYENV_ACTIVATE;
|
||||||
deactivate;
|
deactivate;
|
||||||
else
|
else
|
||||||
EOS
|
EOS
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$NOERROR" ]; then
|
if [ -z "$NOERROR" ]; then
|
||||||
echo " echo \"pyenv-virtualenv: no virtualenv has been activated.\" 1>&2;"
|
echo " echo \"pyenv-virtualenv: no virtualenv has been activated.\" 1>&2;"
|
||||||
|
|||||||
Reference in New Issue
Block a user