From a3c86f013b633fa5f950eed2ad3116c924d0b25d Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Fri, 11 Jul 2014 20:24:58 +0900 Subject: [PATCH] Deactivate virtualenv even if it has been activated manually --- bin/pyenv-sh-deactivate | 8 +++++--- test/deactivate.bats | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/bin/pyenv-sh-deactivate b/bin/pyenv-sh-deactivate index 6c81115..48446c0 100755 --- a/bin/pyenv-sh-deactivate +++ b/bin/pyenv-sh-deactivate @@ -37,8 +37,10 @@ fish ) ;; esac +prefix="${PYENV_ACTIVATE:-${VIRTUAL_ENV}}" + if [ -n "$VERBOSE" ]; then - echo " echo \"pyenv-virtualenv: deactivate ${PYENV_ACTIVATE##*/}\" 1>&2;" + echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;" fi if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then @@ -50,7 +52,7 @@ fi case "$shell" in fish ) cat </dev/null 2>&1; then + export PYENV_DEACTIVATE="$VIRTUAL_ENV"; + unset PYENV_ACTIVATE; + deactivate; +else + echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2; + false; +fi; +EOS +} + @test "deactivate virtualenv (fish)" { export PYENV_VIRTUALENV_INIT=1 export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv" @@ -177,6 +196,26 @@ else; end; EOS } + +@test "deactivate virtualenv which has been activated manually (fish)" { + export PYENV_VIRTUALENV_INIT=1 + export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv" + + PYENV_SHELL="fish" run pyenv-sh-deactivate + + assert_success + assert_output <&2; + false; +end; +EOS +} + @test "should fail if deactivate is invoked as a command" { run pyenv-deactivate