From 191e806ba9983d53c7e3bac31bce75b6a3ee9136 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 23 Dec 2014 11:21:52 +0900 Subject: [PATCH] shell version set in `activate` should be unset in `deactivate` (#61) --- bin/pyenv-sh-activate | 13 ++++++++++++- bin/pyenv-sh-deactivate | 14 +++++++++++--- test/activate.bats | 4 ++++ test/deactivate.bats | 34 +++++++++++++++++++--------------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 5b58efd..9af102f 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -41,8 +41,9 @@ while [ $# -gt 0 ]; do shift 1 done +no_shell= versions=("$@") -if [ -z "$versions" ]; then +if [ -z "${versions}" ]; then no_shell=1 OLDIFS="$IFS" IFS=: versions=($(pyenv-version-name)) @@ -97,6 +98,16 @@ fi if [ -z "$no_shell" ]; then echo "pyenv shell \"${versions}\";" + # shell version set in pyenv-sh-activate should be unset + # https://github.com/yyuu/pyenv-virtualenv/issues/61 + case "$shell" in + fish ) + echo "setenv PYENV_ACTIVATE_SHELL 1;" + ;; + * ) + echo "export PYENV_ACTIVATE_SHELL=1;" + ;; + esac fi prefix="$(pyenv-prefix "${versions}")" diff --git a/bin/pyenv-sh-deactivate b/bin/pyenv-sh-deactivate index 48446c0..725cc8d 100755 --- a/bin/pyenv-sh-deactivate +++ b/bin/pyenv-sh-deactivate @@ -43,10 +43,18 @@ if [ -n "$VERBOSE" ]; then echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;" fi -if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then - # Backward compatibility issue - # https://github.com/yyuu/pyenv-virtualenv/issues/26 +if [ -n "${PYENV_ACTIVATE_SHELL}" ]; then + # shell version set in pyenv-sh-activate should be unset + # https://github.com/yyuu/pyenv-virtualenv/issues/61 echo " pyenv shell --unset;" + case "$shell" in + fish ) + echo " set -e PYENV_ACTIVATE_SHELL;" + ;; + * ) + echo " unset PYENV_ACTIVATE_SHELL;" + ;; + esac fi case "$shell" in diff --git a/test/activate.bats b/test/activate.bats index 320447e..8e6165f 100644 --- a/test/activate.bats +++ b/test/activate.bats @@ -66,6 +66,7 @@ EOS assert_success assert_output </dev/null 2>&1; then pyenv shell --unset; + unset PYENV_ACTIVATE_SHELL; export PYENV_DEACTIVATE="$PYENV_ACTIVATE"; unset PYENV_ACTIVATE; deactivate; @@ -83,9 +84,9 @@ fi; EOS } -@test "deactivate virtualenv (without pyenv-virtualenv-init) (no-error)" { - export PYENV_VIRTUALENV_INIT= +@test "deactivate virtualenv (with shell activation) (no-error)" { export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv" + export PYENV_ACTIVATE_SHELL=1 PYENV_SHELL="bash" run pyenv-sh-deactivate --no-error @@ -93,6 +94,7 @@ EOS assert_output </dev/null 2>&1; then pyenv shell --unset; + unset PYENV_ACTIVATE_SHELL; export PYENV_DEACTIVATE="$PYENV_ACTIVATE"; unset PYENV_ACTIVATE; deactivate; @@ -103,8 +105,8 @@ EOS } @test "deactivate virtualenv which has been activated manually" { - export PYENV_VIRTUALENV_INIT=1 export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv" + export PYENV_ACTIVATE_SHELL= PYENV_SHELL="bash" run pyenv-sh-deactivate @@ -122,8 +124,8 @@ EOS } @test "deactivate virtualenv (fish)" { - export PYENV_VIRTUALENV_INIT=1 export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv" + export PYENV_ACTIVATE_SHELL= PYENV_SHELL="fish" run pyenv-sh-deactivate @@ -141,8 +143,8 @@ EOS } @test "deactivate virtualenv (fish) (no-error)" { - export PYENV_VIRTUALENV_INIT=1 export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv" + export PYENV_ACTIVATE_SHELL= PYENV_SHELL="fish" run pyenv-sh-deactivate --no-error @@ -158,9 +160,9 @@ end; EOS } -@test "deactivate virtualenv (fish) (without pyenv-virtualenv-init)" { - export PYENV_VIRTUALENV_INIT= +@test "deactivate virtualenv (fish) (with shell activation)" { export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv" + export PYENV_ACTIVATE_SHELL=1 PYENV_SHELL="fish" run pyenv-sh-deactivate @@ -168,6 +170,7 @@ EOS assert_output <