5757 VIRTUALENVWRAPPER_PYTHON=" $( which python) "
5858fi
5959
60- # Normalize the directory name in case it includes
61- # relative path components.
62- WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.abspath(os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" )))" )
63- export WORKON_HOME
60+ # If the path is relative, prefix it with $HOME
61+ # (note: for compatibility)
62+ if echo " $WORKON_HOME " | grep -e ' ^[^/~]'
63+ then
64+ export WORKON_HOME=" $HOME /$WORKON_HOME "
65+ fi
66+
67+ # Only call on Python to fix the path if it looks like the
68+ # path might contain stuff to expand.
69+ # (it might be possible to do this in shell, but I don't know a
70+ # cross-shell-safe way of doing it -wolever)
71+ if echo " $WORKON_HOME " | grep -e " [$~]"
72+ then
73+ # This will normalize the path by:
74+ # - Expanding variables (eg, $foo)
75+ # - Converting ~s to complete paths (eg, ~/ to /home/brian/ and ~arthur to /home/arthur)
76+ WORKON_HOME=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import os; print os.path.expandvars(os.path.expanduser(\" $WORKON_HOME \" ))" )
77+ export WORKON_HOME
78+ fi
6479
6580# Verify that the WORKON_HOME directory exists
6681virtualenvwrapper_verify_workon_home () {
@@ -74,43 +89,34 @@ virtualenvwrapper_verify_workon_home () {
7489
7590# HOOK_VERBOSE_OPTION="-v"
7691
77- # Use Python's tempfile module to create a temporary file
78- # with a unique and not-likely-to-be-predictable name.
7992# Expects 1 argument, the suffix for the new file.
8093virtualenvwrapper_tempfile () {
81- typeset base=$( " $VIRTUALENVWRAPPER_PYTHON " -c " import tempfile; print tempfile.NamedTemporaryFile(prefix='virtualenvwrapper.').name" )
82- if [ -z " $base " ]
83- then
84- echo " ${TMPDIR:-/ tmp} /virtualenvwrapper.$$ .` date +%s` .$1 "
85- else
86- echo " $base .$1 "
87- fi
94+ tempfile " virtualenvwrapper-XXXXXX-$1 "
8895}
8996
9097# Run the hooks
9198virtualenvwrapper_run_hook () {
92- # First anything that runs directly from the plugin
93- " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION " $@ "
94- # Now anything that wants to run inside this shell
9599 hook_script=" $( virtualenvwrapper_tempfile hook) "
96- " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION \
97- --source " $@ " >> " $hook_script "
98- source " $hook_script "
99- rm -f " $hook_script "
100+ " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --run-hook-and-write-source " $hook_script " " $@ "
101+ result=$?
102+
103+ if [ $result -eq 0 ]
104+ then
105+ source " $hook_script "
106+ fi
107+ rm -f " $hook_script " > /dev/null 2>&1
108+ return $result
100109}
101110
102111# Set up virtualenvwrapper properly
103112virtualenvwrapper_initialize () {
104113 virtualenvwrapper_verify_workon_home -q || return 1
105- # Test for the virtualenvwrapper package we need so we can report
106- # an installation problem.
107- " $VIRTUALENVWRAPPER_PYTHON " -c " import virtualenvwrapper.hook_loader" > /dev/null 2>&1
114+ virtualenvwrapper_run_hook " initialize"
108115 if [ $? -ne 0 ]
109116 then
110- echo " virtualenvwrapper.sh: Could not find Python module virtualenvwrapper.hook_loader using VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON . Is the PATH set properly? " 1>&2
117+ echo " virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH set properly. " 1>&2
111118 return 1
112119 fi
113- virtualenvwrapper_run_hook " initialize"
114120}
115121
116122# Verify that virtualenv is installed and visible
0 commit comments