@@ -99,12 +99,12 @@ def wrapper(*args, **kwargs):
99
99
return wrapper
100
100
return decorator
101
101
102
- def run_cmd (args , msg = "" , failOnError = True , cwd = None , env = None ):
103
- cwd_log = "cd " + cwd if cwd else ""
102
+ def run_cmd (args , msg = "" , failOnError = True , cwd = None , env = None , quiet = False , ** kwargs ):
103
+ cwd_log = "cd " + cwd + " ;" if cwd else ""
104
104
print ("+" , cwd_log , ' ' .join (args ))
105
- result = subprocess .run (args , cwd = cwd , env = env )
105
+ result = subprocess .run (args , cwd = cwd , env = env , capture_output = quiet , ** kwargs )
106
106
if failOnError and result .returncode != 0 :
107
- xit (msg , status = result .returncode )
107
+ xit (os . linesep . join (( msg , str ( result . stdout ))) , status = result .returncode )
108
108
return result .returncode
109
109
110
110
def known_packages ():
@@ -398,13 +398,13 @@ def xit(msg, status=-1):
398
398
exit (- 1 )
399
399
400
400
401
- def _download_with_curl_and_extract (dest_dir , url ):
401
+ def _download_with_curl_and_extract (dest_dir , url , quiet = False ):
402
402
name = url [url .rfind ("/" )+ 1 :]
403
403
404
404
downloaded_path = os .path .join (dest_dir , name )
405
405
406
406
# first try direct connection
407
- if run_cmd (["curl" , "-L" , "-o" , downloaded_path , url ], failOnError = False ) != 0 :
407
+ if run_cmd (["curl" , "-L" , "-o" , downloaded_path , url ], failOnError = False , quiet = quiet ) != 0 :
408
408
# honor env var 'HTTP_PROXY', 'HTTPS_PROXY', and 'NO_PROXY'
409
409
env = os .environ
410
410
curl_opts = []
@@ -417,16 +417,16 @@ def _download_with_curl_and_extract(dest_dir, url):
417
417
using_proxy = True
418
418
if using_proxy and "NO_PROXY" in env :
419
419
curl_opts += ["--noproxy" , env ["NO_PROXY" ]]
420
- run_cmd (["curl" , "-L" ] + curl_opts + ["-o" , downloaded_path , url ], msg = "Download error" )
420
+ run_cmd (["curl" , "-L" ] + curl_opts + ["-o" , downloaded_path , url ], msg = "Download error" , quiet = quiet )
421
421
422
422
if name .endswith (".tar.gz" ):
423
- run_cmd (["tar" , "xzf" , downloaded_path , "-C" , dest_dir ], msg = "Error extracting tar.gz" )
423
+ run_cmd (["tar" , "xzf" , downloaded_path , "-C" , dest_dir ], msg = "Error extracting tar.gz" , quiet = quiet )
424
424
bare_name = name [:- len (".tar.gz" )]
425
425
elif name .endswith (".tar.bz2" ):
426
- run_cmd (["tar" , "xjf" , downloaded_path , "-C" , dest_dir ], msg = "Error extracting tar.bz2" )
426
+ run_cmd (["tar" , "xjf" , downloaded_path , "-C" , dest_dir ], msg = "Error extracting tar.bz2" , quiet = quiet )
427
427
bare_name = name [:- len (".tar.bz2" )]
428
428
elif name .endswith (".zip" ):
429
- run_cmd (["unzip" , "-u" , downloaded_path , "-d" , dest_dir ], msg = "Error extracting zip" )
429
+ run_cmd (["unzip" , "-u" , downloaded_path , "-d" , dest_dir ], msg = "Error extracting zip" , quiet = quiet )
430
430
bare_name = name [:- len (".zip" )]
431
431
else :
432
432
xit ("Unknown file type: %s" % name )
@@ -437,6 +437,8 @@ def _download_with_curl_and_extract(dest_dir, url):
437
437
def _install_from_url (url , package , extra_opts = [], add_cflags = "" , ignore_errors = False , env = {}, version = None , pre_install_hook = None , build_cmd = []):
438
438
tempdir = tempfile .mkdtemp ()
439
439
440
+ quiet = "-q" in extra_opts
441
+
440
442
os_env = os .environ
441
443
442
444
# honor env var 'CFLAGS' and the explicitly passed env
@@ -445,7 +447,7 @@ def _install_from_url(url, package, extra_opts=[], add_cflags="", ignore_errors=
445
447
cflags = os_env .get ("CFLAGS" , "" ) + ((" " + add_cflags ) if add_cflags else "" )
446
448
setup_env ['CFLAGS' ] = cflags if cflags else ""
447
449
448
- bare_name = _download_with_curl_and_extract (tempdir , url )
450
+ bare_name = _download_with_curl_and_extract (tempdir , url , quiet = quiet )
449
451
450
452
file_realpath = os .path .dirname (os .path .realpath (__file__ ))
451
453
patches_dir = os .path .join (Path (file_realpath ).parent , 'patches' , package )
@@ -455,15 +457,15 @@ def _install_from_url(url, package, extra_opts=[], add_cflags="", ignore_errors=
455
457
456
458
patch_file_path = first_existing (package , versions , os .path .join (patches_dir , "sdist" ), ".patch" )
457
459
if patch_file_path :
458
- run_cmd (["patch" , "-d" , os .path .join (tempdir , bare_name , "" ), "-p1" , "-i" , patch_file_path ])
460
+ run_cmd (["patch" , "-d" , os .path .join (tempdir , bare_name , "" ), "-p1" , "-i" , patch_file_path ], quiet = quiet )
459
461
460
462
whl_patches_dir = os .path .join (patches_dir , "whl" )
461
463
patch_file_path = first_existing (package , versions , whl_patches_dir , ".patch" )
462
464
subdir = read_first_existing (package , versions , whl_patches_dir , ".dir" )
463
465
subdir = "" if subdir is None else subdir
464
466
if patch_file_path :
465
467
os .path .join (tempdir , bare_name , subdir )
466
- run_cmd (["patch" , "-d" , os .path .join (tempdir , bare_name , subdir ), "-p1" , "-i" , patch_file_path ])
468
+ run_cmd (["patch" , "-d" , os .path .join (tempdir , bare_name , subdir ), "-p1" , "-i" , patch_file_path ], quiet = quiet )
467
469
468
470
if pre_install_hook :
469
471
pre_install_hook (os .path .join (tempdir , bare_name ))
@@ -473,9 +475,11 @@ def _install_from_url(url, package, extra_opts=[], add_cflags="", ignore_errors=
473
475
else :
474
476
user_arg = []
475
477
status = run_cmd ([sys .executable , "setup.py" ] + build_cmd + ["install" ] + user_arg + extra_opts , env = setup_env ,
476
- cwd = os .path .join (tempdir , bare_name ))
478
+ cwd = os .path .join (tempdir , bare_name ), quiet = quiet )
477
479
if status != 0 and not ignore_errors :
478
480
xit ("An error occurred trying to run `setup.py install %s %s'" % (user_arg , " " .join (extra_opts )))
481
+ elif quiet :
482
+ info ("{} successfully installed" , package )
479
483
480
484
# NOTE: Following 3 functions are duplicated in pip_hook.py:
481
485
# creates a search list of a versioned file:
@@ -522,7 +526,7 @@ def install_from_pypi(package, extra_opts=[], add_cflags="", ignore_errors=True,
522
526
# this is already the url to the actual package
523
527
pass
524
528
else :
525
- r = subprocess .check_output ("curl -L %s" % url , shell = True ).decode ("utf8" )
529
+ r = subprocess .check_output ("curl -L %s" % url , stderr = subprocess . DEVNULL , shell = True ).decode ("utf8" )
526
530
url = None
527
531
try :
528
532
urls = json .loads (r )["urls" ]
@@ -568,6 +572,7 @@ def get_site_packages_path():
568
572
569
573
def main (argv ):
570
574
parser = argparse .ArgumentParser (description = "The simple Python package installer for GraalVM" )
575
+ parser .add_argument ("--quiet" , "-q" , action = "store_true" , help = "Do not show build output" )
571
576
572
577
subparsers = parser .add_subparsers (title = "Commands" , dest = "command" , metavar = "Use COMMAND --help for further help." )
573
578
@@ -614,6 +619,8 @@ def main(argv):
614
619
)
615
620
616
621
args = parser .parse_args (argv )
622
+
623
+ quiet_flag = ["-q" ] if args .quiet else []
617
624
618
625
if args .command == "list" :
619
626
user_site = get_site_packages_path ()
@@ -646,15 +653,15 @@ def main(argv):
646
653
if pkg not in KNOWN_PACKAGES :
647
654
xit ("Unknown package: '%s'" % pkg )
648
655
else :
649
- extra_opts = []
656
+ extra_opts = [] + quiet_flag
650
657
if args .prefix :
651
658
extra_opts += ["--prefix" , args .prefix ]
652
659
if args .user :
653
660
extra_opts += ["--user" ]
654
661
KNOWN_PACKAGES [pkg ](extra_opts = extra_opts )
655
662
elif args .command == "pypi" :
656
663
for pkg in args .package .split ("," ):
657
- install_from_pypi (pkg , ignore_errors = False )
664
+ install_from_pypi (pkg , extra_opts = quiet_flag , ignore_errors = False )
658
665
659
666
660
667
if __name__ == "__main__" :
0 commit comments