Skip to content

Add as_packages parameter to find_shortest_chain#187

Merged
seddonym merged 2 commits intopython-grimp:masterfrom
Peter554:shortest-path-as-packages
Feb 11, 2025
Merged

Add as_packages parameter to find_shortest_chain#187
seddonym merged 2 commits intopython-grimp:masterfrom
Peter554:shortest-path-as-packages

Conversation

@Peter554
Copy link
Collaborator

@Peter554 Peter554 commented Feb 8, 2025

The implementation of the pathfinding already supports this, so let's add this to the public API!

Comment on lines -309 to +310
.find_shortest_chain(importer, imported, false)?
.find_shortest_chain(importer, imported, as_packages)?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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!

@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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default to false ensures backwards compatibility.

@Peter554 Peter554 marked this pull request as ready for review February 8, 2025 16:55
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 8, 2025

CodSpeed Performance Report

Merging #187 will not alter performance

Comparing Peter554:shortest-path-as-packages (633f81d) with master (830ce44)

Summary

✅ 17 untouched benchmarks

Copy link
Collaborator

@seddonym seddonym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏻 Tiny tweak needed to docs but otherwise good to go.

:param str importer: The module at the start of a potential chain of imports between ``importer`` and ``imported``
(i.e. the module that potentially imports ``imported``, even indirectly).
:param str imported: The module at the end of the potential chain of imports.
:param bool as_packages: Whether to treat the supplied modules as individual modules,
Copy link
Collaborator

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_chains on l. 231, too? I missed that one.)

The implementation of the pathfinding already supports
this, so let's add this to the public API.
@Peter554 Peter554 force-pushed the shortest-path-as-packages branch from ee16f7c to 633f81d Compare February 10, 2025 20:44
@Peter554 Peter554 requested a review from seddonym February 10, 2025 20:54
@seddonym seddonym merged commit 4775375 into python-grimp:master Feb 11, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants