fix: add fallback for finding bundled library when importlib.metadata unavailable#404
Open
Wheest wants to merge 3 commits into
Open
fix: add fallback for finding bundled library when importlib.metadata unavailable#404Wheest wants to merge 3 commits into
Wheest wants to merge 3 commits into
Conversation
This test verifies that rtree can still locate and load the bundled libspatialindex library when importlib.metadata.files() returns None, which happens in sandboxed environments like Bazel.
… unavailable When running in sandboxed environments like Bazel, importlib.metadata.files() may return None or fail to locate files correctly. This adds a fallback that searches for the bundled libspatialindex library relative to the package directory (in rtree.libs/), which works regardless of metadata availability.
for more information, see https://pre-commit.ci
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.
Summary
When running in sandboxed environments like Bazel (with
rules_python),importlib.metadata.files()may returnNoneor fail to locate files correctly, even though the bundledlibspatialindexlibrary exists in the wheel.This PR adds a fallback that searches for the bundled library relative to the package directory (
rtree.libs/), which works regardless of metadata availability.Problem
In Bazel's sandboxed test environment:
The library exists at
rtree.libs/libspatialindex-*.sobutimportlib.metadata.files("rtree")returnsNonebecause Bazel doesn't properly expose package metadata.Solution
After the existing
importlib.metadatalookup, add a simple fallback:This uses the already-defined
_cwd(Path(__file__).parent) to locate the library relative to the package, which works in any environment.Testing
importlib.metadata.files()returningNone