Skip to content

Commit 3152718

Browse files
committed
Merge branch 'restore-prompt'
2 parents c1b9238 + ee18ffa commit 3152718

File tree

6 files changed

+101
-15
lines changed

6 files changed

+101
-15
lines changed

bin/pyenv-sh-activate

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
set -e
1515
[ -n "$PYENV_DEBUG" ] && set -x
1616

17-
unset DEACTIVATE
1817
unset FORCE
1918
unset QUIET
2019
unset VERBOSE
@@ -26,18 +25,14 @@ while [ $# -gt 0 ]; do
2625
echo --unset
2726
exec pyenv-virtualenvs --bare
2827
;;
29-
"-d" | "--deactivate" )
30-
DEACTIVATE=1
31-
;;
3228
"-f" | "--force" )
3329
FORCE=1
3430
;;
3531
"-q" | "--quiet" )
3632
QUIET=1
3733
;;
3834
"--unset" )
39-
echo "pyenv deactivate"
40-
exit
35+
exec pyenv-sh-deactivate
4136
;;
4237
"-v" | "--verbose" )
4338
VERBOSE=1
@@ -115,9 +110,7 @@ if [ -z "$PYENV_VIRTUALENV_INIT" ]; then
115110
pyenv-virtualenv-init >&2 || true
116111
fi
117112

118-
if [ -n "${DEACTIVATE}" ]; then
119-
pyenv-sh-deactivate ${QUIET+--quiet} ${VERBOSE+--verbose}
120-
fi
113+
pyenv-sh-deactivate --quiet ${VERBOSE+--verbose} || true
121114

122115
echo "pyenv-virtualenv: activate ${venv}" 1>&2
123116

@@ -192,3 +185,21 @@ EOS
192185
;;
193186
esac
194187
fi
188+
189+
PYENV_VIRTUALENV_DISABLE_PROMPT="${PYENV_VIRTUALENV_DISABLE_PROMPT:-${PYENV_VIRTUAL_ENV_DISABLE_PROMPT}}"
190+
PYENV_VIRTUALENV_DISABLE_PROMPT="${PYENV_VIRTUALENV_DISABLE_PROMPT:-${VIRTUAL_ENV_DISABLE_PROMPT}}"
191+
192+
if [ -z "${PYENV_VIRTUALENV_DISABLE_PROMPT}" ]; then
193+
case "${shell}" in
194+
fish )
195+
echo "pyenv-virtualenv: prompt changing not work for fish." 1>&2
196+
;;
197+
* )
198+
echo "pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior." 1>&2
199+
cat <<EOS
200+
export _OLD_VIRTUAL_PS1="\${PS1}";
201+
export PS1="(${venv}) \${PS1}";
202+
EOS
203+
;;
204+
esac
205+
fi

bin/pyenv-sh-deactivate

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ EOS
114114
;;
115115
esac
116116
fi
117+
118+
case "${shell}" in
119+
fish )
120+
:
121+
;;
122+
* )
123+
if [ -n "${_OLD_VIRTUAL_PS1}" ]; then
124+
cat <<EOS
125+
export PS1='${_OLD_VIRTUAL_PS1}';
126+
unset _OLD_VIRTUAL_PS1;
127+
EOS
128+
fi
129+
;;
130+
esac

bin/pyenv-virtualenv-init

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fish )
104104
function _pyenv_virtualenv_hook --on-event fish_prompt;
105105
set -l ret \$status
106106
if [ -n "\$VIRTUAL_ENV" ]
107-
pyenv activate --deactivate --quiet; or pyenv deactivate --quiet; or true
107+
pyenv activate --quiet; or pyenv deactivate --quiet; or true
108108
else
109109
pyenv activate --quiet; or true
110110
end
@@ -128,7 +128,7 @@ if [[ "$shell" != "fish" ]]; then
128128
cat <<EOS
129129
local ret=\$?
130130
if [ -n "\$VIRTUAL_ENV" ]; then
131-
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
131+
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
132132
else
133133
eval "\$(pyenv sh-activate --quiet || true)" || true
134134
fi

test/activate.bats

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ load test_helper
55
setup() {
66
export HOME="${TMP}"
77
export PYENV_ROOT="${TMP}/pyenv"
8+
unset PYTHONHOME
9+
unset PYENV_VIRTUALENV_DISABLE_PROMPT
10+
unset PYENV_VIRTUAL_ENV_DISABLE_PROMPT
11+
unset VIRTUAL_ENV_DISABLE_PROMPT
812
}
913

1014
@test "activate virtualenv from current version" {
@@ -22,9 +26,13 @@ setup() {
2226

2327
assert_success
2428
assert_output <<EOS
29+
false
2530
pyenv-virtualenv: activate venv
2631
unset PYENV_DEACTIVATE;
2732
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
33+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
34+
export _OLD_VIRTUAL_PS1="\${PS1}";
35+
export PS1="(venv) \${PS1}";
2836
EOS
2937
}
3038

@@ -43,9 +51,13 @@ EOS
4351

4452
assert_success
4553
assert_output <<EOS
54+
false
4655
pyenv-virtualenv: activate venv
4756
unset PYENV_DEACTIVATE;
4857
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
58+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
59+
export _OLD_VIRTUAL_PS1="\${PS1}";
60+
export PS1="(venv) \${PS1}";
4961
EOS
5062
}
5163

