mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Use PYENV_DEACTIVATE to store which virtualenv has been deactivated (#32)
This commit is contained in:
@@ -75,6 +75,16 @@ if [ -z "$no_shell" ]; then
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
|
||||
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
|
||||
fish )
|
||||
cat <<EOS
|
||||
set -e PYENV_DEACTIVATE;
|
||||
. "$(pyenv-prefix "${versions}")/bin/activate.fish";
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
unset PYENV_DEACTIVATE;
|
||||
source "$(pyenv-prefix "${versions}")/bin/activate";
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -11,12 +11,26 @@ set -e
|
||||
|
||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||
case "$shell" in
|
||||
fish ) echo "functions -q deactivate; and deactivate;";;
|
||||
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
|
||||
fish )
|
||||
cat <<EOS
|
||||
if functions -q deactivate
|
||||
setenv PYENV_DEACTIVATE "\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
end;
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
if declare -f deactivate 1>/dev/null 2>&1; then
|
||||
export PYENV_DEACTIVATE="\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
fi;
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
|
||||
# Backward compatibility issue
|
||||
# https://github.com/yyuu/pyenv-virtualenv/issues/26
|
||||
echo "pyenv shell --unset"
|
||||
echo "pyenv shell --unset;"
|
||||
fi
|
||||
|
||||
@@ -63,53 +63,84 @@ if [ -z "$print" ]; then
|
||||
fi
|
||||
|
||||
case "$shell" in
|
||||
bash )
|
||||
fish )
|
||||
echo "setenv PYENV_VIRTUALENV_INIT 1;"
|
||||
;;
|
||||
* )
|
||||
echo "export PYENV_VIRTUALENV_INIT=1;"
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
if [ -n "\$VIRTUAL_ENV" ]
|
||||
if [ (pyenv version-name) = "system" ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
return 0
|
||||
end
|
||||
if [ "\$VIRTUAL_ENV" != (pyenv prefix) ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
eval (pyenv sh-activate 2>/dev/null); or true
|
||||
end
|
||||
else
|
||||
if [ "\$PYENV_DEACTIVATE" != (pyenv prefix) ]
|
||||
eval (pyenv sh-activate 2>/dev/null); or true
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
ksh )
|
||||
cat <<EOS
|
||||
function _pyenv_virtualenv_hook() {
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
_pyenv_virtualenv_hook() {
|
||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||
pyenv deactivate || true;
|
||||
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
|
||||
pyenv deactivate || true;
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$shell" != "fish" ]]; then
|
||||
cat <<EOS
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
|
||||
pyenv deactivate || true
|
||||
return 0
|
||||
fi
|
||||
if [ "x\$VIRTUAL_ENV" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv deactivate || true
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
else
|
||||
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
EOS
|
||||
|
||||
case "$shell" in
|
||||
bash )
|
||||
cat <<EOS
|
||||
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
|
||||
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
fish )
|
||||
zsh )
|
||||
cat <<EOS
|
||||
setenv PYENV_VIRTUALENV_INIT 1;
|
||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
if [ (pyenv version-name) = "system" ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
else if [ "\$VIRTUAL_ENV" != (pyenv prefix) ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
eval (pyenv sh-activate 2>/dev/null); or true
|
||||
end
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
zsh )
|
||||
cat <<EOS
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
_pyenv_virtualenv_hook() {
|
||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||
pyenv deactivate || true
|
||||
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
|
||||
pyenv deactivate || true
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
typeset -a precmd_functions
|
||||
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
|
||||
precmd_functions+=_pyenv_virtualenv_hook;
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
* )
|
||||
# FIXME: what should i do here??
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -22,7 +22,8 @@ setup() {
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||
unset PYENV_DEACTIVATE;
|
||||
source "${PYENV_ROOT}/versions/venv/bin/activate";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -42,7 +43,8 @@ EOS
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv";
|
||||
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||
unset PYENV_DEACTIVATE;
|
||||
source "${PYENV_ROOT}/versions/venv/bin/activate";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -61,7 +63,8 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||
set -e PYENV_DEACTIVATE;
|
||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -81,7 +84,8 @@ EOS
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv";
|
||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||
set -e PYENV_DEACTIVATE;
|
||||
. "${PYENV_ROOT}/versions/venv/bin/activate.fish";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -99,7 +103,8 @@ EOS
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv27";
|
||||
source "${PYENV_ROOT}/versions/venv27/bin/activate"
|
||||
unset PYENV_DEACTIVATE;
|
||||
source "${PYENV_ROOT}/versions/venv27/bin/activate";
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -117,7 +122,8 @@ EOS
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
pyenv shell "venv27";
|
||||
source "${PYENV_ROOT}/versions/venv27/bin/activate"
|
||||
unset PYENV_DEACTIVATE;
|
||||
source "${PYENV_ROOT}/versions/venv27/bin/activate";
|
||||
EOS
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ setup() {
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
|
||||
if declare -f deactivate 1>/dev/null 2>&1; then
|
||||
export PYENV_DEACTIVATE="\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
fi;
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -24,8 +27,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
|
||||
pyenv shell --unset
|
||||
if declare -f deactivate 1>/dev/null 2>&1; then
|
||||
export PYENV_DEACTIVATE="\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
fi;
|
||||
pyenv shell --unset;
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -36,7 +42,10 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
functions -q deactivate; and deactivate;
|
||||
if functions -q deactivate
|
||||
setenv PYENV_DEACTIVATE "\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
end;
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -47,8 +56,11 @@ EOS
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
functions -q deactivate; and deactivate;
|
||||
pyenv shell --unset
|
||||
if functions -q deactivate
|
||||
setenv PYENV_DEACTIVATE "\$VIRTUAL_ENV";
|
||||
deactivate;
|
||||
end;
|
||||
pyenv shell --unset;
|
||||
EOS
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,22 @@ load test_helper
|
||||
run pyenv-virtualenv-init - bash
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export PYENV_VIRTUALENV_INIT=1;
|
||||
_pyenv_virtualenv_hook() {
|
||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||
pyenv deactivate || true;
|
||||
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
|
||||
pyenv deactivate || true;
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
|
||||
pyenv deactivate || true
|
||||
return 0
|
||||
fi
|
||||
if [ "x\$VIRTUAL_ENV" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv deactivate || true
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
else
|
||||
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
|
||||
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
|
||||
@@ -50,12 +58,20 @@ EOS
|
||||
assert_output <<EOS
|
||||
setenv PYENV_VIRTUALENV_INIT 1;
|
||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||
if [ -n "\$VIRTUAL_ENV" ]
|
||||
if [ (pyenv version-name) = "system" ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
else if [ "\$VIRTUAL_ENV" != (pyenv prefix) ]
|
||||
return 0
|
||||
end
|
||||
if [ "\$VIRTUAL_ENV" != (pyenv prefix) ]
|
||||
eval (pyenv sh-deactivate); or true
|
||||
eval (pyenv sh-activate 2>/dev/null); or true
|
||||
end
|
||||
else
|
||||
if [ "\$PYENV_DEACTIVATE" != (pyenv prefix) ]
|
||||
eval (pyenv sh-activate 2>/dev/null); or true
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
}
|
||||
@@ -64,15 +80,23 @@ EOS
|
||||
run pyenv-virtualenv-init - zsh
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export PYENV_VIRTUALENV_INIT=1;
|
||||
_pyenv_virtualenv_hook() {
|
||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||
if [ -n "\$VIRTUAL_ENV" ]; then
|
||||
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
|
||||
pyenv deactivate || true
|
||||
elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
|
||||
return 0
|
||||
fi
|
||||
if [ "x\$VIRTUAL_ENV" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv deactivate || true
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
else
|
||||
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
|
||||
pyenv activate 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
};
|
||||
typeset -a precmd_functions
|
||||
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
|
||||
precmd_functions+=_pyenv_virtualenv_hook;
|
||||
|
||||
Reference in New Issue
Block a user