Skip to content

Commit 3885460

Browse files
committed
pass VIRTUALENVWRAPPER_VIRTUALENV_ARGS when calling VIRTUALENVWRAPPER_VIRTUALENV; fixes #89; fixes #87
1 parent ae242aa commit 3885460

File tree

5 files changed

+52
-29
lines changed

5 files changed

+52
-29
lines changed

docs/en/install.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ After editing it, reload the startup file (e.g., run: ``source
8484

8585
.. _variable-VIRTUALENVWRAPPER_VIRTUALENV:
8686

87+
.. _variable-VIRTUALENVWRAPPER_VIRTUALENV_ARGS:
88+
8789
.. _variable-VIRTUALENVWRAPPER_PYTHON:
8890

8991
Python Interpreter, virtualenv, and $PATH
@@ -111,6 +113,19 @@ sourcing ``virtualenvwrapper.sh``. For example::
111113
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
112114
source /usr/local/bin/virtualenvwrapper.sh
113115

116+
Default Arguments for virtualenv
117+
================================
118+
119+
If the application identified by ``VIRTUALENVWRAPPER_VIRTUALENV``
120+
needs arguments, they can be set in
121+
``VIRTUALENVWRAPPER_VIRTUALENV_ARGS``. The same variable can be used
122+
to set default arguments to be passed to ``virtualenv``. For example,
123+
set the value to ``--no-site-packages`` to ensure that all new
124+
environments are isolated from the system ``site-packages`` directory.
125+
126+
::
127+
128+
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
114129

115130
Quick-Start
116131
===========

tests/run_tests

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python"
3434
# Clear any user settings for the hook directory or log directory
3535
unset VIRTUALENVWRAPPER_HOOK_DIR
3636
unset VIRTUALENVWRAPPER_LOG_DIR
37+
unset VIRTUALENVWRAPPER_VIRTUALENV
38+
unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
3739

3840
# Run the test scripts with a little formatting around them to make it
3941
# easier to find where each script output starts.

tests/test_mkvirtualenv.sh

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ setUp () {
2222
}
2323

2424
test_create() {
25-
mkvirtualenv "env1"
25+
mkvirtualenv "env1" >/dev/null 2>&1
2626
assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
2727
for hook in postactivate predeactivate postdeactivate
2828
do
@@ -32,7 +32,7 @@ test_create() {
3232
}
3333

3434
test_activates () {
35-
mkvirtualenv "env2"
35+
mkvirtualenv "env2" >/dev/null 2>&1
3636
assertTrue virtualenvwrapper_verify_active_environment
3737
assertSame "env2" $(basename "$VIRTUAL_ENV")
3838
}
@@ -45,7 +45,7 @@ test_hooks () {
4545
chmod +x "$WORKON_HOME/premkvirtualenv"
4646

4747
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
48-
mkvirtualenv "env3"
48+
mkvirtualenv "env3" >/dev/null 2>&1
4949
output=$(cat "$test_dir/catch_output")
5050
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
5151
expected="GLOBAL premkvirtualenv $workon_home_as_pwd env3
@@ -86,6 +86,33 @@ test_no_workon_home () {
8686
WORKON_HOME="$old_home"
8787
}
8888

89+
test_mkvirtualenv_sitepackages () {
90+
# This part of the test is not reliable because
91+
# creating a new virtualenv from inside the
92+
# tox virtualenv inherits the setting from there.
93+
# # Without the option, verify that site-packages are copied.
94+
# mkvirtualenv "with_sp" >/dev/null 2>&1
95+
# ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
96+
# assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]"
97+
# rmvirtualenv "env3"
98+
99+
# With the argument, verify that they are not copied.
100+
mkvirtualenv --no-site-packages "without_sp" >/dev/null 2>&1
101+
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
102+
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
103+
rmvirtualenv "env4"
104+
}
105+
106+
test_mkvirtualenv_args () {
107+
VIRTUALENVWRAPPER_VIRTUALENV_ARGS="--no-site-packages"
108+
# With the argument, verify that they are not copied.
109+
mkvirtualenv "without_sp2" >/dev/null 2>&1
110+
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
111+
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
112+
rmvirtualenv "env4"
113+
unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
114+
}
115+
89116
test_virtualenv_fails () {
90117
# Test to reproduce the conditions in issue #76
91118
# https://bitbucket.org/dhellmann/virtualenvwrapper/issue/76/
@@ -103,7 +130,7 @@ test_virtualenv_fails () {
103130
chmod +x "$WORKON_HOME/premkvirtualenv"
104131

105132
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
106-
mkvirtualenv "env3"
133+
mkvirtualenv "env3" >/dev/null 2>&1
107134
output=$(cat "$test_dir/catch_output" 2>/dev/null)
108135
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
109136
expected=""
@@ -114,26 +141,5 @@ test_virtualenv_fails () {
114141
VIRTUALENVWRAPPER_VIRTUALENV=virtualenv
115142
}
116143

117-
# test_mkvirtualenv_sitepackages () {
118-
# # Without the option verify that site-packages are copied.
119-
# mkvirtualenv "env3"
120-
# assertSame "env3" "$(basename $VIRTUAL_ENV)"
121-
# pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
122-
# sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
123-
# #cat "$sitepackages/easy-install.pth"
124-
# assertTrue "Do not have expected virtualenv.py" "[ -f $sitepackages/virtualenv.py ]"
125-
# rmvirtualenv "env3"
126-
#
127-
# # With the argument, verify that they are not copied.
128-
# mkvirtualenv --no-site-packages "env4"
129-
# assertSame "env4" $(basename "$VIRTUAL_ENV")
130-
# pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
131-
# sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
132-
# assertTrue "[ -f $sitepackages/setuptools.pth ]"
133-
# assertTrue "[ -f $sitepackages/easy-install.pth ]"
134-
# assertFalse "Have virtualenv.py but should not" "[ -f $sitepackages/virtualenv.py ]"
135-
# rmvirtualenv "env4"
136-
# }
137-
138144

139145
. "$test_dir/shunit2"

tests/test_toggleglobalsitepackages.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ tearDown () {
2929

3030
test_toggleglobalsitepackages () {
3131
ngsp_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
32-
assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
32+
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
3333
toggleglobalsitepackages -q
34-
assertFalse "$ngsp_file exists" "[ -f "$ngsp_file" ]"
34+
assertFalse "$ngsp_file exists" "[ -f \"$ngsp_file\" ]"
3535
toggleglobalsitepackages -q
36-
assertTrue "$ngsp_file does not exist" "[ -f "$ngsp_file" ]"
36+
assertTrue "$ngsp_file does not exist" "[ -f \"$ngsp_file\" ]"
3737
}
3838

3939
test_toggleglobalsitepackages_quiet () {

virtualenvwrapper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mkvirtualenv () {
220220
virtualenvwrapper_verify_workon_home || return 1
221221
virtualenvwrapper_verify_virtualenv || return 1
222222
(cd "$WORKON_HOME" &&
223-
"$VIRTUALENVWRAPPER_VIRTUALENV" "$@" &&
223+
"$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" &&
224224
[ -d "$WORKON_HOME/$envname" ] && \
225225
virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname"
226226
)

0 commit comments

Comments
 (0)