-
Notifications
You must be signed in to change notification settings - Fork 23
Add as_packages parameter to find_shortest_chain
#187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seddonym
merged 2 commits into
python-grimp:master
from
Peter554:shortest-path-as-packages
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,17 +296,18 @@ impl GraphWrapper { | |
| .collect()) | ||
| } | ||
|
|
||
| // TODO(peter) Add `as_packages` argument here? The implementation already supports it! | ||
| #[pyo3(signature = (importer, imported, as_packages=false))] | ||
| pub fn find_shortest_chain( | ||
| &self, | ||
| importer: &str, | ||
| imported: &str, | ||
| as_packages: bool, | ||
| ) -> PyResult<Option<Vec<String>>> { | ||
| let importer = self.get_visible_module_by_name(importer)?.token(); | ||
| let imported = self.get_visible_module_by_name(imported)?.token(); | ||
| Ok(self | ||
| ._graph | ||
| .find_shortest_chain(importer, imported, false)? | ||
| .find_shortest_chain(importer, imported, as_packages)? | ||
|
Comment on lines
-309
to
+310
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation already supports it - we just need to pass the parameter through! |
||
| .map(|chain| { | ||
| chain | ||
| .iter() | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,11 +220,19 @@ def find_upstream_modules(self, module: str, as_package: bool = False) -> Set[st | |
| raise NotImplementedError | ||
|
|
||
| @abc.abstractmethod | ||
| def find_shortest_chain(self, importer: str, imported: str) -> tuple[str, ...] | None: | ||
| def find_shortest_chain( | ||
| self, importer: str, imported: str, as_packages: bool = False | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default to false ensures backwards compatibility. |
||
| ) -> tuple[str, ...] | None: | ||
| """ | ||
| Attempt to find the shortest chain of imports between two modules, in the direction | ||
| of importer to imported. | ||
|
|
||
| Optional args: | ||
| as_packages: Whether to treat the supplied modules as individual modules, | ||
| or as packages (including any descendants, if there are any). If | ||
| treating them as subpackages, all descendants of the supplied modules | ||
| will be checked too. | ||
|
|
||
| Returns: | ||
| Tuple of module names, from importer to imported, or None if no chain exists. | ||
| """ | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add this to the signature on l. 219 too. (While we're at it, would you mind adding it to the signature of
find_shortest_chainson l. 231, too? I missed that one.)