Commits

Doug Hellmann  committed 3885460

pass VIRTUALENVWRAPPER_VIRTUALENV_ARGS when calling VIRTUALENVWRAPPER_VIRTUALENV; fixes #89; fixes #87

  • Participants
  • Parent commits ae242aa

Comments (0)

Files changed (5)

File docs/en/install.rst

 
 .. _variable-VIRTUALENVWRAPPER_VIRTUALENV:
 
+.. _variable-VIRTUALENVWRAPPER_VIRTUALENV_ARGS:
+
 .. _variable-VIRTUALENVWRAPPER_PYTHON:
 
 Python Interpreter, virtualenv, and $PATH
     export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
     source /usr/local/bin/virtualenvwrapper.sh
 
+Default Arguments for virtualenv
+================================
+
+If the application identified by ``VIRTUALENVWRAPPER_VIRTUALENV``
+needs arguments, they can be set in
+``VIRTUALENVWRAPPER_VIRTUALENV_ARGS``. The same variable can be used
+to set default arguments to be passed to ``virtualenv``. For example,
+set the value to ``--no-site-packages`` to ensure that all new
+environments are isolated from the system ``site-packages`` directory.
+
+::
+
+    export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
 
 Quick-Start
 ===========

File tests/run_tests

 # Clear any user settings for the hook directory or log directory
 unset VIRTUALENVWRAPPER_HOOK_DIR
 unset VIRTUALENVWRAPPER_LOG_DIR
+unset VIRTUALENVWRAPPER_VIRTUALENV
+unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
 
 # Run the test scripts with a little formatting around them to make it
 # easier to find where each script output starts.

File tests/test_mkvirtualenv.sh

 }
 
 test_create() {
-    mkvirtualenv "env1"
+    mkvirtualenv "env1" >/dev/null 2>&1
     assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
     for hook in postactivate predeactivate postdeactivate
     do
 }
 
 test_activates () {
-    mkvirtualenv "env2"
+    mkvirtualenv "env2" >/dev/null 2>&1
     assertTrue virtualenvwrapper_verify_active_environment
     assertSame "env2" $(basename "$VIRTUAL_ENV")
 }
     chmod +x "$WORKON_HOME/premkvirtualenv"
 
     echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
-    mkvirtualenv "env3"
+    mkvirtualenv "env3" >/dev/null 2>&1
     output=$(cat "$test_dir/catch_output")
     workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
     expected="GLOBAL premkvirtualenv $workon_home_as_pwd env3
     WORKON_HOME="$old_home"
 }
 
+test_mkvirtualenv_sitepackages () {
+    # This part of the test is not reliable because
+    # creating a new virtualenv from inside the
+    # tox virtualenv inherits the setting from there.
+#     # Without the option, verify that site-packages are copied.
+# 	mkvirtualenv "with_sp" >/dev/null 2>&1
+#     ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+#     assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]"
+#     rmvirtualenv "env3"
+    
+    # With the argument, verify that they are not copied.
+    mkvirtualenv --no-site-packages "without_sp" >/dev/null 2>&1
+    ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+    assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
+    rmvirtualenv "env4"
+}
+
+test_mkvirtualenv_args () {
+    VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages"
+    # With the argument, verify that they are not copied.
+    mkvirtualenv "without_sp2" >/dev/null 2>&1
+    ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
+    assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
+    rmvirtualenv "env4"
+    unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
+}
+
 test_virtualenv_fails () {
     # Test to reproduce the conditions in issue #76
     # https://bitbucket.org/dhellmann/virtualenvwrapper/issue/76/
     chmod +x "$WORKON_HOME/premkvirtualenv"
 
     echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
-    mkvirtualenv "env3"
+    mkvirtualenv "env3" >/dev/null 2>&1
     output=$(cat "$test_dir/catch_output" 2>/dev/null)
     workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
     expected=""
     VIRTUALENVWRAPPER_VIRTUALENV=virtualenv
 }
 
-# test_mkvirtualenv_sitepackages () {
-#     # Without the option verify that site-packages are copied.
-#     mkvirtualenv "env3"
-#     assertSame "env3" "$(basename $VIRTUAL_ENV)"
-#     pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
-#     sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
-#     #cat "$sitepackages/easy-install.pth"
-#     assertTrue "Do not have expected virtualenv.py" "[ -f $sitepackages/virtualenv.py ]"
-#     rmvirtualenv "env3"
-#     
-#     # With the argument, verify that they are not copied.
-#     mkvirtualenv --no-site-packages "env4"
-#     assertSame "env4" $(basename "$VIRTUAL_ENV")
-#     pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
-#     sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
-#     assertTrue "[ -f $sitepackages/setuptools.pth ]"
-#     assertTrue "[ -f $sitepackages/easy-install.pth ]"
-#     assertFalse "Have virtualenv.py but should not" "[ -f $sitepackages/virtualenv.py ]"    
-#     rmvirtualenv "env4"
-# }
-
 
 . "$test_dir/shunit2"

File tests/test_toggleglobalsitepackages.sh

 
 test_toggleglobalsitepackages () {
     ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
-    assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
+    assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
     toggleglobalsitepackages -q
-    assertFalse "$ngsp_file exists" "[ -f "$ngsp_file" ]"
+    assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]"
     toggleglobalsitepackages -q
-    assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
+    assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
 }
 
 test_toggleglobalsitepackages_quiet () {

File virtualenvwrapper.sh

     virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_virtualenv || return 1
     (cd "$WORKON_HOME" &&
-        "$VIRTUALENVWRAPPER_VIRTUALENV" "$@" &&
+        "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" &&
         [ -d "$WORKON_HOME/$envname" ] && \
             virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname"
         )