@@ -66,51 +66,24 @@ function virtualenvwrapper_verify_workon_home () {
6666 return 0
6767}
6868
69- # Create a hook script
70- #
71- # Usage: virtualenvwrapper_make_hook filename comment
72- #
73- function virtualenvwrapper_make_hook () {
74- filename=" $1 "
75- comment=" $2 "
76- if [ ! -f " $filename " ]
77- then
78- # echo "Creating $filename"
79- cat - > " $filename " << EOF
80- #!/bin/sh
81- # $comment
8269
83- EOF
84- fi
85- if [ ! -x " $filename " ]
86- then
87- chmod +x " $filename "
88- fi
70+ # Run a hook script in the current shell
71+ function virtualenvwrapper_source_hook () {
72+ python -m virtualenvwrapper.hook_loader --source " ${1} _source" >> $TMPDIR /$$ .hook
73+ source $TMPDIR /$$ .hook
74+ rm -f $TMPDIR /$$ .hook
75+ }
76+
77+ # Run a hook script in its own shell
78+ function virtualenvwrapper_run_hook () {
79+ python -m virtualenvwrapper.hook_loader " $@ "
8980}
9081
9182# Set up virtualenvwrapper properly
9283function virtualenvwrapper_initialize () {
9384 virtualenvwrapper_verify_workon_home -q || return 1
94- # mkvirtualenv
95- virtualenvwrapper_make_hook " $WORKON_HOME /premkvirtualenv" \
96- " This hook is run after a new virtualenv is created and before it is activated."
97- virtualenvwrapper_make_hook " $WORKON_HOME /postmkvirtualenv" \
98- " This hook is run after a new virtualenv is activated."
99- # rmvirtualenv
100- virtualenvwrapper_make_hook " $WORKON_HOME /prermvirtualenv" \
101- " This hook is run before a virtualenv is deleted."
102- virtualenvwrapper_make_hook " $WORKON_HOME /postrmvirtualenv" \
103- " This hook is run after a virtualenv is deleted."
104- # deactivate
105- virtualenvwrapper_make_hook " $WORKON_HOME /predeactivate" \
106- " This hook is run before every virtualenv is deactivated."
107- virtualenvwrapper_make_hook " $WORKON_HOME /postdeactivate" \
108- " This hook is run after every virtualenv is deactivated."
109- # activate
110- virtualenvwrapper_make_hook " $WORKON_HOME /preactivate" \
111- " This hook is run before every virtualenv is activated."
112- virtualenvwrapper_make_hook " $WORKON_HOME /postactivate" \
113- " This hook is run after every virtualenv is activated."
85+ virtualenvwrapper_run_hook initialize
86+ virtualenvwrapper_source_hook initialize
11487}
11588
11689virtualenvwrapper_initialize
@@ -152,30 +125,6 @@ function virtualenvwrapper_verify_active_environment () {
152125 return 0
153126}
154127
155- # Run a hook script in the current shell
156- function virtualenvwrapper_source_hook () {
157- scriptname=" $1 "
158- # echo "Looking for hook $scriptname"
159- if [ -f " $scriptname " ]
160- then
161- source " $scriptname "
162- fi
163- }
164-
165- # Run a hook script in its own shell
166- function virtualenvwrapper_run_hook () {
167- scriptname=" $1 "
168- shift
169- # echo "Looking for hook $scriptname"
170- if [ -x " $scriptname " ]
171- then
172- " $scriptname " " $@ "
173- elif [ -e " $scriptname " ]
174- then
175- echo " Warning: Found \" $scriptname \" but it is not executable." 1>&2
176- fi
177- }
178-
179128# Create a new environment, in the WORKON_HOME.
180129#
181130# Usage: mkvirtualenv [options] ENVNAME
0 commit comments