Skip to content

Commit d9e3adc

Browse files
author
Yamashita Yuu
committed
Performe as same as before v20140614 if pyenv virtualenv-init is not configured (#26)
1 parent 4a6ef11 commit d9e3adc

File tree

5 files changed

+111
-4
lines changed

5 files changed

+111
-4
lines changed

bin/pyenv-sh-activate

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ if [ -z "$versions" ]; then
3333
IFS="$OLDIFS"
3434
fi
3535

36+
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
37+
# Backward compatibility issue
38+
# https://github.com/yyuu/pyenv-virtualenv/issues/26
39+
no_shell=
40+
fi
41+
3642
if [ "${#versions[@]}" -gt 1 ]; then
3743
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
3844
exit 1

bin/pyenv-sh-deactivate

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ set -e
1111

1212
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
1313
case "$shell" in
14-
fish ) echo "functions -q deactivate; and deactivate";;
15-
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
14+
fish ) echo "functions -q deactivate; and deactivate;";;
15+
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate;";;
1616
esac
17+
18+
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
19+
# Backward compatibility issue
20+
# https://github.com/yyuu/pyenv-virtualenv/issues/26
21+
echo "pyenv shell --unset"
22+
fi

bin/pyenv-virtualenv-init

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fi
6565
case "$shell" in
6666
bash )
6767
cat <<EOS
68+
export PYENV_VIRTUALENV_INIT=1
6869
_pyenv_virtualenv_hook() {
6970
if [[ "\$(pyenv version-name)" == "system" ]]; then
7071
pyenv deactivate || true;
@@ -80,6 +81,7 @@ EOS
8081
;;
8182
fish )
8283
cat <<EOS
84+
setenv PYENV_VIRTUALENV_INIT=1;
8385
function _pyenv_virtualenv_hook --on-event fish_prompt;
8486
if [ (pyenv version-name) = "system" ]
8587
eval (pyenv sh-deactivate); or true
@@ -92,6 +94,7 @@ EOS
9294
;;
9395
zsh )
9496
cat <<EOS
97+
export PYENV_VIRTUALENV_INIT=1
9598
_pyenv_virtualenv_hook() {
9699
if [[ "\$(pyenv version-name)" == "system" ]]; then
97100
pyenv deactivate || true

test/activate.bats

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ setup() {
88
}
99

1010
@test "activate virtualenv from current version" {
11+
export PYENV_VIRTUALENV_INIT=1
12+
1113
stub pyenv-version-name "echo venv"
1214
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
1315
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
@@ -24,7 +26,29 @@ source "${PYENV_ROOT}/versions/venv/bin/activate"
2426
EOS
2527
}
2628

29+
@test "activate virtualenv from current version (without pyenv-virtualenv-init)" {
30+
export PYENV_VIRTUALENV_INIT=
31+
32+
stub pyenv-version-name "echo venv"
33+
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
34+
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
35+
36+
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
37+
38+
unstub pyenv-version-name
39+
unstub pyenv-virtualenv-prefix
40+
unstub pyenv-prefix
41+
42+
assert_success
43+
assert_output <<EOS
44+
pyenv shell "venv";
45+
source "${PYENV_ROOT}/versions/venv/bin/activate"
46+
EOS
47+
}
48+
2749
@test "activate virtualenv from current version (fish)" {
50+
export PYENV_VIRTUALENV_INIT=1
51+
2852
stub pyenv-version-name "echo venv"
2953
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
3054
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
@@ -41,7 +65,47 @@ EOS
4165
EOS
4266
}
4367

68+
@test "activate virtualenv from current version (fish) (without pyenv-virtualenv-init)" {
69+
export PYENV_VIRTUALENV_INIT=
70+
71+
stub pyenv-version-name "echo venv"
72+
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
73+
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
74+
75+
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
76+
77+
unstub pyenv-version-name
78+
unstub pyenv-virtualenv-prefix
79+
unstub pyenv-prefix
80+
81+
assert_success
82+
assert_output <<EOS
83+
pyenv shell "venv";
84+
. "${PYENV_ROOT}/versions/venv/bin/activate.fish"
85+
EOS
86+
}
87+
4488
@test "activate virtualenv from command-line argument" {
89+
export PYENV_VIRTUALENV_INIT=1
90+
91+
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
92+
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
93+
94+
run pyenv-sh-activate "venv27"
95+
96+
unstub pyenv-virtualenv-prefix
97+
unstub pyenv-prefix
98+
99+
assert_success
100+
assert_output <<EOS
101+
pyenv shell "venv27";
102+
source "${PYENV_ROOT}/versions/venv27/bin/activate"
103+
EOS
104+
}
105+
106+
@test "activate virtualenv from command-line argument (without pyenv-virtualenv-init)" {
107+
export PYENV_VIRTUALENV_INIT=
108+
45109
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
46110
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
47111

test/deactivate.bats

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,48 @@ setup() {
77
}
88

99
@test "deactivate virtualenv" {
10+
export PYENV_VIRTUALENV_INIT=1
11+
12+
PYENV_SHELL="bash" run pyenv-sh-deactivate
13+
14+
assert_success
15+
assert_output <<EOS
16+
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
17+
EOS
18+
}
19+
20+
@test "deactivate virtualenv (without pyenv-virtualenv-init)" {
21+
export PYENV_VIRTUALENV_INIT=
22+
1023
PYENV_SHELL="bash" run pyenv-sh-deactivate
1124

1225
assert_success
1326
assert_output <<EOS
14-
declare -f deactivate 1>/dev/null 2>&1 && deactivate
27+
declare -f deactivate 1>/dev/null 2>&1 && deactivate;
28+
pyenv shell --unset
1529
EOS
1630
}
1731

1832
@test "deactivate virtualenv (fish)" {
33+
export PYENV_VIRTUALENV_INIT=1
34+
35+
PYENV_SHELL="fish" run pyenv-sh-deactivate
36+
37+
assert_success
38+
assert_output <<EOS
39+
functions -q deactivate; and deactivate;
40+
EOS
41+
}
42+
43+
@test "deactivate virtualenv (fish) (without pyenv-virtualenv-init)" {
44+
export PYENV_VIRTUALENV_INIT=
45+
1946
PYENV_SHELL="fish" run pyenv-sh-deactivate
2047

2148
assert_success
2249
assert_output <<EOS
23-
functions -q deactivate; and deactivate
50+
functions -q deactivate; and deactivate;
51+
pyenv shell --unset
2452
EOS
2553
}
2654

0 commit comments

Comments
 (0)