12
12
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
13
# specific language governing permissions and limitations under the License.
14
14
15
-
16
15
"""
17
16
This script a configuration helper to select pip requirement files to install
18
17
and python and shell configuration scripts to execute based on provided config
74
73
import shutil
75
74
import subprocess
76
75
77
-
78
76
# platform-specific file base names
79
77
sys_platform = str (sys .platform ).lower ()
80
78
on_win = False
89
87
raise Exception ('Unsupported OS/platform' )
90
88
platform_names = tuple ()
91
89
92
-
93
90
# common file basenames for requirements and scripts
94
91
base = ('base' ,)
95
92
108
105
shell_scripts = ('win.bat' ,)
109
106
110
107
111
- def call (cmd , root_dir ):
108
+ def call (cmd , root_dir , quiet = True ):
112
109
""" Run a `cmd` command (as a list of args) with all env vars."""
113
110
cmd = ' ' .join (cmd )
111
+ if not quiet :
112
+ print (' Running command:' , repr (cmd ))
113
+
114
114
if subprocess .Popen (cmd , shell = True , env = dict (os .environ ), cwd = root_dir ).wait () != 0 :
115
115
print ()
116
116
print ('Failed to execute command:\n %(cmd)s. Aborting...' % locals ())
@@ -188,18 +188,18 @@ def create_virtualenv(std_python, root_dir, tpp_dirs, quiet=False):
188
188
components.
189
189
"""
190
190
if not quiet :
191
- print (" * Configuring Python ..." )
191
+ print (' * Configuring Python ...' )
192
192
# search virtualenv.py in the tpp_dirs. keep the first found
193
193
venv_py = None
194
194
for tpd in tpp_dirs :
195
195
venv = os .path .join (root_dir , tpd , 'virtualenv.py' )
196
196
if os .path .exists (venv ):
197
- venv_py = '"' + venv + '" '
197
+ venv_py = ''' + venv + '' '
198
198
break
199
199
200
200
# error out if venv_py not found
201
201
if not venv_py :
202
- print (" Configuration Error ... aborting." )
202
+ print (' Configuration Error ... aborting.' )
203
203
exit (1 )
204
204
205
205
vcmd = [std_python , venv_py , '--never-download' ]
@@ -209,12 +209,12 @@ def create_virtualenv(std_python, root_dir, tpp_dirs, quiet=False):
209
209
vcmd .extend (build_pip_dirs_args (tpp_dirs , root_dir ))
210
210
# we create the virtualenv in the root_dir
211
211
vcmd .append ('"' + root_dir + '"' )
212
- call (vcmd , root_dir )
212
+ call (vcmd , root_dir , quiet )
213
213
214
214
215
215
def activate (root_dir ):
216
216
""" Activate a virtualenv in the current process."""
217
- print (" * Activating ..." )
217
+ print (' * Activating ...' )
218
218
bin_dir = os .path .join (root_dir , 'bin' )
219
219
activate_this = os .path .join (bin_dir , 'activate_this.py' )
220
220
with open (activate_this ) as f :
@@ -228,29 +228,36 @@ def install_3pp(configs, root_dir, tpp_dirs, quiet=False):
228
228
using the vendored components in `tpp_dirs`.
229
229
"""
230
230
if not quiet :
231
- print (" * Installing components ..." )
231
+ print (' * Installing components ...' )
232
232
requirement_files = get_conf_files (configs , root_dir , requirements )
233
233
for req_file in requirement_files :
234
- pcmd = ['pip' , 'install' , '--no-index' , '--no-cache-dir' ]
234
+ if on_win :
235
+ pcmd = ['python' , '-m' ]
236
+ else :
237
+ pcmd = []
238
+ pcmd += ['pip' , 'install' , '--no-index' , '--no-cache-dir' ]
235
239
if quiet :
236
240
pcmd += ['--quiet' ]
241
+ if on_win :
242
+ pcmd += ['--verbose' , '--verbose' , '--verbose' ]
243
+
237
244
pip_dir_args = list (build_pip_dirs_args (tpp_dirs , root_dir , '--find-links=' ))
238
245
pcmd .extend (pip_dir_args )
239
246
req_loc = os .path .join (root_dir , req_file )
240
247
pcmd .extend (['-r' , '"' + req_loc + '"' ])
241
- call (pcmd , root_dir )
248
+ call (pcmd , root_dir , quiet )
242
249
243
250
244
251
def run_scripts (configs , root_dir , configured_python , quiet = False ):
245
252
"""
246
253
Run Python scripts and shell scripts found in `configs`.
247
254
"""
248
255
if not quiet :
249
- print (" * Configuring ..." )
256
+ print (' * Configuring ...' )
250
257
# Run Python scripts for each configurations
251
258
for py_script in get_conf_files (configs , root_dir , python_scripts ):
252
259
cmd = [configured_python , '"' + os .path .join (root_dir , py_script ) + '"' ]
253
- call (cmd , root_dir )
260
+ call (cmd , root_dir , quiet )
254
261
255
262
# Run sh_script scripts for each configurations
256
263
for sh_script in get_conf_files (configs , root_dir , shell_scripts ):
@@ -259,7 +266,7 @@ def run_scripts(configs, root_dir, configured_python, quiet=False):
259
266
if on_win :
260
267
cmd = []
261
268
cmd = cmd + [os .path .join (root_dir , sh_script )]
262
- call (cmd , root_dir )
269
+ call (cmd , root_dir , quiet )
263
270
264
271
265
272
def chmod_bin (directory ):
@@ -352,8 +359,11 @@ def get_conf_files(config_dir_paths, root_dir, file_names=requirements):
352
359
if not os .path .exists (scripts_dir ):
353
360
os .makedirs (scripts_dir )
354
361
if not os .path .exists (bin_dir ):
355
- cmd = ('mklink /J "%(bin_dir)s" "%(scripts_dir)s"' % locals ()).split ()
356
- call (cmd , root_dir )
362
+ cmd = [
363
+ 'mklink' , '/J' ,
364
+ '"%(bin_dir)s"' % locals (),
365
+ '"%(scripts_dir)s"' % locals ()]
366
+ call (cmd , root_dir , run_quiet )
357
367
else :
358
368
configured_python = os .path .join (bin_dir , 'python' )
359
369
scripts_dir = bin_dir
@@ -398,5 +408,5 @@ def get_conf_files(config_dir_paths, root_dir, file_names=requirements):
398
408
run_scripts (configs , root_dir , configured_python , quiet = run_quiet )
399
409
chmod_bin (bin_dir )
400
410
if not run_quiet :
401
- print (" * Configuration completed." )
411
+ print (' * Configuration completed.' )
402
412
print ()
0 commit comments