@@ -206,9 +206,6 @@ def compile_all(self):
206206 print (f"Building { item ['name' ]} " )
207207 build_function = getattr (self , build_function_name )
208208 build_function (item )
209- elif "pip-install" in item :
210- print (f"Installing { item ['name' ]} with pip" )
211- self ._build_with_pip (item )
212209 else :
213210 print (
214211 f"No '{ build_function_name } ' found in compile_all.py -- "
@@ -225,7 +222,7 @@ def python_exe(self):
225222 return os .path .join (self .install_dir , "bin" , "python" ) + to_exe ()
226223 return os .path .join (self .install_dir , "bin" , "python_d" ) + to_exe ()
227224
228- def build_python (self , _ = None ):
225+ def build_python (self , args = None ):
229226 if self .skip_existing :
230227 if os .path .exists (os .path .join (self .install_dir , "bin" , "DLLs" )):
231228 print (" Not rebuilding Python, it is already in the LibPack" )
@@ -343,6 +340,9 @@ def build_python(self, _=None):
343340 os .rename (pyconfig , target )
344341 else :
345342 raise NotImplemented ("Non-Windows compilation of Python is not implemented yet" )
343+ self ._build_pip ()
344+ if "requirements" in args :
345+ self ._install_python_requirements (args ["requirements" ])
346346
347347 def get_python_version (self , exe : str = None ) -> str :
348348 if exe is None :
@@ -361,18 +361,42 @@ def get_python_version(self, exe: str = None) -> str:
361361 print (e .stderr .decode ("utf-8" ))
362362 exit (1 )
363363
364- def build_pip (self , _ = None ):
364+ def _build_pip (self , _ = None ):
365+ print (" Installing the latest pip" )
365366 path_to_python = self .python_exe ()
366367 try :
367368 subprocess .run (
368369 [path_to_python , "-m" , "ensurepip" , "--upgrade" ], capture_output = True , check = True
369370 )
371+ subprocess .run (
372+ [path_to_python , "-m" , "pip" , "install" , "--upgrade" , "pip" ],
373+ capture_output = True ,
374+ check = True ,
375+ )
370376 except subprocess .CalledProcessError as e :
371377 print ("ERROR: Failed to run LibPack's Python executable" )
372378 print (e .stdout .decode ("utf-8" ))
373379 print (e .stderr .decode ("utf-8" ))
374380 exit (1 )
375381
382+ def _install_python_requirements (self , requirements ):
383+ print (" Installing the following requirements (and their dependencies) using pip:" )
384+ for req in requirements :
385+ print (" " + req )
386+ path_to_python = self .python_exe ()
387+ call_args = [path_to_python , "-m" , "pip" , "install" , "--ignore-installed" ]
388+ call_args .extend (requirements )
389+ try :
390+ subprocess .run (
391+ call_args ,
392+ check = True ,
393+ capture_output = True ,
394+ )
395+ except subprocess .CalledProcessError as e :
396+ print (f"ERROR: Failed to pip install requirements" )
397+ print (e .output .decode ("utf-8" ))
398+ exit (1 )
399+
376400 def build_qt (self , options : dict ):
377401 """Doesn't really "build" Qt, just copies the pre-compiled libraries from the configured path"""
378402 qt_dir = options ["install-directory" ]
@@ -516,23 +540,20 @@ def _build_standard_cmake(self, extra_args: List[str] = None):
516540
517541 def _pip_install (self , requirement : str ) -> None :
518542 path_to_python = self .python_exe ()
519- if self .skip_existing :
543+ try :
544+ # Get rid of any version that's already there.
520545 package_name = requirement .split ("==" )[0 ]
521- try :
522- result = subprocess .run (
523- [path_to_python , "-m" , "pip" , "show" , package_name ],
524- check = True ,
525- capture_output = True ,
526- )
527- if "WARNING:" not in result .stdout .decode ("utf-8" ):
528- print (f" Not reinstalling { package_name } , it is already in the LibPack" )
529- return
530- except subprocess .CalledProcessError :
531- pass
532-
546+ subprocess .run (
547+ [path_to_python , "-m" , "pip" , "uninstall" , "--yes" , package_name ],
548+ check = True ,
549+ capture_output = True ,
550+ )
551+ except subprocess .CalledProcessError as e :
552+ print (f"{ package_name } was not uninstalled... continuing" )
553+ pass
533554 try :
534555 subprocess .run (
535- [path_to_python , "-m" , "pip" , "install" , requirement ],
556+ [path_to_python , "-m" , "pip" , "install" , "--ignore-installed" , requirement ],
536557 check = True ,
537558 capture_output = True ,
538559 )
0 commit comments