Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use `PYENV_DEACTIVATE` to store which virtualenv has been deactivated #33

Merged
merged 1 commit into from

1 participant

@yyuu
Owner

This should fix #32.

@yyuu yyuu merged commit c68685a into master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@yyuu yyuu deleted the restore-deactivate branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2014
This page is out of date. Refresh to see the latest.
View
14 bin/pyenv-sh-activate
@@ -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
View
20 bin/pyenv-sh-deactivate
@@ -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
View
99 bin/pyenv-virtualenv-init
@@ -63,53 +63,84 @@ if [ -z "$print" ]; then
fi
case "$shell" in
-bash )
- 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
-};
-if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
- PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
-fi
-EOS
+fish )
+ echo "setenv PYENV_VIRTUALENV_INIT 1;"
+ ;;
+* )
+ echo "export PYENV_VIRTUALENV_INIT=1;"
;;
+esac
+
+case "$shell" in
fish )
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
+ 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
;;
-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
+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
+ ;;
+ zsh )
+ cat <<EOS
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
+ ;;
+ * )
+ # FIXME: what should i do here??
+ ;;
+ esac
+fi
View
18 test/activate.bats
@@ -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
}
View
24 test/deactivate.bats
@@ -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
}
View
60 test/init.bats
@@ -29,13 +29,21 @@ 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;
- pyenv activate 2>/dev/null || 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
@@ -50,11 +58,19 @@ EOS
assert_output <<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
+ 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
@@ -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
- pyenv deactivate || true
- elif [[ "\$VIRTUAL_ENV" != "\$(pyenv prefix)" ]]; then
- pyenv deactivate || true
- pyenv activate 2>/dev/null || 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
-}
+};
typeset -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook;
Something went wrong with that request. Please try again.