@@ -69,11 +81,15 @@ EOS
6981
7082
eval "\$(pyenv virtualenv-init -)"
7183
84+
false
7285
pyenv-virtualenv: activate venv
7386
export PYENV_VERSION="venv";
7487
export PYENV_ACTIVATE_SHELL=1;
7588
unset PYENV_DEACTIVATE;
7689
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv";
90+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
91+
export _OLD_VIRTUAL_PS1="\${PS1}";
92+
export PS1="(venv) \${PS1}";
7793
EOS
7894
}
7995

@@ -92,9 +108,11 @@ EOS
92108

93109
assert_success
94110
assert_output <<EOS
111+
false
95112
pyenv-virtualenv: activate venv
96113
set -e PYENV_DEACTIVATE;
97114
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
115+
pyenv-virtualenv: prompt changing not work for fish.
98116
EOS
99117
}
100118

@@ -118,11 +136,13 @@ EOS
118136
119137
status --is-interactive; and . (pyenv virtualenv-init -|psub)
120138
139+
false
121140
pyenv-virtualenv: activate venv
122141
setenv PYENV_VERSION "venv";
123142
setenv PYENV_ACTIVATE_SHELL 1;
124143
set -e PYENV_DEACTIVATE;
125144
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv";
145+
pyenv-virtualenv: prompt changing not work for fish.
126146
EOS
127147
}
128148

@@ -139,11 +159,15 @@ EOS
139159

140160
assert_success
141161
assert_output <<EOS
162+
false
142163
pyenv-virtualenv: activate venv27
143164
export PYENV_VERSION="venv27";
144165
export PYENV_ACTIVATE_SHELL=1;
145166
unset PYENV_DEACTIVATE;
146167
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
168+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
169+
export _OLD_VIRTUAL_PS1="\${PS1}";
170+
export PS1="(venv27) \${PS1}";
147171
EOS
148172
}
149173

@@ -165,11 +189,15 @@ EOS
165189
166190
eval "\$(pyenv virtualenv-init -)"
167191
192+
false
168193
pyenv-virtualenv: activate venv27
169194
export PYENV_VERSION="venv27";
170195
export PYENV_ACTIVATE_SHELL=1;
171196
unset PYENV_DEACTIVATE;
172197
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
198+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
199+
export _OLD_VIRTUAL_PS1="\${PS1}";
200+
export PS1="(venv27) \${PS1}";
173201
EOS
174202
}
175203

@@ -186,11 +214,13 @@ EOS
186214

187215
assert_success
188216
assert_output <<EOS
217+
false
189218
pyenv-virtualenv: activate venv27
190219
setenv PYENV_VERSION "venv27";
191220
setenv PYENV_ACTIVATE_SHELL 1;
192221
set -e PYENV_DEACTIVATE;
193222
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
223+
pyenv-virtualenv: prompt changing not work for fish.
194224
EOS
195225
}
196226

@@ -212,20 +242,27 @@ EOS
212242
213243
status --is-interactive; and . (pyenv virtualenv-init -|psub)
214244
245+
false
215246
pyenv-virtualenv: activate venv27
216247
setenv PYENV_VERSION "venv27";
217248
setenv PYENV_ACTIVATE_SHELL 1;
218249
set -e PYENV_DEACTIVATE;
219250
setenv VIRTUAL_ENV "${PYENV_ROOT}/versions/venv27";
251+
pyenv-virtualenv: prompt changing not work for fish.
220252
EOS
221253
}
222254

223255
@test "unset invokes deactivate" {
256+
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
257+
export PYENV_ACTIVATE_SHELL=
258+
224259
run pyenv-sh-activate --unset
225260

226261
assert_success
227262
assert_output <<EOS
228-
pyenv deactivate
263+
pyenv-virtualenv: deactivate venv
264+
export PYENV_DEACTIVATE="${PYENV_ROOT}/versions/venv";
265+
unset VIRTUAL_ENV;
229266
EOS
230267
}
231268

@@ -315,11 +352,15 @@ EOS
315352

316353
assert_success
317354
assert_output <<EOS
355+
false
318356
pyenv-virtualenv: activate venv27
319357
export PYENV_VERSION="venv27:2.7.10";
320358
export PYENV_ACTIVATE_SHELL=1;
321359
unset PYENV_DEACTIVATE;
322360
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv27";
361+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
362+
export _OLD_VIRTUAL_PS1="\${PS1}";
363+
export PS1="(venv27) \${PS1}";
323364
EOS
324365
}
325366

