Skip to content

Commit 90f1d98

Browse files
ssbarneavsajip
authored andcommitted
bpo-25351: avoid activate failure on strict shells (pythonGH-3804)
1 parent 288d1da commit 90f1d98

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

Lib/venv/scripts/common/activate

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33

44
deactivate () {
55
# reset old environment variables
6-
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
7-
PATH="$_OLD_VIRTUAL_PATH"
6+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
7+
PATH="${_OLD_VIRTUAL_PATH:-}"
88
export PATH
99
unset _OLD_VIRTUAL_PATH
1010
fi
11-
if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
12-
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
11+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
12+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
1313
export PYTHONHOME
1414
unset _OLD_VIRTUAL_PYTHONHOME
1515
fi
1616

1717
# This should detect bash and zsh, which have a hash command that must
1818
# be called to get it to forget past commands. Without forgetting
1919
# past commands the $PATH changes we made may not be respected
20-
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
20+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
2121
hash -r
2222
fi
2323

24-
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
25-
PS1="$_OLD_VIRTUAL_PS1"
24+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
25+
PS1="${_OLD_VIRTUAL_PS1:-}"
2626
export PS1
2727
unset _OLD_VIRTUAL_PS1
2828
fi
@@ -47,15 +47,15 @@ export PATH
4747
# unset PYTHONHOME if set
4848
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
4949
# could use `if (set -u; : $PYTHONHOME) ;` in bash
50-
if [ -n "$PYTHONHOME" ] ; then
51-
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
50+
if [ -n "${PYTHONHOME:-}" ] ; then
51+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
5252
unset PYTHONHOME
5353
fi
5454

55-
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
56-
_OLD_VIRTUAL_PS1="$PS1"
55+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
56+
_OLD_VIRTUAL_PS1="${PS1:-}"
5757
if [ "x__VENV_PROMPT__" != x ] ; then
58-
PS1="__VENV_PROMPT__$PS1"
58+
PS1="__VENV_PROMPT__${PS1:-}"
5959
else
6060
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
6161
# special case for Aspen magic directories
@@ -71,6 +71,6 @@ fi
7171
# This should detect bash and zsh, which have a hash command that must
7272
# be called to get it to forget past commands. Without forgetting
7373
# past commands the $PATH changes we made may not be respected
74-
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
74+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
7575
hash -r
7676
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid venv activate failures with undefined variables

0 commit comments

Comments
 (0)