Skip to content

Commit 8d8c0eb

Browse files
committed
merge pmclanahan's test changes and toggleglobalsitepackages
2 parents b72f4ac + 5507739 commit 8d8c0eb

File tree

6 files changed

+123
-23
lines changed

6 files changed

+123
-23
lines changed

docs/en/command_ref.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,33 @@ The directory names are added to a path file named
364364
for the environment.
365365

366366
*Based on a contribution from James Bennett and Jannis Leidel.*
367+
368+
.. _command-toggleglobalsitepackages:
369+
370+
toggleglobalsitepackages
371+
------------------------
372+
373+
Controls whether the active virtualenv will access the packages in the
374+
global Python ``site-packages`` directory.
375+
376+
Syntax::
377+
378+
toggleglobalsitepackages [-q]
379+
380+
Outputs the new state of the virtualenv. Use the ``-q`` switch to turn off all
381+
output.
382+
383+
::
384+
385+
$ mkvirtualenv env1
386+
New python executable in env1/bin/python
387+
Installing distribute.............................................
388+
..................................................................
389+
..................................................................
390+
done.
391+
(env1)$ toggleglobalsitepackages
392+
Disabled global site-packages
393+
(env1)$ toggleglobalsitepackages
394+
Enabled global site-packages
395+
(env1)$ toggleglobalsitepackages -q
396+
(env1)$

docs/en/history.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ dev
1111
- If WORKON_HOME does not exist, create it. Patch from Carl Karsten
1212
(:bbuser:`CarlFK`). Test updates based on patches from Matt Austin
1313
(:bbuser:`maafy6`) and Hugo Lopes Tavares (:bbuser:`hltbra`).
14+
- Merge in contributions from Paul McLanahan (:bbuser:`pmclanahan`)
15+
to fix the test harness to ensure that the test scripts are
16+
actually running under the expected shell.
17+
- Merge in new shell command :ref:`command-toggleglobalsitepackages`
18+
from Paul McLanahan (:bbuser:`pmclanahan`). The new command
19+
changes the configuration of the active virtualenv to enable or
20+
disable the global ``site-packages`` directory.
1421

1522
2.6.3
1623

tests/run_tests

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,31 @@ export HOOK_VERBOSE_OPTION="-q"
3131
# tox-created virtualenv.
3232
export VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python"
3333

34-
if [ -n "${ZSH_VERSION:-}" ]
35-
then
36-
export SHELL=$(which zsh)
37-
fi
38-
3934
# Run the test scripts with a little formatting around them to make it
4035
# easier to find where each script output starts.
41-
for test_script in $scripts
36+
for test_shell in bash ksh zsh
4237
do
43-
echo
44-
echo '********************************************************************************'
45-
echo "Running $test_script"
46-
echo " VIRTUAL_ENV=$VIRTUAL_ENV"
47-
echo " VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON"
48-
echo " $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)"
49-
echo " PYTHONPATH=$PYTHONPATH"
50-
echo " SHELL=$SHELL"
51-
echo
52-
export SHUNIT_PARENT="$test_script"
53-
$test_script || exit 1
54-
echo
38+
test_shell_opts=
39+
if [ $test_shell = "zsh" ]; then
40+
test_shell_opts="-o shwordsplit"
41+
fi
42+
test_shell=$(which $test_shell)
43+
44+
for test_script in $scripts
45+
do
46+
echo
47+
echo '********************************************************************************'
48+
echo "Running $test_script"
49+
echo " VIRTUAL_ENV=$VIRTUAL_ENV"
50+
echo " VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON"
51+
echo " $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)"
52+
echo " PYTHONPATH=$PYTHONPATH"
53+
echo " SHELL=$test_shell"
54+
echo
55+
export SHUNIT_PARENT="$test_script"
56+
$test_shell $test_shell_opts $test_script || exit 1
57+
echo
58+
done
5559
done
5660

5761
exit 0
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
#set -x
4+
5+
test_dir=$(cd $(dirname $0) && pwd)
6+
7+
export WORKON_HOME="$(echo ${TMPDIR:-/tmp}/WORKON_HOME | sed 's|//|/|g')"
8+
9+
oneTimeSetUp() {
10+
rm -rf "$WORKON_HOME"
11+
mkdir -p "$WORKON_HOME"
12+
source "$test_dir/../virtualenvwrapper.sh"
13+
}
14+
15+
oneTimeTearDown() {
16+
rm -rf "$WORKON_HOME"
17+
}
18+
19+
setUp () {
20+
echo
21+
rm -f "$test_dir/catch_output"
22+
mkvirtualenv --no-site-packages "globaltest"
23+
}
24+
25+
tearDown () {
26+
deactivate
27+
rmvirtualenv "globaltest"
28+
}
29+
30+
test_toggleglobalsitepackages () {
31+
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
32+
assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
33+
toggleglobalsitepackages -q
34+
assertFalse "$ngsp_file exists" "[ -f "$ngsp_file" ]"
35+
toggleglobalsitepackages -q
36+
assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
37+
}
38+
39+
test_toggleglobalsitepackages_quiet () {
40+
assertEquals "Command output is not correct" "Enabled global site-packages" "`toggleglobalsitepackages`"
41+
assertEquals "Command output is not correct" "Disabled global site-packages" "`toggleglobalsitepackages`"
42+
43+
assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`"
44+
assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`"
45+
}
46+
47+
. "$test_dir/shunit2"

tox.ini

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
envlist = py27,py26,py25,py24
33

44
[testenv]
5-
commands =
6-
zsh -o shwordsplit ./tests/run_tests {envdir} []
7-
ksh ./tests/run_tests {envdir} []
8-
bash ./tests/run_tests {envdir} []
5+
commands = bash ./tests/run_tests {envdir} []
96

107
# Not sure why this is needed, but on my system if it isn't included then
118
# the python version picked up for 2.6 is actually 2.7.
129
# IF THIS CAUSES YOU A PROBLEM COMMENT IT OUT BEFORE RUNNING THE TESTS.
1310
[testenv:py26]
14-
basepython=/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
11+
basepython=/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6

virtualenvwrapper.sh

100644100755
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ lssitepackages () {
511511
fi
512512
}
513513

514+
# Toggles the currently-active virtualenv between having and not having
515+
# access to the global site-packages.
516+
toggleglobalsitepackages () {
517+
virtualenvwrapper_verify_workon_home || return 1
518+
virtualenvwrapper_verify_active_environment || return 1
519+
typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
520+
if [ -f $no_global_site_packages_file ]; then
521+
rm $no_global_site_packages_file
522+
[ "$1" = "-q" ] || echo "Enabled global site-packages"
523+
else
524+
touch $no_global_site_packages_file
525+
[ "$1" = "-q" ] || echo "Disabled global site-packages"
526+
fi
527+
}
528+
514529
# Duplicate the named virtualenv to make a new one.
515530
cpvirtualenv() {
516531
typeset env_name="$1"

0 commit comments

Comments
 (0)