@@ -444,6 +444,13 @@ def get_handler_filename(handler):
444444
445445
446446def _install_package (package , path ):
447+ """ Runs python pip install $(package) -t $(path) --ignore-installed command
448+
449+ :param str package:
450+ Name of the package or directory to the local src
451+ :param str path:
452+ Path to copy installed pip packages to.
453+ """
447454 subprocess .check_call (
448455 [
449456 sys .executable ,
@@ -457,6 +464,29 @@ def _install_package(package, path):
457464 ]
458465 )
459466
467+ def _install_local_package (package , path ):
468+ """ Install a local package and install it. Uses `pip show` to find the
469+ local location
470+ :param str package:
471+ Name of the local package
472+ :param str path:
473+ Path to copy installed pip packages to.
474+ """
475+ print (f"Running pip show { package } " )
476+ proc = subprocess .run ([sys .executable , "-m" , "pip" , "show" , package ], stdout = subprocess .PIPE )
477+ if not proc .stdout :
478+ return False
479+
480+ out = str (proc .stdout , "utf-8" )
481+ captures = re .search ("Location: ([^ \n ]+)" , out )
482+ if not captures :
483+ return False
484+
485+ directory = captures .groups ()[0 ]
486+ _install_package (directory , path )
487+ return True
488+
489+
460490def _install_packages (path , packages ):
461491 """Install all packages listed to the target directory.
462492
@@ -484,17 +514,18 @@ def _filter_blacklist(package):
484514 _install_package (package , path )
485515 except subprocess .CalledProcessError as e :
486516 try :
487- print ("Failed install of {package} " .format (package = package ))
488517 # editable local package are can also be named as `-e git+git@...#egg=$(local_name)`
489518 # this try attempts to find the egg name, and install it
490- captures = re .findall ("egg=([\w+_-]+)" , package )
491- if captures :
492- alternative = captures [0 ]
493- print ("Trying to install with alternative name {alternative}" .format (alternative = alternative ))
494- _install_package (alternative , path )
495-
496- except subprocess .CalledProcessError as e :
497- pass
519+ captures = re .search ("egg=([\w+_-]+)" , package )
520+ if not captures :
521+ raise Exception ()
522+ alternative = captures .groups ()[0 ]
523+ if not _install_local_package (alternative , path ):
524+ raise Exception ()
525+
526+ except Exception as e :
527+ print (e )
528+ print ("Failed to install of {package} " .format (package = package ))
498529 print (
499530 "Install directory contents are now: {directory}" .format (
500531 directory = os .listdir (path )
0 commit comments