mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-11 21:13:52 -05:00
Merge branch 'issue26'
This commit is contained in:
@@ -33,6 +33,12 @@ if [ -z "$versions" ]; then
|
|||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
fi
|
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
|
if [ "${#versions[@]}" -gt 1 ]; then
|
||||||
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
|
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ set -e
|
|||||||
|
|
||||||
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
||||||
case "$shell" in
|
case "$shell" in
|
||||||
fish ) echo "functions -q deactivate; and deactivate";;
|
fish ) echo "functions -q deactivate; and deactivate;";;
|
||||||
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
|
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
|
||||||
|
# Backward compatibility issue
|
||||||
|
# https://github.com/yyuu/pyenv-virtualenv/issues/26
|
||||||
|
echo "pyenv shell --unset"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ fi
|
|||||||
case "$shell" in
|
case "$shell" in
|
||||||
bash )
|
bash )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
_pyenv_virtualenv_hook() {
|
_pyenv_virtualenv_hook() {
|
||||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||||
pyenv deactivate || true;
|
pyenv deactivate || true;
|
||||||
@@ -80,6 +81,7 @@ EOS
|
|||||||
;;
|
;;
|
||||||
fish )
|
fish )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
|
setenv PYENV_VIRTUALENV_INIT=1;
|
||||||
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
function _pyenv_virtualenv_hook --on-event fish_prompt;
|
||||||
if [ (pyenv version-name) = "system" ]
|
if [ (pyenv version-name) = "system" ]
|
||||||
eval (pyenv sh-deactivate); or true
|
eval (pyenv sh-deactivate); or true
|
||||||
@@ -92,6 +94,7 @@ EOS
|
|||||||
;;
|
;;
|
||||||
zsh )
|
zsh )
|
||||||
cat <<EOS
|
cat <<EOS
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
_pyenv_virtualenv_hook() {
|
_pyenv_virtualenv_hook() {
|
||||||
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
if [[ "\$(pyenv version-name)" == "system" ]]; then
|
||||||
pyenv deactivate || true
|
pyenv deactivate || true
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "activate virtualenv from current version" {
|
@test "activate virtualenv from current version" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
|
|
||||||
stub pyenv-version-name "echo venv"
|
stub pyenv-version-name "echo venv"
|
||||||
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
@@ -24,7 +26,29 @@ source "${PYENV_ROOT}/versions/venv/bin/activate"
|
|||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from current version (without pyenv-virtualenv-init)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=
|
||||||
|
|
||||||
|
stub pyenv-version-name "echo venv"
|
||||||
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
|
||||||
|
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv";
|
||||||
|
source "${PYENV_ROOT}/versions/venv/bin/activate"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
@test "activate virtualenv from current version (fish)" {
|
@test "activate virtualenv from current version (fish)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
|
|
||||||
stub pyenv-version-name "echo venv"
|
stub pyenv-version-name "echo venv"
|
||||||
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
@@ -41,7 +65,47 @@ EOS
|
|||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from current version (fish) (without pyenv-virtualenv-init)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=
|
||||||
|
|
||||||
|
stub pyenv-version-name "echo venv"
|
||||||
|
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
|
||||||
|
|
||||||
|
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
|
||||||
|
|
||||||
|
unstub pyenv-version-name
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv";
|
||||||
|
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
@test "activate virtualenv from command-line argument" {
|
@test "activate virtualenv from command-line argument" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
|
|
||||||
|
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
|
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
|
|
||||||
|
run pyenv-sh-activate "venv27"
|
||||||
|
|
||||||
|
unstub pyenv-virtualenv-prefix
|
||||||
|
unstub pyenv-prefix
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
pyenv shell "venv27";
|
||||||
|
source "${PYENV_ROOT}/versions/venv27/bin/activate"
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "activate virtualenv from command-line argument (without pyenv-virtualenv-init)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=
|
||||||
|
|
||||||
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
|
||||||
|
|
||||||
|
|||||||
@@ -7,20 +7,48 @@ setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "deactivate virtualenv" {
|
@test "deactivate virtualenv" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
|
|
||||||
PYENV_SHELL="bash" run pyenv-sh-deactivate
|
PYENV_SHELL="bash" run pyenv-sh-deactivate
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
assert_output <<EOS
|
||||||
declare -f deactivate 1>/dev/null 2>&1 && deactivate
|
declare -f deactivate 1>/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 <<EOS
|
||||||
|
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
|
||||||
|
pyenv shell --unset
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "deactivate virtualenv (fish)" {
|
@test "deactivate virtualenv (fish)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=1
|
||||||
|
|
||||||
PYENV_SHELL="fish" run pyenv-sh-deactivate
|
PYENV_SHELL="fish" run pyenv-sh-deactivate
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_output <<EOS
|
assert_output <<EOS
|
||||||
functions -q deactivate; and deactivate
|
functions -q deactivate; and deactivate;
|
||||||
|
EOS
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "deactivate virtualenv (fish) (without pyenv-virtualenv-init)" {
|
||||||
|
export PYENV_VIRTUALENV_INIT=
|
||||||
|
|
||||||
|
PYENV_SHELL="fish" run pyenv-sh-deactivate
|
||||||
|
|
||||||
|
assert_success
|
||||||
|
assert_output <<EOS
|
||||||
|
functions -q deactivate; and deactivate;
|
||||||
|
pyenv shell --unset
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user