2222
2323
2424class PythonLibraryResolver (LibraryResolver ):
25- # TODO: https://github.com/databrickslabs/ucx/issues/1640
25+ """Resolve python libraries by registering and installing Python libraries."""
2626
2727 def __init__ (
2828 self ,
@@ -61,13 +61,22 @@ def _install_library(self, path_lookup: PathLookup, *libraries: str) -> list[Dep
6161 return self ._install_egg (* resolved_libraries )
6262 return self ._install_pip (* resolved_libraries )
6363
64- @staticmethod
65- def _resolve_libraries (path_lookup : PathLookup , * libraries : str ) -> list [str ]:
66- # Resolve relative pip installs from notebooks: %pip install ../../foo.whl
64+ def _resolve_libraries (self , path_lookup : PathLookup , * libraries : str ) -> list [str ]:
65+ """Resolve pip installs as library (pip install databricks-labs-ucx) or as path (pip install ../../ucx.whl).
66+
67+ A library is defined as library, i.e. *not* as path, when the library:
68+ 1. Is not found in the path lookup.
69+ 2. Is not located in the temporary virtual environment where this resolver install libraries. If this is the
70+ case, it signals the library is installed for a second time.
71+
72+ Otherwise, we consider the library to be a path.
73+
74+ Note: The above works given our design choice to *only* build dependency graphs when all dependencies are found.
75+ """
6776 libs = []
6877 for library in libraries :
6978 maybe_library = path_lookup .resolve (Path (library ))
70- if maybe_library is None :
79+ if maybe_library is None or maybe_library . is_relative_to ( self . _temporary_virtual_environment ) :
7180 libs .append (library )
7281 else :
7382 libs .append (maybe_library .as_posix ())
@@ -81,9 +90,11 @@ def _install_pip(self, *libraries: str) -> list[DependencyProblem]:
8190 * libraries ,
8291 "-t" ,
8392 str (self ._temporary_virtual_environment ),
93+ "--upgrade" , # Upgrades when library already installed
8494 ]
8595 return_code , stdout , stderr = self ._runner (args )
86- logger .debug (f"pip output:\n { stdout } \n { stderr } " )
96+ if stdout or stderr :
97+ logger .debug (f"pip output:\n { stdout } \n { stderr } " )
8798 if return_code != 0 :
8899 command = " " .join (args )
89100 problem = DependencyProblem ("library-install-failed" , f"'{ command } ' failed with '{ stderr } '" )
0 commit comments