@@ -71,24 +71,23 @@ function virtualenvwrapper_verify_workon_home () {
7171
7272HOOK_VERBOSE_OPTION=" -v"
7373
74- # Run a hook script in the current shell
75- function virtualenvwrapper_source_hook () {
74+ # Run the hooks
75+ function virtualenvwrapper_run_hook () {
76+ # First anything that runs directly from the plugin
77+ " $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION " $@ "
78+ # Now anything that wants to run inside this shell
79+ hook_name=" $1 "
80+ shift # get rid of hook name
7681 " $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION \
77- --source " ${1 } _source" >> $TMPDIR /$$ .hook
82+ --source " ${hook_name } _source" " $@ " >> $TMPDIR /$$ .hook
7883 source $TMPDIR /$$ .hook
7984 rm -f $TMPDIR /$$ .hook
8085}
8186
82- # Run a hook script in its own shell
83- function virtualenvwrapper_run_hook () {
84- " $VIRTUALENVWRAPPER_PYTHON " -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION " $@ "
85- }
86-
8787# Set up virtualenvwrapper properly
8888function virtualenvwrapper_initialize () {
8989 virtualenvwrapper_verify_workon_home -q || return 1
90- virtualenvwrapper_run_hook initialize
91- virtualenvwrapper_source_hook initialize
90+ virtualenvwrapper_run_hook " initialize"
9291}
9392
9493virtualenvwrapper_initialize
@@ -150,7 +149,6 @@ function mkvirtualenv () {
150149 # Now activate the new environment
151150 workon " $envname "
152151 virtualenvwrapper_run_hook " post_mkvirtualenv"
153- virtualenvwrapper_source_hook " post_mkvirtualenv"
154152}
155153
156154# Remove an environment, in the WORKON_HOME.
@@ -169,9 +167,9 @@ function rmvirtualenv () {
169167 echo " Either switch to another environment, or run 'deactivate'." >&2
170168 return 1
171169 fi
172- virtualenvwrapper_run_hook " $WORKON_HOME /prermvirtualenv " " $env_dir "
170+ virtualenvwrapper_run_hook " pre_rmvirtualenv " " $env_name "
173171 rm -rf " $env_dir "
174- virtualenvwrapper_run_hook " $WORKON_HOME /postrmvirtualenv " " $env_dir "
172+ virtualenvwrapper_run_hook " post_rmvirtualenv " " $env_name "
175173}
176174
177175# List the available environments.
@@ -215,8 +213,7 @@ function workon () {
215213 deactivate
216214 fi
217215
218- virtualenvwrapper_run_hook " $WORKON_HOME /preactivate"
219- virtualenvwrapper_run_hook " $WORKON_HOME /$env_name /bin/preactivate"
216+ virtualenvwrapper_run_hook " pre_activate" " $env_name "
220217
221218 source " $activate "
222219
@@ -227,23 +224,21 @@ function workon () {
227224 eval ' function deactivate () {
228225 # Call the local hook before the global so we can undo
229226 # any settings made by the local postactivate first.
230- virtualenvwrapper_source_hook "$VIRTUAL_ENV/bin/predeactivate"
231- virtualenvwrapper_source_hook "$WORKON_HOME/predeactivate"
227+ virtualenvwrapper_run_hook "pre_deactivate"
232228
233229 env_postdeactivate_hook="$VIRTUAL_ENV/bin/postdeactivate"
230+ old_env=$(basename "$VIRTUAL_ENV")
234231
235232 # Restore the original definition of deactivate
236233 eval "$virtualenvwrapper_saved_deactivate"
237234
238235 # Instead of recursing, this calls the now restored original function.
239236 deactivate
240237
241- virtualenvwrapper_source_hook "$env_postdeactivate_hook"
242- virtualenvwrapper_source_hook "$WORKON_HOME/postdeactivate"
238+ virtualenvwrapper_run_hook "post_deactivate" "$old_env"
243239 }'
244240
245- virtualenvwrapper_source_hook " $WORKON_HOME /postactivate"
246- virtualenvwrapper_source_hook " $VIRTUAL_ENV /bin/postactivate"
241+ virtualenvwrapper_run_hook " post_activate"
247242
248243 return 0
249244}
0 commit comments