57
57
VIRTUALENVWRAPPER_PYTHON=" $( which python) "
58
58
fi
59
59
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
64
79
65
80
# Verify that the WORKON_HOME directory exists
66
81
virtualenvwrapper_verify_workon_home () {
@@ -74,43 +89,34 @@ virtualenvwrapper_verify_workon_home () {
74
89
75
90
# HOOK_VERBOSE_OPTION="-v"
76
91
77
- # Use Python's tempfile module to create a temporary file
78
- # with a unique and not-likely-to-be-predictable name.
79
92
# Expects 1 argument, the suffix for the new file.
80
93
virtualenvwrapper_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 "
88
95
}
89
96
90
97
# Run the hooks
91
98
virtualenvwrapper_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
95
99
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
100
109
}
101
110
102
111
# Set up virtualenvwrapper properly
103
112
virtualenvwrapper_initialize () {
104
113
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"
108
115
if [ $? -ne 0 ]
109
116
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
111
118
return 1
112
119
fi
113
- virtualenvwrapper_run_hook " initialize"
114
120
}
115
121
116
122
# Verify that virtualenv is installed and visible
0 commit comments