16
16
log = logging .getLogger (__name__ )
17
17
18
18
# Are we running under msys
19
- if (sys .platform == 'win32'
20
- and
21
- os .environ .get ('OS' ) == 'Windows_NT'
22
- and
23
- os .environ .get ('MSYSTEM' ) == 'MINGW32' ):
19
+ if sys .platform == 'win32' and \
20
+ os .environ .get ('OS' ) == 'Windows_NT' and \
21
+ os .environ .get ('MSYSTEM' ) == 'MINGW32' :
24
22
is_msys = True
25
23
script_folder = 'Scripts'
26
24
else :
@@ -59,11 +57,13 @@ def run_global(script_name, *args):
59
57
GLOBAL_HOOKS = [
60
58
# initialize
61
59
("initialize" ,
62
- "This hook is run during the startup phase when loading virtualenvwrapper.sh." ),
60
+ "This hook is run during the startup phase "
61
+ "when loading virtualenvwrapper.sh." ),
63
62
64
63
# mkvirtualenv
65
64
("premkvirtualenv" ,
66
- "This hook is run after a new virtualenv is created and before it is activated." ),
65
+ "This hook is run after a new virtualenv is created "
66
+ "and before it is activated." ),
67
67
("postmkvirtualenv" ,
68
68
"This hook is run after a new virtualenv is activated." ),
69
69
@@ -89,7 +89,7 @@ def run_global(script_name, *args):
89
89
("get_env_details" ,
90
90
"This hook is run when the list of virtualenvs is printed "
91
91
"so each name can include details." ),
92
- ]
92
+ ]
93
93
94
94
95
95
LOCAL_HOOKS = [
@@ -109,7 +109,7 @@ def run_global(script_name, *args):
109
109
("get_env_details" ,
110
110
"This hook is run when the list of virtualenvs is printed "
111
111
"in 'long' mode so each name can include details." ),
112
- ]
112
+ ]
113
113
114
114
115
115
def make_hook (filename , comment ):
@@ -149,15 +149,17 @@ def initialize_source(args):
149
149
#
150
150
# Run user-provided scripts
151
151
#
152
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
152
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && \
153
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
153
154
"""
154
155
155
156
156
157
def pre_mkvirtualenv (args ):
157
158
log .debug ('pre_mkvirtualenv %s' , str (args ))
158
159
envname = args [0 ]
159
160
for filename , comment in LOCAL_HOOKS :
160
- make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ), comment )
161
+ make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
162
+ comment )
161
163
run_global ('premkvirtualenv' , * args )
162
164
return
163
165
@@ -167,15 +169,17 @@ def post_mkvirtualenv_source(args):
167
169
#
168
170
# Run user-provided scripts
169
171
#
170
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
172
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && \
173
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
171
174
"""
172
175
173
176
174
177
def pre_cpvirtualenv (args ):
175
178
log .debug ('pre_cpvirtualenv %s' , str (args ))
176
179
envname = args [0 ]
177
180
for filename , comment in LOCAL_HOOKS :
178
- make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ), comment )
181
+ make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ),
182
+ comment )
179
183
run_global ('precpvirtualenv' , * args )
180
184
return
181
185
@@ -185,7 +189,8 @@ def post_cpvirtualenv_source(args):
185
189
#
186
190
# Run user-provided scripts
187
191
#
188
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
192
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && \
193
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
189
194
"""
190
195
191
196
@@ -204,7 +209,8 @@ def post_rmvirtualenv(args):
204
209
def pre_activate (args ):
205
210
log .debug ('pre_activate' )
206
211
run_global ('preactivate' , * args )
207
- script_path = get_path ('$WORKON_HOME' , args [0 ], script_folder , 'preactivate' )
212
+ script_path = get_path ('$WORKON_HOME' , args [0 ],
213
+ script_folder , 'preactivate' )
208
214
run_script (script_path , * args )
209
215
return
210
216
@@ -215,8 +221,10 @@ def post_activate_source(args):
215
221
#
216
222
# Run user-provided scripts
217
223
#
218
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
219
- [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
224
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate" ] && \
225
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postactivate"
226
+ [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate" ] && \
227
+ source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postactivate"
220
228
"""
221
229
222
230
@@ -226,8 +234,10 @@ def pre_deactivate_source(args):
226
234
#
227
235
# Run user-provided scripts
228
236
#
229
- [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
230
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
237
+ [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate" ] && \
238
+ source "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/predeactivate"
239
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate" ] && \
240
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/predeactivate"
231
241
"""
232
242
233
243
@@ -238,16 +248,19 @@ def post_deactivate_source(args):
238
248
# Run user-provided scripts
239
249
#
240
250
VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV="$WORKON_HOME/%(env_name)s"
241
- [ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
242
- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
251
+ [ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && \
252
+ source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
253
+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && \
254
+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
243
255
unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
244
256
""" % {'env_name' : args [0 ]}
245
257
246
258
247
259
def get_env_details (args ):
248
260
log .debug ('get_env_details' )
249
261
run_global ('get_env_details' , * args )
250
- script_path = get_path ('$WORKON_HOME' , args [0 ], script_folder , 'get_env_details' )
262
+ script_path = get_path ('$WORKON_HOME' , args [0 ],
263
+ script_folder , 'get_env_details' )
251
264
run_script (script_path , * args )
252
265
return
253
266
@@ -263,7 +276,8 @@ def get_path(*args):
263
276
'''
264
277
path = os .path .expanduser (os .path .expandvars (os .path .join (* args )))
265
278
if is_msys :
266
- # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
279
+ # MSYS accept unix or Win32 and sometimes
280
+ # it drives to mixed style paths
267
281
if re .match (r'^/[a-zA-Z](/|^)' , path ):
268
282
# msys path could starts with '/c/'-form drive letter
269
283
path = '' .join ((path [1 ], ':' , path [2 :]))
0 commit comments