From d9e3adc1085d5f8ddc525088bf8532a3c080f971 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Sun, 15 Jun 2014 16:32:25 +0900 Subject: [PATCH] Performe as same as before v20140614 if `pyenv virtualenv-init` is not configured (#26) --- bin/pyenv-sh-activate | 6 ++++ bin/pyenv-sh-deactivate | 10 ++++-- bin/pyenv-virtualenv-init | 3 ++ test/activate.bats | 64 +++++++++++++++++++++++++++++++++++++++ test/deactivate.bats | 32 ++++++++++++++++++-- 5 files changed, 111 insertions(+), 4 deletions(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 0aff9eba..547c6bba 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -33,6 +33,12 @@ if [ -z "$versions" ]; then IFS="$OLDIFS" fi +if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then + # Backward compatibility issue + # https://github.com/yyuu/pyenv-virtualenv/issues/26 + no_shell= +fi + if [ "${#versions[@]}" -gt 1 ]; then echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2 exit 1 diff --git a/bin/pyenv-sh-deactivate b/bin/pyenv-sh-deactivate index 8cc75683..38b08fb9 100755 --- a/bin/pyenv-sh-deactivate +++ b/bin/pyenv-sh-deactivate @@ -11,6 +11,12 @@ 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 ) echo "functions -q deactivate; and deactivate;";; +* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";; esac + +if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then + # Backward compatibility issue + # https://github.com/yyuu/pyenv-virtualenv/issues/26 + echo "pyenv shell --unset" +fi diff --git a/bin/pyenv-virtualenv-init b/bin/pyenv-virtualenv-init index 20f8744f..ae5b9f15 100755 --- a/bin/pyenv-virtualenv-init +++ b/bin/pyenv-virtualenv-init @@ -65,6 +65,7 @@ fi case "$shell" in bash ) cat </dev/null 2>&1 && deactivate; +EOS +} + +@test "deactivate virtualenv (without pyenv-virtualenv-init)" { + export PYENV_VIRTUALENV_INIT= + PYENV_SHELL="bash" run pyenv-sh-deactivate assert_success assert_output </dev/null 2>&1 && deactivate +declare -f deactivate 1>/dev/null 2>&1 && deactivate; +pyenv shell --unset EOS } @test "deactivate virtualenv (fish)" { + export PYENV_VIRTUALENV_INIT=1 + + PYENV_SHELL="fish" run pyenv-sh-deactivate + + assert_success + assert_output <