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 77 - Add support for ksh. Thanks to Doug Latornell for doing the
88 research on what needed to be changed.
99 - 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.
1013
11142.0.2
1215
Original file line number Diff line number Diff line change @@ -53,6 +53,27 @@ and the location of the script installed with this package::
5353After editing it, reload the startup file (e.g., run: ``source
5454~/.bashrc ``).
5555
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+
5677Quick-Start
5778===========
5879
Original file line number Diff line number Diff line change @@ -63,5 +63,15 @@ test_get_python_version() {
6363 assertSame " $expected " " $actual "
6464}
6565
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+ }
6676
6777. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -99,11 +99,17 @@ virtualenvwrapper_run_hook () {
9999# Set up virtualenvwrapper properly
100100virtualenvwrapper_initialize () {
101101 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
102110 virtualenvwrapper_run_hook " initialize"
103111}
104112
105- virtualenvwrapper_initialize
106-
107113# Verify that virtualenv is installed and visible
108114virtualenvwrapper_verify_virtualenv () {
109115 venv=$( which virtualenv | grep -v " not found" )
@@ -426,3 +432,8 @@ cpvirtualenv() {
426432 echo " Created $new_env virtualenv"
427433 workon " $new_env "
428434}
435+
436+ #
437+ # Invoke the initialization hooks
438+ #
439+ virtualenvwrapper_initialize
You can’t perform that action at this time.
0 commit comments