File tree Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Expand file tree Collapse file tree 4 files changed +47
-2
lines changed Original file line number Diff line number Diff line change 7
7
- Add support for ksh. Thanks to Doug Latornell for doing the
8
8
research on what needed to be changed.
9
9
- Switch to ``tempfile `` command for creating temporary hook files.
10
+ - Test import of virtualenvwrapper.hook_loader on startup and report
11
+ the error in a way that should help the user figure out how to fix
12
+ it.
10
13
11
14
2.0.2
12
15
Original file line number Diff line number Diff line change @@ -53,6 +53,27 @@ and the location of the script installed with this package::
53
53
After editing it, reload the startup file (e.g., run: ``source
54
54
~/.bashrc ``).
55
55
56
+ Python Interpreter and $PATH
57
+ ============================
58
+
59
+ During startup, ``virtualenvwrapper.sh `` finds the first ``python `` on
60
+ the ``$PATH `` and remembers it to use later. This eliminates any
61
+ conflict as the ``$PATH `` changes, enabling interpreters inside
62
+ virtual environments where virtualenvwrapper is not installed.
63
+ Because of this behavior, it is important for the ``$PATH `` to be set
64
+ **before ** sourcing ``virtualenvwrapper.sh ``. For example::
65
+
66
+ export PATH=/usr/local/bin:$PATH
67
+ source /usr/local/bin/virtualenvwrapper.sh
68
+
69
+ To override the ``$PATH `` search, set the variable
70
+ ``VIRTUALENVWRAPPER_PYTHON `` to the full path of the interpreter to
71
+ use (also **before ** sourcing ``virtualenvwrapper.sh ``). For
72
+ example::
73
+
74
+ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
75
+ source /usr/local/bin/virtualenvwrapper.sh
76
+
56
77
Quick-Start
57
78
===========
58
79
Original file line number Diff line number Diff line change @@ -63,5 +63,15 @@ test_get_python_version() {
63
63
assertSame " $expected " " $actual "
64
64
}
65
65
66
+ test_python_interpreter_set_incorrectly () {
67
+ return_to=" $( pwd) "
68
+ cd " $WORKON_HOME "
69
+ mkvirtualenv --no-site-packages no_wrappers
70
+ output=` VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV /bin/python $SHELL $return_to /virtualenvwrapper.sh 2>&1 `
71
+ assertTrue " Unexpected message: $output " " echo \" $output \" | grep 'Could not find Python module virtualenvwrapper.hook_loader'"
72
+ assertFalse " Failed to detect invalid Python location" " VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV /bin/python $SHELL $return_to /virtualenvwrapper.sh >/dev/null 2>&1"
73
+ cd " $return_to "
74
+ deactivate
75
+ }
66
76
67
77
. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -99,11 +99,17 @@ virtualenvwrapper_run_hook () {
99
99
# Set up virtualenvwrapper properly
100
100
virtualenvwrapper_initialize () {
101
101
virtualenvwrapper_verify_workon_home -q || return 1
102
+ # Test for the virtualenvwrapper package we need so we can report
103
+ # an installation problem.
104
+ " $VIRTUALENVWRAPPER_PYTHON " -c " import virtualenvwrapper.hook_loader" > /dev/null 2>&1
105
+ if [ $? -ne 0 ]
106
+ then
107
+ echo " virtualenvwrapper.sh: Could not find Python module virtualenvwrapper.hook_loader using VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON . Is the PATH set properly?" 1>&2
108
+ return 1
109
+ fi
102
110
virtualenvwrapper_run_hook " initialize"
103
111
}
104
112
105
- virtualenvwrapper_initialize
106
-
107
113
# Verify that virtualenv is installed and visible
108
114
virtualenvwrapper_verify_virtualenv () {
109
115
venv=$( which virtualenv | grep -v " not found" )
@@ -426,3 +432,8 @@ cpvirtualenv() {
426
432
echo " Created $new_env virtualenv"
427
433
workon " $new_env "
428
434
}
435
+
436
+ #
437
+ # Invoke the initialization hooks
438
+ #
439
+ virtualenvwrapper_initialize
You can’t perform that action at this time.
0 commit comments