Remove PYENV_DEACTIVATE (fixes #121)

This means that pyenv-virtualenv will not allow manual deactivation of
virtualenv if pyenv-virtualenv-init is enabled. This must be acceptable
since the activation of virtualenv is just setting of environment
variables in current implementation.
This commit is contained in:
Yamashita, Yuu
2015-11-23 12:28:10 +00:00
parent f92a3a26c5
commit 5f87786adf
8 changed files with 33 additions and 74 deletions

View File

@@ -14,6 +14,10 @@
set -e
[ -n "$PYENV_DEBUG" ] && set -x
if [ -z "${PYENV_ROOT}" ]; then
PYENV_ROOT="$(pyenv-root)"
fi
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
@@ -66,7 +70,7 @@ fi
venv="${versions}"
# exit as success if some virtualenv outside from pyenv is already activated
if [ -n "${VIRTUAL_ENV}" ]; then
if [ -n "${VIRTUAL_ENV}" ] && [[ "${VIRTUAL_ENV}" == "${VIRTUAL_ENV#${PYENV_ROOT}/versions/}" ]]; then
if [ -z "${FORCE}" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: virtualenv \`${VIRTUAL_ENV}' is already activated" 1>&2
@@ -77,7 +81,7 @@ if [ -n "${VIRTUAL_ENV}" ]; then
fi
if ! pyenv-virtualenv-prefix "${venv}" 1>/dev/null 2>&1; then
if [ -z "$QUIET" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: version \`${venv}' is not a virtualenv" 1>&2
fi
echo "false"
@@ -89,7 +93,7 @@ fi
for version in "${versions[@]}"; do
if [[ "${version}" != "${venv}" ]]; then
if pyenv-virtualenv-prefix "${version}" 1>/dev/null 2>&1; then
if [ -z "$QUIET" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
fi
echo "false"
@@ -116,16 +120,6 @@ if [[ "${VIRTUAL_ENV}" == "${prefix}" ]]; then
fi
fi
if [[ "${PYENV_DEACTIVATE}" == "${prefix}" ]]; then
if [ -z "${FORCE}" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: \`${venv}' is marked deactivated. use \`pyenv activate --force ${venv}' to activate forcibly." 1>&2
fi
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"
if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
@@ -161,16 +155,10 @@ fi
# virtualenv/pyvenv
case "${shell}" in
fish )
cat <<EOS
set -e PYENV_DEACTIVATE;
setenv VIRTUAL_ENV "${prefix}";
EOS
echo "setenv VIRTUAL_ENV \"${prefix}\";"
;;
* )
cat <<EOS
unset PYENV_DEACTIVATE;
export VIRTUAL_ENV="${prefix}";
EOS
echo "export VIRTUAL_ENV=\"${prefix}\";"
;;
esac

View File

@@ -32,11 +32,13 @@ while [ $# -gt 0 ]; do
done
if [ -z "${VIRTUAL_ENV}" ]; then
if [ -z "$QUIET" ]; then
echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2
if [ -z "${FORCE}" ]; then
if [ -z "${QUIET}" ]; then
echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2
fi
echo "false"
exit 1
fi
echo "false"
exit 1
fi
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
@@ -72,20 +74,13 @@ fi
# virtualenv/pyvenv
case "${shell}" in
fish )
cat <<EOS
setenv PYENV_DEACTIVATE "${VIRTUAL_ENV}";
set -e VIRTUAL_ENV;
EOS
echo "set -e VIRTUAL_ENV;"
;;
* )
cat <<EOS
export PYENV_DEACTIVATE="${VIRTUAL_ENV}";
unset VIRTUAL_ENV;
EOS
echo "unset VIRTUAL_ENV;"
;;
esac
# anaconda/miniconda
if [ -n "${CONDA_DEFAULT_ENV}" ]; then
case "${shell}" in

View File

@@ -11,6 +11,10 @@
PYENV_VIRTUALENV_VERSION="20151103"
if [ -z "${PYENV_ROOT}" ]; then
PYENV_ROOT="$(pyenv-root)"
fi
set -e
[ -n "$PYENV_DEBUG" ] && set -x
@@ -19,10 +23,6 @@ if [ "$1" = "--complete" ]; then
exec pyenv-versions --bare
fi
if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv"
fi
unset PIP_REQUIRE_VENV
unset PIP_REQUIRE_VIRTUALENV
@@ -105,7 +105,7 @@ version() {
local version
if [ -n "$USE_PYVENV" ]; then
version="$(pyenv-which pyvenv 2>/dev/null || true)"
version="${version#$(pyenv-root)/versions/}"
version="${version#${PYENV_ROOT}/versions/}"
version="${version%/bin/pyvenv}"
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (pyvenv ${version:-unknown})"
else