1212import subprocess
1313import sys
1414
15- import pkg_resources
1615
1716log = logging .getLogger (__name__ )
1817
19-
2018# Are we running under msys
21- if sys .platform == 'win32' and os .environ .get ('OS' ) == 'Windows_NT' and os .environ .get ('MSYSTEM' ) == 'MINGW32' :
19+ if (sys .platform == 'win32'
20+ and
21+ os .environ .get ('OS' ) == 'Windows_NT'
22+ and
23+ os .environ .get ('MSYSTEM' ) == 'MINGW32' ):
2224 is_msys = True
2325 script_folder = 'Scripts'
2426else :
@@ -32,12 +34,12 @@ def run_script(script_path, *args):
3234 if os .path .exists (script_path ):
3335 cmd = [script_path ] + list (args )
3436 if is_msys :
35- cmd = [get_path (os .environ ['MSYS_HOME' ],'bin' ,'sh.exe' )] + cmd
37+ cmd = [get_path (os .environ ['MSYS_HOME' ], 'bin' , 'sh.exe' )] + cmd
3638 log .debug ('running %s' , str (cmd ))
3739 try :
38- return_code = subprocess .call (cmd )
40+ subprocess .call (cmd )
3941 except OSError :
40- _ , msg , _ = sys .exc_info ()
42+ _ , msg , _ = sys .exc_info ()
4143 log .error ('could not run "%s": %s' , script_path , str (msg ))
4244 #log.debug('Returned %s', return_code)
4345 return
@@ -85,7 +87,8 @@ def run_global(script_name, *args):
8587
8688 # get_env_details
8789 ("get_env_details" ,
88- "This hook is run when the list of virtualenvs is printed so each name can include details." ),
90+ "This hook is run when the list of virtualenvs is printed "
91+ "so each name can include details." ),
8992 ]
9093
9194
@@ -104,13 +107,14 @@ def run_global(script_name, *args):
104107
105108 # get_env_details
106109 ("get_env_details" ,
107- "This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details." ),
110+ "This hook is run when the list of virtualenvs is printed "
111+ "in 'long' mode so each name can include details." ),
108112 ]
109113
110114
111115def make_hook (filename , comment ):
112116 """Create a hook script.
113-
117+
114118 :param filename: The name of the file to write.
115119 :param comment: The comment to insert into the file.
116120 """
@@ -122,14 +126,15 @@ def make_hook(filename, comment):
122126 f .write ("""#!%(shell)s
123127# %(comment)s
124128
125- """ % {'comment' :comment , 'shell' :os .environ .get ('SHELL' , '/bin/sh' )})
129+ """ % {'comment' : comment ,
130+ 'shell' : os .environ .get ('SHELL' , '/bin/sh' ),
131+ })
126132 finally :
127133 f .close ()
128134 os .chmod (filename , PERMISSIONS )
129135 return
130136
131137
132-
133138# HOOKS
134139
135140
@@ -147,9 +152,10 @@ def initialize_source(args):
147152[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/initialize" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/initialize"
148153"""
149154
155+
150156def pre_mkvirtualenv (args ):
151157 log .debug ('pre_mkvirtualenv %s' , str (args ))
152- envname = args [0 ]
158+ envname = args [0 ]
153159 for filename , comment in LOCAL_HOOKS :
154160 make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ), comment )
155161 run_global ('premkvirtualenv' , * args )
@@ -164,9 +170,10 @@ def post_mkvirtualenv_source(args):
164170[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postmkvirtualenv"
165171"""
166172
173+
167174def pre_cpvirtualenv (args ):
168175 log .debug ('pre_cpvirtualenv %s' , str (args ))
169- envname = args [0 ]
176+ envname = args [0 ]
170177 for filename , comment in LOCAL_HOOKS :
171178 make_hook (get_path ('$WORKON_HOME' , envname , script_folder , filename ), comment )
172179 run_global ('precpvirtualenv' , * args )
@@ -234,7 +241,7 @@ def post_deactivate_source(args):
234241[ -f "$WORKON_HOME/%(env_name)s/bin/postdeactivate" ] && source "$WORKON_HOME/%(env_name)s/bin/postdeactivate"
235242[ -f "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate" ] && source "$VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate"
236243unset VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV
237- """ % { 'env_name' :args [0 ] }
244+ """ % {'env_name' : args [0 ]}
238245
239246
240247def get_env_details (args ):
@@ -244,18 +251,22 @@ def get_env_details(args):
244251 run_script (script_path , * args )
245252 return
246253
254+
247255def get_path (* args ):
248256 '''
249257 Get a full path from args.
250- Path separator is determined according to the os and the shell and allow to use is_msys.
258+
259+ Path separator is determined according to the os and the shell and
260+ allow to use is_msys.
261+
251262 Variables and user are expanded during the process.
252263 '''
253264 path = os .path .expanduser (os .path .expandvars (os .path .join (* args )))
254265 if is_msys :
255266 # MSYS accept unix or Win32 and sometimes it drives to mixed style paths
256267 if re .match (r'^/[a-zA-Z](/|^)' , path ):
257268 # msys path could starts with '/c/'-form drive letter
258- path = '' .join ((path [1 ],':' ,path [2 :]))
269+ path = '' .join ((path [1 ], ':' , path [2 :]))
259270 path = path .replace ('/' , os .sep )
260-
271+
261272 return os .path .abspath (path )
0 commit comments