@@ -66,61 +66,84 @@ def run_global(script_name, *args):
66
66
GLOBAL_HOOKS = [
67
67
# initialize
68
68
("initialize" ,
69
- "This hook is run during the startup phase "
69
+ "This hook is sourced during the startup phase "
70
70
"when loading virtualenvwrapper.sh." ),
71
71
72
72
# mkvirtualenv
73
73
("premkvirtualenv" ,
74
74
"This hook is run after a new virtualenv is created "
75
75
"and before it is activated." ),
76
+ # argument: name of new environment
76
77
("postmkvirtualenv" ,
77
- "This hook is run after a new virtualenv is activated." ),
78
+ "This hook is sourced after a new virtualenv is activated." ),
79
+
80
+ # cpvirtualenv:
81
+ # precpvirtualenv <old> <new> (run),
82
+ # postcpvirtualenv (sourced)
78
83
79
84
# rmvirtualenv
80
85
("prermvirtualenv" ,
81
86
"This hook is run before a virtualenv is deleted." ),
87
+ # argument: full path to environment directory
82
88
("postrmvirtualenv" ,
83
89
"This hook is run after a virtualenv is deleted." ),
90
+ # argument: full path to environment directory
84
91
85
92
# deactivate
86
93
("predeactivate" ,
87
- "This hook is run before every virtualenv is deactivated." ),
94
+ "This hook is sourced before every virtualenv is deactivated." ),
88
95
("postdeactivate" ,
89
- "This hook is run after every virtualenv is deactivated." ),
96
+ "This hook is sourced after every virtualenv is deactivated." ),
90
97
91
98
# activate
92
99
("preactivate" ,
93
100
"This hook is run before every virtualenv is activated." ),
101
+ # argument: environment name
94
102
("postactivate" ,
95
- "This hook is run after every virtualenv is activated." ),
103
+ "This hook is sourced after every virtualenv is activated." ),
104
+
105
+ # mkproject:
106
+ # premkproject <new project name> (run),
107
+ # postmkproject (sourced)
96
108
97
109
# get_env_details
98
110
("get_env_details" ,
99
111
"This hook is run when the list of virtualenvs is printed "
100
112
"so each name can include details." ),
113
+ # argument: environment name
101
114
]
102
115
103
116
104
117
LOCAL_HOOKS = [
105
118
# deactivate
106
119
("predeactivate" ,
107
- "This hook is run before this virtualenv is deactivated." ),
120
+ "This hook is sourced before this virtualenv is deactivated." ),
108
121
("postdeactivate" ,
109
- "This hook is run after this virtualenv is deactivated." ),
122
+ "This hook is sourced after this virtualenv is deactivated." ),
110
123
111
124
# activate
112
125
("preactivate" ,
113
126
"This hook is run before this virtualenv is activated." ),
114
127
("postactivate" ,
115
- "This hook is run after this virtualenv is activated." ),
128
+ "This hook is sourced after this virtualenv is activated." ),
116
129
117
130
# get_env_details
118
131
("get_env_details" ,
119
132
"This hook is run when the list of virtualenvs is printed "
120
133
"in 'long' mode so each name can include details." ),
134
+ # argument: environment name
121
135
]
122
136
123
137
138
+ SOURCED = ('initialize' ,
139
+ 'postactivate' ,
140
+ 'predeactivate' ,
141
+ 'postdeactivate' ,
142
+ 'postmkproject' ,
143
+ 'postmkvirtualenv' ,
144
+ )
145
+
146
+
124
147
def make_hook (filename , comment ):
125
148
"""Create a hook script.
126
149
@@ -132,13 +155,18 @@ def make_hook(filename, comment):
132
155
log .info ('creating %s' , filename )
133
156
f = open (filename , 'w' )
134
157
try :
158
+ # for sourced scripts, the shebang line won't be used;
159
+ # it is useful for editors to recognize the file type, though
135
160
f .write ("#!%(shell)s\n # %(comment)s\n \n " % {
136
161
'comment' : comment ,
137
162
'shell' : os .environ .get ('SHELL' , '/bin/sh' ),
138
163
})
139
164
finally :
140
165
f .close ()
141
- os .chmod (filename , PERMISSIONS )
166
+ os .chmod (filename ,
167
+ os .path .basename (filename ) in SOURCED
168
+ and PERMISSIONS_SOURCED
169
+ or PERMISSIONS )
142
170
return
143
171
144
172
0 commit comments