Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activate.sh fails if 'nounset' option is set #150

Closed
billputer opened this issue Jul 7, 2011 · 24 comments
Closed

activate.sh fails if 'nounset' option is set #150

billputer opened this issue Jul 7, 2011 · 24 comments

Comments

@billputer
Copy link

I get the following error when I try to activate a virtualenv.

$ source test-env/bin/activate
-bash: _OLD_VIRTUAL_PATH: unbound variable

This is happening because I've configured Bash to use the nounset option, which throws an error when accessing unset variables (see here)

@billputer
Copy link
Author

I can fix this by changing this line:
if [ -n "$OLD_VIRTUAL_PATH" ] ; then
to:
if [ -n "${_OLD_VIRTUAL_PATH=''}" ] ; then
The ${VAR=DEFAULT} construct returns VAR if it's set, and DEFAULT if it's not (see this page. We can then use the empty string as default, causing the expected behavior. It's a little less readable than I'd like, but it does the trick.

@billputer
Copy link
Author

Actually, that's a lame fix, since it requires rewriting all existential tests. It's far easier to just add set -o nounset to the top of the script.

@dbenamy
Copy link

dbenamy commented Sep 20, 2011

I hit this too.

@dcarley
Copy link

dcarley commented Oct 27, 2011

Me too

@dannystaple
Copy link

I am suspecting that perhaps a way to unset the -u for the innards of the script, and then have it restore the original setting when finishing would make sense.

I'm trying to figure out a way of doing so here - http://stackoverflow.com/questions/13494841/how-can-you-ask-bash-for-the-current-options

@dannystaple
Copy link

Pull request made -#357

@tingletech
Copy link

I would do:

if [ -n "$OLD_VIRTUAL_PATH" ] ; then

to:

if [ -n "${_OLD_VIRTUAL_PATH-}" ] ; then
${var-DEFAULT}  If var not set, evaluate expression as $DEFAULT *

@beaumartinez
Copy link

Yup, just hit this myself.

Running virtualenv==1.11.4.

@beaumartinez
Copy link

Workaround for now—

set -o nounset

[...]

set +o nounset
. ~/.env/bin/activate
set -o nounset

[...]

@Ivoz Ivoz added this to the 1.11.5 milestone Apr 18, 2014
@blueyed
Copy link

blueyed commented Mar 2, 2015

This might be fixed by #723, which uses if ! [ -z "${_OLD_VIRTUAL_PATH+x}" ] ; then.

Please note that $_OLD_VIRTUAL_PATH itself is meant to be removed in #722 though. But #723 fixes it for the other vars, too.

@b-long
Copy link

b-long commented Jul 24, 2015

👍

@JordanP
Copy link

JordanP commented Jul 27, 2015

I am hitting this too....

@pottmi
Copy link

pottmi commented Aug 1, 2015

It is kinda weird that such a easy problem is not fixed after four years.
beaumartinez's work-a-round is the most simple for now.

@alex
Copy link
Member

alex commented Aug 12, 2015

This is fixed by #645.

@dstufft dstufft closed this as completed Aug 12, 2015
@dstufft
Copy link
Member

dstufft commented Aug 12, 2015

Fixed

b-long added a commit to Bioconductor/packagebuilder that referenced this issue Dec 11, 2015
Burnetts added a commit to Burnetts/fair-ubuntu-centre that referenced this issue Feb 28, 2017
benjaoming pushed a commit to fairdk/fair-ubuntu-centre that referenced this issue Feb 28, 2017
@ssbarnea
Copy link
Contributor

ssbarnea commented Mar 7, 2017

@dstufft could you please specify in which release was this fixed so we can assure that we have the minimal needed version installed? From the bug is not clear at all regarding which release includes the fix.

@pfmoore
Copy link
Member

pfmoore commented Mar 7, 2017

@ssbarnea It was fixed on 12 Aug 2015, as noted in the comments above, so any version released after that date. From https://virtualenv.pypa.io/en/latest/changes/ that means 13.1.1 (and indeed the note for that version mentions this change specifically). All of that information is easily available, so you could probably have found it with a brief search (that's what I did).

@ssbarnea
Copy link
Contributor

ssbarnea commented Mar 7, 2017

I have some bad news: this bug should be reopened because now I get activate: line 13: _OLD_VIRTUAL_PYTHONHOME: unbound variable and while fixing this I think there is critical to introduce a test that does attempt to activate the virtual environment using strict bash

@ssbarnea
Copy link
Contributor

ssbarnea commented Mar 7, 2017

This also applies to line 22: ZSH_VERSION: unbound variable... and wondering how long the list would go... my workaround command line starting to look perverse:

PS1="${{PS1:-}}" _OLD_VIRTUAL_PATH="${{_OLD_VIRTUAL_PATH:-}}" _OLD_VIRTUAL_PYTHONHOME="${{_OLD_VIRTUAL_PYTHONHOME:-}}" source "$VENV/bin/activate"

@pfmoore
Copy link
Member

pfmoore commented Mar 7, 2017

You can of course just set up the environment yourself, or use the full pathname of the Python executable.

@ssbarnea
Copy link
Contributor

ssbarnea commented Mar 7, 2017

Sorry for reopening the discussion on this, I made the mistake of not checking the versions of virtualenv that we had on the build server and I made an ugly discovery, an ancient version 1.10.1. This would count for lots of bugs. I am going to upgrade it tomorrow.

@pottmi
Copy link

pottmi commented Mar 8, 2017 via email

@ssbarnea
Copy link
Contributor

ssbarnea commented Mar 17, 2017

It seems that the bug still exists even in the current release, so I raised it as #1029

@allan-simon
Copy link

it's fixed now #922

@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests