Use PYENV_DEACTIVATE to store which virtualenv has been deactivated (#32)

This commit is contained in:
Yamashita Yuu
2014-06-30 22:40:59 +09:00
parent 7079cbe979
commit 08b4c94f85
6 changed files with 169 additions and 72 deletions

View File

@@ -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 File

@@ -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 File

@@ -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;