You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pyvenv activate script failure with specific bash option #69538
When writing bash shellscripts, I always set options "set -ueC" for strict error checking. However, loading pyvenv's activate and deactivate scripts from bash with "-u" option, they are failure because they may refer undefined shell variables.
I hope activate script and deactivate function are enclosed like following block
_OLD_BASH_OPTIONS="$-"
set +u
### script body ##
set -$_OLD_BASH_OPTIONS
unset _OLD_BASH_OPTIONS
Another option, all shell-variables in the script change like
Note that in the equivalent issue raised against virtualenv, the concern was raised that some old sh-like shells might not support this syntax, but it was pointed out that it is part of the posix standard. I'm not arguing for or against here, just noting relevant information :)
The script comment specifically says "from bash", but presumably the script can be and is sourced from other sh-like shells.
ssbarnea commented on Sep 28, 2017
ssbarneamannequin
Mannequin
More actions
Based on my tests this worked with all shells I tested with, the syntax being a very old one and not some new/modern one.
Passed: bash, zsh, dash, ksh
Platforms: MacOS, RHEL Linux
Failed with: tcsh but with the note that even the original code would fail with tcsh anyway. tcsh/csh are not bourne/posix compatible so there is no regression introduced by the the use of "${VAR:-}" syntax.
A simple way to test the syntax with enable shell is:
SHELLCMD -c 'echo "[${AAA:-}]"'
New changeset a5610e0 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-25351: avoid activate failure on strict shells (GH-3804) (bpo-3820) a5610e0
Activity
s-wakaba commentedon Oct 9, 2015
When writing bash shellscripts, I always set options "set -ueC" for strict error checking. However, loading pyvenv's activate and deactivate scripts from bash with "-u" option, they are failure because they may refer undefined shell variables.
I hope activate script and deactivate function are enclosed like following block
_OLD_BASH_OPTIONS="$-"
set +u
### script body ##
set -$_OLD_BASH_OPTIONS
unset _OLD_BASH_OPTIONS
Another option, all shell-variables in the script change like
vsajip commentedon Feb 14, 2016
Can you try the attached script in place of the current activate script and see if it meets the requirements?
ssbarnea commentedon Sep 28, 2017
This is a perfectly valid bug and I am surprised it was ignored for so long.
I just raised a PR for addressing it, please review it.
bitdancer commentedon Sep 28, 2017
Note that in the equivalent issue raised against virtualenv, the concern was raised that some old sh-like shells might not support this syntax, but it was pointed out that it is part of the posix standard. I'm not arguing for or against here, just noting relevant information :)
The script comment specifically says "from bash", but presumably the script can be and is sourced from other sh-like shells.
ssbarnea commentedon Sep 28, 2017
Based on my tests this worked with all shells I tested with, the syntax being a very old one and not some new/modern one.
Passed: bash, zsh, dash, ksh
Platforms: MacOS, RHEL Linux
Failed with: tcsh but with the note that even the original code would fail with tcsh anyway. tcsh/csh are not bourne/posix compatible so there is no regression introduced by the the use of "${VAR:-}" syntax.
A simple way to test the syntax with enable shell is:
SHELLCMD -c 'echo "[${AAA:-}]"'
vsajip commentedon Sep 29, 2017
New changeset 90f1d98 by Vinay Sajip (Sorin Sbarnea) in branch 'master':
bpo-25351: avoid activate failure on strict shells (GH-3804)
90f1d98
vstinner commentedon Sep 29, 2017
New changeset a5610e0 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-25351: avoid activate failure on strict shells (GH-3804) (bpo-3820)
a5610e0
vstinner commentedon Sep 29, 2017
The bug has been fixed in Python 3.6 and 3.7 (master), thank you Sorin Sbarnea!
Python 3.4 and 3.5 don't accept bug fixes anymore, only security fixes:
https://devguide.python.org/#status-of-python-branches