importvirtualenv

37 views
Skip to first unread message

Justin

unread,
May 4, 2012, 9:17:11 AM5/4/12
to virtualenvwrapper
Hello group.

I've gone about creating importvirtualenv. My reasoning is that pip
freeze won't work for gathering the requirements as i have locally
added a bunch of paths to my existing virtualenvs. Importvirtualenv is
very similar to the cpvirtualenv in that they both make the virtualenv
relocatable. Importvirtualenv takes an virtualenv external to workhome
wheras cp only handles internal virtualenvs. I still have work to do
actually refactoring and deduping some of the code between
cpvirtualenv and importvirtualenv, but i'm having a problem getting a
test to pass and hoping its something bash related that y'all can
point me in the right direction.

In particular the test test_derive_workon_home.sh.
I have abstracted out the python call to expandvars, expanduser to a
function called expandpath. I did this for two reasons... I had
updated my postactivate user script to change directory to the
virtualenv which then prevented pip installing requirements when
mkvirtualenv from working cause the path for the requirements would be
wrong after the cd unless i passed a full path... and the
importvirtualenv needed to do all the same things checks/expansion on
the external virutalenv path.

So my hang up right now is that the path won't return unless i put in
an preceding echo. (The full code can be found at
https://bitbucket.org/barberj/virtualenvwrapper/src/73d217d4a344).

This commit shows the echo i'm talking about at line 80:
https://bitbucket.org/barberj/virtualenvwrapper/changeset/73d217d4a344.

Test results with the echo:
test_includes_tilde
ASSERT:expected:</Users/jbarber/.test-virtualenvs> but was:<
/Users/jbarber/.test-virtualenvs>

Results without the echo:

test_includes_tilde
expandpath:1: = not found
ASSERT:expected:</Users/jbarber/.test-virtualenvs> but was:<>

I tried doing a sys.stdout.flush and various other things, but bash
programing isn't my forte so I'm guessing at this point. Any pointers?

Thanks,

Justin


Doug Hellmann

unread,
May 4, 2012, 9:30:31 AM5/4/12
to virtuale...@googlegroups.com
So you're saying that expandpath() produces no output if you don't have the trailing newline at the end of the data written to sys.stdout?

It does sound like a buffer flushing issue. Did you try passing -u to the interpreter to get unbuffered I/O?

Doug

Justin

unread,
May 4, 2012, 7:11:52 PM5/4/12
to virtuale...@googlegroups.com
passing -u didn't help.

if i take out expanduser i get results... not right ones, but results none the less...

"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(\"$1\"))+'\n')"

Something about expanduser mucking with the buffering?

Doug Hellmann

unread,
May 4, 2012, 8:23:46 PM5/4/12
to virtuale...@googlegroups.com

Justin

unread,
May 4, 2012, 8:27:43 PM5/4/12
to virtuale...@googlegroups.com
i only committed that in to show the conditions when i could get it to actually return results. In my first post i describe expandpath only will display results if i put in an extra echo at line 80

Doug Hellmann

unread,
May 4, 2012, 8:58:33 PM5/4/12
to virtuale...@googlegroups.com
Sorry, I got confused and thought the \n in the write() statement was the extra newline.

Your code works fine on my system. What version of what OS and shell are you using?

Try creating a script that uses expandpath() (other than importvirtualenv) and use "set -x" to see the commands being run. For example,

source ./virtualenvwrapper.sh
set -x
expandpath ~
expandpath $HOME
expandpath ~/$HOME
expandpath foo
set +x

Doug

Justin

unread,
May 5, 2012, 11:39:56 AM5/5/12
to virtuale...@googlegroups.com
very cool trick. it returns expected results. 

$ ./test.sh 
++ expandpath /Users/jbarber
++ '[' /Users/jbarber == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("/Users/jbarber")))+'\''\n'\'')'
/Users/jbarber
++ return 0
++ expandpath /Users/jbarber
++ '[' /Users/jbarber == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("/Users/jbarber")))+'\''\n'\'')'
/Users/jbarber
++ return 0
++ expandpath foo
++ '[' foo == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("foo")))+'\''\n'\'')'
/Users/jbarber/foo
++ return 0
++ set +x

Question... not sure why i haven't noticed this before, when i run the test and specify it for a certain environment (tox -e py27 tests/test_derive_workon_home.sh) it looks like its running three times. Its only on the third time it errors. And i get a warning that i can't figure out how to silence. I have attached the results and included my os and shell below.

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.7.3
BuildVersion:   11D50d

$ echo $0
-bash

Thanks

Justin
results.txt

Justin Barber

unread,
May 5, 2012, 1:02:22 PM5/5/12
to virtuale...@googlegroups.com
weird. created test_expandpath and getting same results as the derived home test. runs three times and third time errors. Something must be going on with my system that i'm unaware of...
--
Justin Barber
(512)JBARBER
    .......__o
    .......\<,
    ....( )/ ( )

Doug Hellmann

unread,
May 5, 2012, 1:07:21 PM5/5/12
to virtuale...@googlegroups.com


On May 5, 2012, at 11:39 AM, Justin <barber...@gmail.com> wrote:

very cool trick. it returns expected results. 

I should have had you include single quotes around the args to avoid having the shell expand the values before calling the function. 


$ ./test.sh 
++ expandpath /Users/jbarber
++ '[' /Users/jbarber == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("/Users/jbarber")))+'\''\n'\'')'
/Users/jbarber
++ return 0
++ expandpath /Users/jbarber
++ '[' /Users/jbarber == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("/Users/jbarber")))+'\''\n'\'')'
/Users/jbarber
++ return 0
++ expandpath foo
++ '[' foo == '' ']'
++ /usr/bin/python -c 'import os,sys; sys.stdout.write(os.path.realpath(os.path.expandvars(os.path.expanduser("foo")))+'\''\n'\'')'
/Users/jbarber/foo
++ return 0
++ set +x

Question... not sure why i haven't noticed this before, when i run the test and specify it for a certain environment (tox -e py27 tests/test_derive_workon_home.sh) it looks like its running three times. Its only on the third time it errors. And i get a warning that i can't figure out how to silence. I have attached the results and included my os and shell below.

The tests are all run under each shell supported by virtualenvwrapper. In your case they are failing under zsh, so you could focus your debugging there. 
<results.txt>

Justin

unread,
May 5, 2012, 1:51:20 PM5/5/12
to virtuale...@googlegroups.com

Was a case of == vs = 
_______________________________________________________________ [tox summary] ________________________________________________________________
[TOX] py27: commands succeeded
[TOX] congratulations :)

Running all tests now!

Doug Hellmann

unread,
May 5, 2012, 4:11:29 PM5/5/12
to virtuale...@googlegroups.com
Great!
Reply all
Reply to author
Forward
0 new messages