Repository navigation
Conversation
Peter554
force-pushed
the
direct-import-methods-as-package
branch
from
November 10, 2026 16:46
46c4fb3 to
0bb356d
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
Peter554
force-pushed
the
direct-import-methods-as-package
branch
2 times, most recently
from
November 10, 2026 16:51
68662ca to
f2e4cfc
Compare
Peter554
marked this pull request as ready for review
November 10, 2026 16:53
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the package-aware direct import query changes.
No open issues 🎉
What changed in this PR
Adds package-aware direct import queries to Grimp, addressing #25. Callers can include a module’s descendants without manually combining and filtering results.
Changes:
- Add optional
as_package=Falseto both direct import query methods, preserving default behavior. - Implement package-level queries in Rust, excluding imports within the queried package.
- Add Python and Rust tests, API documentation, and a changelog entry.
| File | Description |
|---|---|
tests/unit/application/graph/test_direct_imports.py |
Test package queries and missing-module errors in both modes. |
src/grimp/application/graph.py |
Expose and document as_package in the Python API. |
rust/src/graph/mod.rs |
Pass the new option through the Python–Rust bindings. |
rust/src/graph/graph_manipulation.rs |
Adapt internal callers while preserving individual-module behavior. |
rust/src/graph/direct_import_queries.rs |
Implement package-aware queries and add Rust tests. |
docs/usage.rst |
Document the parameter and package filtering behavior. |
CHANGELOG.rst |
Announce the new option and link to #25. |
Review effort: Balanced
Previously this checked every import in the graph against both expressions, which made each call proportional to the size of the graph. This is slow when it is called many times, as Import Linter does for each of the expressions in a contract's ignore_imports. Instead, find the modules that match each expression, then only look at the imports of the modules that match the importer expression. Assistant-model: Claude Code
seddonym
force-pushed
the
direct-import-methods-as-package
branch
from
November 13, 2026 12:52
f2e4cfc to
7bc1e5c
Compare
This branch has not been deployed
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.
Motivation
Closes #25.
find_upstream_modulesandfind_downstream_modulescan treat the supplied module as a package withas_package=True, anddirect_import_existshasas_packages.find_modules_directly_imported_byandfind_modules_that_directly_importdidn't, which made it awkward to ask "what does this package directly import?" or "what directly imports this package?".To do that today, you have to find the package's descendants, call the method for each one, combine the results, and remove the modules within the package.
As discussed here import-linter/import-linter#406 (comment)
Changes
Add
as_package=Falseto both methods. Withas_package=True:find_upstream_modules;The default behaviour is unchanged. Includes tests, docs and a changelog entry.