stubgen: add LIB_PATH
option to locate dependent shared libraries
#1045
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses issues such as
ModuleNotFoundError
that could occur during stub generation when extension modules depend on external shared libraries (e.g.,.dll
on Windows,.so
on Linux) located outside of the standard search paths.Background
On Windows, when stubgen attempts to import an extension module to generate stubs,
importlib.import_module()
may fail if the Python interpreter cannot locate the required dependent DLLs—for example, if they are not in the same directory as the.pyd
file.Example error:
In contrast, on Linux, the dynamic linker can use the extension module's embedded RPATH to find dependencies.
Proposed Change
A new
LIB_PATH
argument has been introduced tonanobind_add_stub
. This option allows you to specify a list of directories containing dependent shared libraries. During stub generation:os.add_dll_directory()
.LD_LIBRARY_PATH
environment variable (on macOS, toDYLD_LIBRARY_PATH
).Example Usage