Commits

Doug Hellmann committed 8d8c0eb Merge

merge pmclanahan's test changes and toggleglobalsitepackages

Comments (0)

Files changed (6)

docs/en/command_ref.rst

 for the environment.
 
 *Based on a contribution from James Bennett and Jannis Leidel.*
+
+.. _command-toggleglobalsitepackages:
+
+toggleglobalsitepackages
+------------------------
+
+Controls whether the active virtualenv will access the packages in the
+global Python ``site-packages`` directory.
+
+Syntax::
+
+    toggleglobalsitepackages [-q]
+
+Outputs the new state of the virtualenv. Use the ``-q`` switch to turn off all
+output.
+
+::
+
+    $ mkvirtualenv env1
+    New python executable in env1/bin/python
+    Installing distribute.............................................
+    ..................................................................
+    ..................................................................
+    done.
+    (env1)$ toggleglobalsitepackages
+    Disabled global site-packages
+    (env1)$ toggleglobalsitepackages
+    Enabled global site-packages
+    (env1)$ toggleglobalsitepackages -q
+    (env1)$

docs/en/history.rst

   - If WORKON_HOME does not exist, create it. Patch from Carl Karsten
     (:bbuser:`CarlFK`). Test updates based on patches from Matt Austin
     (:bbuser:`maafy6`) and Hugo Lopes Tavares (:bbuser:`hltbra`).
+  - Merge in contributions from Paul McLanahan (:bbuser:`pmclanahan`)
+    to fix the test harness to ensure that the test scripts are
+    actually running under the expected shell.
+  - Merge in new shell command :ref:`command-toggleglobalsitepackages`
+    from Paul McLanahan (:bbuser:`pmclanahan`). The new command
+    changes the configuration of the active virtualenv to enable or
+    disable the global ``site-packages`` directory.
 
 2.6.3
 
 # tox-created virtualenv.
 export VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python"
 
-if [ -n "${ZSH_VERSION:-}" ]
-then
-    export SHELL=$(which zsh)
-fi
-
 # Run the test scripts with a little formatting around them to make it
 # easier to find where each script output starts.
-for test_script in $scripts
+for test_shell in bash ksh zsh
 do
-	echo
- 	echo '********************************************************************************'
-	echo "Running $test_script"
-    echo "  VIRTUAL_ENV=$VIRTUAL_ENV"
-    echo "  VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON"
-    echo "    $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)"
-    echo "  PYTHONPATH=$PYTHONPATH"
-    echo "  SHELL=$SHELL"
-	echo
-    export SHUNIT_PARENT="$test_script"
-	$test_script || exit 1
-	echo
+    test_shell_opts=
+    if [ $test_shell = "zsh" ]; then
+        test_shell_opts="-o shwordsplit"
+    fi
+    test_shell=$(which $test_shell)
+
+    for test_script in $scripts
+    do
+        echo
+        echo '********************************************************************************'
+        echo "Running $test_script"
+        echo "  VIRTUAL_ENV=$VIRTUAL_ENV"
+        echo "  VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON"
+        echo "    $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)"
+        echo "  PYTHONPATH=$PYTHONPATH"
+        echo "  SHELL=$test_shell"
+        echo
+        export SHUNIT_PARENT="$test_script"
+        $test_shell $test_shell_opts $test_script || exit 1
+        echo
+    done
 done
 
 exit 0

tests/test_toggleglobalsitepackages.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(cd $(dirname $0) && pwd)
+
+export WORKON_HOME="$(echo ${TMPDIR:-/tmp}/WORKON_HOME | sed 's|//|/|g')"
+
+oneTimeSetUp() {
+    rm -rf "$WORKON_HOME"
+    mkdir -p "$WORKON_HOME"
+    source "$test_dir/../virtualenvwrapper.sh"
+}
+
+oneTimeTearDown() {
+    rm -rf "$WORKON_HOME"
+}
+
+setUp () {
+    echo
+    rm -f "$test_dir/catch_output"
+    mkvirtualenv --no-site-packages "globaltest"
+}
+
+tearDown () {
+    deactivate
+    rmvirtualenv "globaltest"
+}
+
+test_toggleglobalsitepackages () {
+    ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+    assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
+    toggleglobalsitepackages -q
+    assertFalse "$ngsp_file exists" "[ -f "$ngsp_file" ]"
+    toggleglobalsitepackages -q
+    assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
+}
+
+test_toggleglobalsitepackages_quiet () {
+    assertEquals "Command output is not correct" "Enabled global site-packages" "`toggleglobalsitepackages`"
+    assertEquals "Command output is not correct" "Disabled global site-packages" "`toggleglobalsitepackages`"
+    
+    assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`"
+    assertEquals "Command output is not correct" "" "`toggleglobalsitepackages -q`"
+}
+
+. "$test_dir/shunit2"
 envlist = py27,py26,py25,py24
 
 [testenv]
-commands = 
-  zsh -o shwordsplit ./tests/run_tests {envdir} []
-  ksh ./tests/run_tests {envdir} []
-  bash ./tests/run_tests {envdir} []
+commands = bash ./tests/run_tests {envdir} []
 
 # Not sure why this is needed, but on my system if it isn't included then
 # the python version picked up for 2.6 is actually 2.7.
 # IF THIS CAUSES YOU A PROBLEM COMMENT IT OUT BEFORE RUNNING THE TESTS.
 [testenv:py26]
-basepython=/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
+basepython=/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6

virtualenvwrapper.sh

     fi
 }
 
+# Toggles the currently-active virtualenv between having and not having
+# access to the global site-packages.
+toggleglobalsitepackages () {
+    virtualenvwrapper_verify_workon_home || return 1
+    virtualenvwrapper_verify_active_environment || return 1
+    typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+    if [ -f $no_global_site_packages_file ]; then
+        rm $no_global_site_packages_file
+        [ "$1" = "-q" ] || echo "Enabled global site-packages"
+    else
+        touch $no_global_site_packages_file
+        [ "$1" = "-q" ] || echo "Disabled global site-packages"
+    fi
+}
+
 # Duplicate the named virtualenv to make a new one.
 cpvirtualenv() {
     typeset env_name="$1"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.