move max_depth default into find_libraries

This commit is contained in:
Harmen Stoppels 2024-11-07 15:26:27 +01:00
parent 1da7ddc2b3
commit 33e152accc
2 changed files with 10 additions and 9 deletions

View File

@ -2350,7 +2350,8 @@ def find_libraries(
recursive: if False (default) search only root folder, if True recurse from the root. Note recursive: if False (default) search only root folder, if True recurse from the root. Note
that recursive search does not imply exhaustive search. The function returns early if that recursive search does not imply exhaustive search. The function returns early if
libraries are found in typical, low-depth library directories. libraries are found in typical, low-depth library directories.
max_depth: if set, don't search below this depth. Cannot be set if recursive is False max_depth: if set, don't search below this depth. Cannot be set if recursive is False.
Defaults to 4.
runtime: Windows only option, no-op elsewhere. If True (default), search for runtime shared runtime: Windows only option, no-op elsewhere. If True (default), search for runtime shared
libs (.DLL), otherwise, search for .Lib files. If shared is False, this has no meaning. libs (.DLL), otherwise, search for .Lib files. If shared is False, this has no meaning.
@ -2395,6 +2396,10 @@ def find_libraries(
if not recursive: if not recursive:
return LibraryList(find(root, libraries, recursive=False)) return LibraryList(find(root, libraries, recursive=False))
if max_depth is None:
# this default covers search in <root>/lib/pythonX.Y/site-packages/<package>/*.
max_depth = 4
# Even if recursive is True, we will do some form of targeted, iterative deepening, in order # Even if recursive is True, we will do some form of targeted, iterative deepening, in order
# to return early if libraries are found in common, low-depth library directories. # to return early if libraries are found in common, low-depth library directories.
if sys.platform == "win32": if sys.platform == "win32":
@ -2408,7 +2413,6 @@ def find_libraries(
# avoid the expensive recursive search of the root directory # avoid the expensive recursive search of the root directory
fallback_recursive = [os.path.join(root, libdir) for libdir in common_lib_dirs] fallback_recursive = [os.path.join(root, libdir) for libdir in common_lib_dirs]
# reduce max_depth by 1 as we already joined the common library directories # reduce max_depth by 1 as we already joined the common library directories
if max_depth is not None:
max_depth -= 1 max_depth -= 1
else: else:
# the call site already has a common library dir as root # the call site already has a common library dir as root

View File

@ -1158,12 +1158,9 @@ def _libs_default_handler(spec: "Spec"):
) )
for shared in search_shared: for shared in search_shared:
# Since we are searching for link libraries, on Windows search only for .Lib extensions by # Since we are searching for link libraries, on Windows search only for
# default as those represent import libraries for implicit links. # ".Lib" extensions by default as those represent import libraries for implicit links.
# Set max_depth=4 to allow searching in <home>/lib/pythonX.Y/site-packages/<name>/ libs = fs.find_libraries(name, home, shared=shared, recursive=True, runtime=False)
libs = fs.find_libraries(
name, home, shared=shared, recursive=True, runtime=False, max_depth=4
)
if libs: if libs:
return libs return libs