Refactor Windows DLL loading in Python packages#559
Merged
Conversation
1 task
The existing space1d/space2d/space3d package initializers each carried the same Windows DLL setup code before importing their pybind extension. That logic only added the current package directory plus entries already present on PATH via os.add_dll_directory(). In practice this was fragile for wheel installs because the extension import could still fail if dependent DLLs were bundled in package-local locations that were not already on PATH. Centralize the DLL search setup in amrex._dll and call it from each spaceNd package before importing amrex_*d_pybind. The new helper prefers package-local locations first: the current spaceNd directory, spaceNd/.libs, the parent amrex package directory, and amrex/.libs. It then falls back to PATH for source and developer installs. Keep the os.add_dll_directory() handles alive for the lifetime of the process and deduplicate discovered paths. This keeps the Windows import workaround in one place and makes it compatible with vendored wheel layouts as well as traditional shared- library installs.
70bf3fd to
3a9b82c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The existing
space1d/space2d/space3dpackage initializers each carried the same Windows DLL setup code before importing their pybind extension. That logic only added the current package directory plus entries already present onPATHviaos.add_dll_directory(). In practice this was fragile for wheel installs because the extension import could still fail if dependent DLLs were bundled in package-local locations that were not already onPATH.Example: for ImpactX wheels we just build one ImpactX wheel that vendors the AMReX and ImpactX libs and both the pyAMReX and pyImpactX sources: BLAST-ImpactX/impactx-wheels#22 (We do not yet publish AMReX wheels.)
Centralize the DLL search setup in
amrex._dlland call it from eachspaceNdpackage before importingamrex_*d_pybind. The new helper prefers package-local locations first: the currentspaceNddirectory,spaceNd/.libs, the parent amrex package directory, andamrex/.libs. It then falls back toPATHfor source and developer installs.Keep the
os.add_dll_directory()handles alive for the lifetime of the process and deduplicate discovered paths. This keeps the Windows import workaround in one place and makes it compatible with vendored wheel layouts as well as traditional shared- library installs.