1616log = logging .getLogger (__name__ )
1717
1818# 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' :
2422 is_msys = True
2523 script_folder = 'Scripts'
2624else :
@@ -59,11 +57,13 @@ def run_global(script_name, *args):
5957GLOBAL_HOOKS = [
6058 # initialize
6159 ("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." ),
6362
6463 # mkvirtualenv
6564 ("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." ),
6767 ("postmkvirtualenv" ,
6868 "This hook is run after a new virtualenv is activated." ),
6969
@@ -89,7 +89,7 @@ def run_global(script_name, *args):
8989 ("get_env_details" ,
9090 "This hook is run when the list of virtualenvs is printed "
9191 "so each name can include details." ),
92- ]
92+ ]
9393
9494
9595LOCAL_HOOKS = [
@@ -109,7 +109,7 @@ def run_global(script_name, *args):
109109 ("get_env_details" ,
110110 "This hook is run when the list of virtualenvs is printed "
111111 "in 'long' mode so each name can include details." ),
112- ]
112+ ]
113113
114114
115115def make_hook (filename , comment ):
@@ -149,15 +149,17 @@ def initialize_source(args):
149149#
150150# Run user-provided scripts
151151#
152- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
152+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && \
153+ source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
153154"""
154155
155156
156157def pre_mkvirtualenv (args ):
157158 log .debug ('pre_mkvirtualenv %s' , str (args ))
158159 envname = args [0 ]
159160 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 )
161163 run_global ('premkvirtualenv' , * args )
162164 return
163165
@@ -167,15 +169,17 @@ def post_mkvirtualenv_source(args):
167169#
168170# Run user-provided scripts
169171#
170- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
172+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && \
173+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
171174"""
172175
173176
174177def pre_cpvirtualenv (args ):
175178 log .debug ('pre_cpvirtualenv %s' , str (args ))
176179 envname = args [0 ]
177180 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 )
179183 run_global ('precpvirtualenv' , * args )
180184 return
181185
@@ -185,7 +189,8 @@ def post_cpvirtualenv_source(args):
185189#
186190# Run user-provided scripts
187191#
188- [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
192+ [ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv" ] && \
193+ source "$VIRTUALENVWRAPPER_HOOK_DIR/postcpvirtualenv"
189194"""
190195
191196
@@ -204,7 +209,8 @@ def post_rmvirtualenv(args):
204209def pre_activate (args ):
205210 log .debug ('pre_activate' )
206211 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' )
208214 run_script (script_path , * args )
209215 return
210216
@@ -215,8 +221,10 @@ def post_activate_source(args):
215221#
216222# Run user-provided scripts
217223#
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"
220228"""
221229
222230
@@ -226,8 +234,10 @@ def pre_deactivate_source(args):
226234#
227235# Run user-provided scripts
228236#
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"
231241"""
232242
233243
@@ -238,16 +248,19 @@ def post_deactivate_source(args):
238248# Run user-provided scripts
239249#
240250VIRTUALENVWRAPPER_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"
243255unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
244256""" % {'env_name' : args [0 ]}
245257
246258
247259def get_env_details (args ):
248260 log .debug ('get_env_details' )
249261 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' )
251264 run_script (script_path , * args )
252265 return
253266
@@ -263,7 +276,8 @@ def get_path(*args):
263276 '''
264277 path = os .path .expanduser (os .path .expandvars (os .path .join (* args )))
265278 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
267281 if re .match (r'^/[a-zA-Z](/|^)' , path ):
268282 # msys path could starts with '/c/'-form drive letter
269283 path = '' .join ((path [1 ], ':' , path [2 :]))
0 commit comments