classification
Title: pyvenv activate script failure with specific bash option
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, s-wakaba, ssbarnea, vinay.sajip, vstinner
Priority: normal Keywords: patch

Created on 2015-10-09 07:23 by s-wakaba, last changed 2017-09-29 12:35 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
activate vinay.sajip, 2016-02-14 18:04
Pull Requests
URL Status Linked Edit
PR 3804 merged ssbarnea, 2017-09-28 15:11
PR 3820 merged python-dev, 2017-09-29 12:01
Messages (8)
msg252593 - (view) Author: (s-wakaba) Date: 2015-10-09 07:23
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

$SPAM -> ${SPAM:-}
msg260284 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2016-02-14 18:04
Can you try the attached script in place of the current activate script and see if it meets the requirements?
msg303255 - (view) Author: Sorin Sbarnea (ssbarnea) * Date: 2017-09-28 15:11
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.
msg303287 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-09-28 23:07
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.
msg303289 - (view) Author: Sorin Sbarnea (ssbarnea) * Date: 2017-09-28 23:42
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:-}]"'
msg303325 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-09-29 11:48
New changeset 90f1d989594f3340c5ffaa2cf9cef1876ac6bb89 by Vinay Sajip (Sorin Sbarnea) in branch 'master':
bpo-25351: avoid activate failure on strict shells (GH-3804)
https://github.com/python/cpython/commit/90f1d989594f3340c5ffaa2cf9cef1876ac6bb89
msg303327 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-29 12:34
New changeset a5610e07460a8df4b0923a32d37234cd535ec952 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-25351: avoid activate failure on strict shells (GH-3804) (#3820)
https://github.com/python/cpython/commit/a5610e07460a8df4b0923a32d37234cd535ec952
msg303328 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-29 12:35
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
History
Date User Action Args
2017-09-29 12:35:44vstinnersetstatus: open -> closed
versions: + Python 3.6, Python 3.7, - Python 3.4, Python 3.5
messages: + msg303328

resolution: fixed
stage: patch review -> resolved
2017-09-29 12:34:45vstinnersetnosy: + vstinner
messages: + msg303327
2017-09-29 12:01:09python-devsetpull_requests: + pull_request3804
2017-09-29 11:48:18vinay.sajipsetmessages: + msg303325
2017-09-28 23:42:15ssbarneasetmessages: + msg303289
2017-09-28 23:07:46r.david.murraysetnosy: + r.david.murray
messages: + msg303287
2017-09-28 15:11:08ssbarneasettype: enhancement -> behavior
versions: + Python 3.4
keywords: + patch
nosy: + ssbarnea

messages: + msg303255
stage: patch review
pull_requests: + pull_request3790
2016-02-14 18:04:36vinay.sajipsetfiles: + activate

messages: + msg260284
2016-02-07 06:56:09ned.deilysetnosy: + vinay.sajip
2015-10-09 07:23:57s-wakabacreate