test/conda-activate.bats

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ load test_helper
55
setup() {
66
export HOME="${TMP}"
77
export PYENV_ROOT="${TMP}/pyenv"
8+
unset _OLD_VIRTUAL_PYTHONHOME
9+
unset _OLD_VIRTUAL_PS1
810
}
911

1012
@test "activate conda root from current version" {
@@ -23,10 +25,14 @@ setup() {
2325

2426
assert_success
2527
assert_output <<EOS
28+
false
2629
pyenv-virtualenv: activate anaconda-2.3.0
2730
unset PYENV_DEACTIVATE;
2831
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0";
2932
export CONDA_DEFAULT_ENV="root";
33+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
34+
export _OLD_VIRTUAL_PS1="\${PS1}";
35+
export PS1="(anaconda-2.3.0) \${PS1}";
3036
EOS
3137
}
3238

@@ -46,10 +52,12 @@ EOS
4652

4753
assert_success
4854
assert_output <<EOS
55+
false
4956
pyenv-virtualenv: activate anaconda-2.3.0
5057
set -e PYENV_DEACTIVATE;
5158
setenv VIRTUAL_ENV "${TMP}/pyenv/versions/anaconda-2.3.0";
5259
setenv CONDA_DEFAULT_ENV "root";
60+
pyenv-virtualenv: prompt changing not work for fish.
5361
EOS
5462
}
5563

@@ -68,12 +76,16 @@ EOS
6876

6977
assert_success
7078
assert_output <<EOS
79+
false
7180
pyenv-virtualenv: activate miniconda-3.9.1
7281
export PYENV_VERSION="miniconda-3.9.1";
7382
export PYENV_ACTIVATE_SHELL=1;
7483
unset PYENV_DEACTIVATE;
7584
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1";
7685
export CONDA_DEFAULT_ENV="root";
86+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
87+
export _OLD_VIRTUAL_PS1="\${PS1}";
88+
export PS1="(miniconda-3.9.1) \${PS1}";
7789
EOS
7890
}
7991

@@ -93,10 +105,14 @@ EOS
93105

94106
assert_success
95107
assert_output <<EOS
108+
false
96109
pyenv-virtualenv: activate anaconda-2.3.0/envs/foo
97110
unset PYENV_DEACTIVATE;
98111
export VIRTUAL_ENV="${PYENV_ROOT}/versions/anaconda-2.3.0/envs/foo";
99112
export CONDA_DEFAULT_ENV="foo";
113+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
114+
export _OLD_VIRTUAL_PS1="\${PS1}";
115+
export PS1="(anaconda-2.3.0/envs/foo) \${PS1}";
100116
EOS
101117
}
102118

@@ -115,11 +131,15 @@ EOS
115131

116132
assert_success
117133
assert_output <<EOS
134+
false
118135
pyenv-virtualenv: activate miniconda-3.9.1/envs/bar
119136
export PYENV_VERSION="miniconda-3.9.1/envs/bar";
120137
export PYENV_ACTIVATE_SHELL=1;
121138
unset PYENV_DEACTIVATE;
122139
export VIRTUAL_ENV="${PYENV_ROOT}/versions/miniconda-3.9.1/envs/bar";
123140
export CONDA_DEFAULT_ENV="bar";
141+
pyenv-virtualenv: prompt changing will be removed from future release. configure \`export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
142+
export _OLD_VIRTUAL_PS1="\${PS1}";
143+
export PS1="(miniconda-3.9.1/envs/bar) \${PS1}";
124144
EOS
125145
}

test/init.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export PYENV_VIRTUALENV_INIT=1;
5555
_pyenv_virtualenv_hook() {
5656
local ret=\$?
5757
if [ -n "\$VIRTUAL_ENV" ]; then
58-
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
58+
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
5959
else
6060
eval "\$(pyenv sh-activate --quiet || true)" || true
6161
fi
@@ -77,7 +77,7 @@ setenv PYENV_VIRTUALENV_INIT 1;
7777
function _pyenv_virtualenv_hook --on-event fish_prompt;
7878
set -l ret \$status
7979
if [ -n "\$VIRTUAL_ENV" ]
80-
pyenv activate --deactivate --quiet; or pyenv deactivate --quiet; or true
80+
pyenv activate --quiet; or pyenv deactivate --quiet; or true
8181
else
8282
pyenv activate --quiet; or true
8383
end
@@ -96,7 +96,7 @@ export PYENV_VIRTUALENV_INIT=1;
9696
_pyenv_virtualenv_hook() {
9797
local ret=\$?
9898
if [ -n "\$VIRTUAL_ENV" ]; then
99-
eval "\$(pyenv sh-activate --deactivate --quiet || pyenv sh-deactivate --quiet || true)" || true
99+
eval "\$(pyenv sh-activate --quiet || pyenv sh-deactivate --quiet || true)" || true
100100
else
101101
eval "\$(pyenv sh-activate --quiet || true)" || true
102102
fi

0 commit comments

Comments
 (0)