Skip to content

Final purge of direct pkg_resources usages #10675

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
merged 7 commits into from
Dec 4, 2021
Merged

Conversation

uranusjr
Copy link
Member

@uranusjr uranusjr commented Nov 22, 2021

I think this is it! No more pkg_resources calls (except from the compatibility shim)!

Needs to first fix #10674. Submit to run CI first… Done and ready

@uranusjr uranusjr added the skip news Does not need a NEWS file entry (eg: trivial changes) label Nov 22, 2021
@uranusjr uranusjr force-pushed the metadata-misc branch 2 times, most recently from a3a79b1 to 174babb Compare November 22, 2021 13:24
@uranusjr uranusjr force-pushed the metadata-misc branch 2 times, most recently from 20893bf to 794347d Compare November 22, 2021 15:07
@uranusjr uranusjr marked this pull request as ready for review November 25, 2021 10:17
@uranusjr
Copy link
Member Author

Should be ready. This changes quite several files, but is mostly just moving things into pip._interval.metadata (because the direct usages are eliminated) and removing shim functions that are no longer used.

@uranusjr uranusjr added this to the 22.0 milestone Dec 4, 2021
@uranusjr
Copy link
Member Author

uranusjr commented Dec 4, 2021

Yay, everything seems to work!

@sbidoul
Copy link
Member

sbidoul commented Dec 4, 2021

That's a great achievement. Thanks for this effort!

@@ -149,17 +148,17 @@ def __init__(self, *, package: str, reason: str) -> None:


class NoneMetadataError(PipError):
Copy link
Member

Choose a reason for hiding this comment

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

For a follow up, we should probably give this a more meaningful name -- DeclaredMetadataFileIsMissingError or something similar.

Copy link
Member Author

@uranusjr uranusjr Dec 4, 2021

Choose a reason for hiding this comment

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

FWIW this exception never actually makes sense; it’s caught in exactly two places, one just sets the result to an empty string, and the other is the outmost except PipError block that prints the exception as an error message. It will probably go away entirely when the importlib.metadata backend gets implemented.

Copy link
Member

Choose a reason for hiding this comment

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

Well, if I remember correctly, the situation which this was originally raised in was something weird, like a metadata file that has a truth has_metadata but get_metadata returned None. I'm not quite sure how this could happen, TBH. I do remember seeing this exception get raised in another situation in one of these porting PRs, which might have changed the meaning of it?

If we're sure that this will never happen with importlib metadata, then yea, this can probably go away.

Copy link
Member Author

Choose a reason for hiding this comment

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

the situation which this was originally raised in was something weird, like a metadata file that has a truth has_metadata but get_metadata returned None. I'm not quite sure how this could happen, TBH.

That’s correct, and the exception can happen for permission reasons. But the thing is that this discrepency isn’t really necessary due to how the exception is handled. And this also does not happen in importlib.metadata because has_metadata does not even exist in the API—the only way to know if a metadata file exists in importlib.metadata is try to read it.

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

LGTM, barring a few non-blocking comments. :)

Comment on lines +114 to +115
except UnsupportedWheel as e:
raise UnsupportedWheel(f"{name} has an invalid wheel, {e}")
Copy link
Member

Choose a reason for hiding this comment

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

Why not let this error pass through as-is?

The caller has the name and can use it, if they really want to, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I don’t really want to think about changing behaviour right now; I’ll get too many chances for that when we try to re-implement everything in importlib.metadata and deal with those subtle differences.

@uranusjr uranusjr merged commit ebc13b4 into pypa:main Dec 4, 2021
@uranusjr uranusjr deleted the metadata-misc branch December 4, 2021 20:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants