Skip to content

Commit d759930

Browse files
committed
fix issue with add2virtualenv and noclobber setting in shell; fixes #137
1 parent 62eb6b5 commit d759930

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

docs/en/history.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dev
88
- mkvirtualenv_help should use ``$VIRTUALENVWRAPPER_PYTHON`` instead
99
of calling ``virtualenv`` directly (:bbissue:`148`).
1010
- Fix issue with lazy-loader code under zsh (:bbissue:`144`).
11+
- Fix issue with ``noclobber`` option under zsh (:bbissue:`137`).
1112

1213
.. _stevedore: http://pypi.python.org/pypi/stevedore
1314

tests/test_add2virtualenv.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,44 @@ test_add2virtualenv () {
3737
cd - >/dev/null 2>&1
3838
}
3939

40+
test_add2virtualenv_zsh_noclobber () {
41+
# See issue #137
42+
if [ ! -z $ZSH_VERSION ]
43+
then
44+
set -o noclobber
45+
elif [[ "$SHELL" =~ "bash" ]]
46+
then
47+
shopt -o -s noclobber
48+
else
49+
return 0
50+
fi
51+
mkvirtualenv "pathtest_noclobber" >/dev/null 2>&1
52+
full_path=$(pwd)
53+
add2virtualenv "$full_path"
54+
RC=$?
55+
if [ ! -z $ZSH_VERSION ]
56+
then
57+
unsetopt noclobber
58+
elif [[ "/$SHELL" =~ "/bash" ]]
59+
then
60+
shopt -o -u noclobber
61+
fi
62+
assertEquals "0" "$RC"
63+
cdsitepackages
64+
# Check contents of path file
65+
path_file="./_virtualenv_path_extensions.pth"
66+
assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file"
67+
assertTrue "No path insert code in $(cat $path_file)" "grep -q sys.__egginsert $path_file"
68+
# Check the path we inserted is actually at the top
69+
expected="$full_path"
70+
actual=$($WORKON_HOME/pathtest_noclobber/bin/python -c "import sys; sys.stdout.write(sys.path[1]+'\n')")
71+
assertSame "$expected" "$actual"
72+
# Make sure the temporary file created
73+
# during the edit was removed
74+
assertFalse "Temporary file ${path_file}.tmp still exists" "[ -f ${path_file}.tmp ]"
75+
cd - >/dev/null 2>&1
76+
}
77+
4078
test_add2virtualenv_relative () {
4179
mkvirtualenv "pathtest_relative" >/dev/null 2>&1
4280
parent_dir=$(dirname $(pwd))

virtualenvwrapper.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ function add2virtualenv {
721721

722722
if [ ! -f "$path_file" ]
723723
then
724-
echo "import sys; sys.__plen = len(sys.path)" >> "$path_file"
725-
echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file"
724+
echo "import sys; sys.__plen = len(sys.path)" > "$path_file" || return 1
725+
echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file" || return 1
726726
fi
727727

728728
for pydir in "$@"

0 commit comments

Comments
 (0)