-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Search all distributions when trying to find a match in get_distribution() #8702
Search all distributions when trying to find a match in get_distribution() #8702
Conversation
This matches the behavior of pkg_resources.get_distribution(), which this function intends to replace.
The call to get_installed_distributions() now passes all flags excplicitly so they are more obvious and less likely to be misunderstood in the future. The behavior also documented in the function docstring. The search_distribution() helper function is renamed with a leading underscore to make it clear that it is intended as a helper function to get_distribution().
@@ -140,6 +140,7 @@ def print_results(hits, name_column_width=None, terminal_width=None): | |||
write_output(line) | |||
if name in installed_packages: | |||
dist = get_distribution(name) | |||
assert dist is not None |
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.
This whole module is using the distribution-related functions in a very inprecise way. I’ll submit a standalone refactoring PR after this is accepted
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.
Looks good, thanks! The two other call sites of misc.get_distribution
should not be affected by this change.
I'm not sure how we could add a test for this. Perhaps by mocking dist_is_local
?
@pradyunsg I took the liberty to create milestone 20.2.2 |
Me either, non-local site-packages are difficult to test, for obvious reasons. I’ll take a look later and see whether existing tests can offer some inspiration. |
I added a couple of tests for this. |
When is 20.2.2 going to be released? A regression in pip is really impactful to the community and can not be left hanging for days on end. |
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.
The tests look good to me, thanks for adding them @uranusjr.
See #8511 (comment). |
Fix #8695. I also made some minor refactoring so we can better avoid this kind of behavioural mistakes in the future.