Skip to content
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

Add PEP 714 support for JSON API client #3698

Merged
merged 1 commit into from
May 21, 2024
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented May 21, 2024

Summary

Closes #3689.

Test Plan

Manually verified we pick up core-metadata from PyPI if I remove the aliases.

@charliermarsh charliermarsh added the compatibility Compatibility with a specification or another tool label May 21, 2024
@charliermarsh charliermarsh force-pushed the charlie/dist-info-json branch from c449d18 to 12c6e79 Compare May 21, 2024 14:26
@charliermarsh
Copy link
Member Author

Oh interesting, Serde does not treat aliases as fallbacks. They're mutually exclusive.

@charliermarsh charliermarsh force-pushed the charlie/dist-info-json branch from 12c6e79 to 07a4c66 Compare May 21, 2024 14:50
@charliermarsh charliermarsh requested review from zanieb and konstin May 21, 2024 14:51
pub dist_info_metadata: Option<DistInfoMetadata>,
pub data_dist_info_metadata: Option<DistInfoMetadata>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Repeating like this is the only way I could figure out to support multiple aliases under different names, where multiple values can be present. (PyPI serves both core-metadata and data-dist-info-metadata; serde's alias feature errors if multiple values are present.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Per PEP 714, we could omit data_dist_info_metadata... But there may be registries that only serve that in practice, since that's what pip did for a while.

Copy link
Member

Choose a reason for hiding this comment

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

I would define a separate wire type with what you want to support, and then implement From<FileWire> for File (or TryFrom if needed). Then use #[serde(from = "FileWire")]. That way, you can resolve the aliases down to one field at deserialization time, and avoid spreading that complexity outward to anyone consuming File.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, but we already have a separate File type that we use in our own abstractions.

Copy link
Member Author

Choose a reason for hiding this comment

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

So in a sense this is FileWire. And we have a From elsewhere.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I was confused because I wouldn't normally expect a wire type to have pub fields and otherwise be exported. Basically, my suggestion boils down to "encapsulate the aliases at the deserialization boundary." But if the point of File is to be the boundary and be exposed to the world, then yeah, I think what you have is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this is meant to be roughly "the exact JSON we get from the API", so I suppose this is ok.

@charliermarsh charliermarsh force-pushed the charlie/dist-info-json branch from 07a4c66 to 62a10f1 Compare May 21, 2024 15:19
@charliermarsh charliermarsh enabled auto-merge (squash) May 21, 2024 15:21
@charliermarsh charliermarsh merged commit 5205165 into main May 21, 2024
44 checks passed
@charliermarsh charliermarsh deleted the charlie/dist-info-json branch May 21, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incorrect use of data-dist-info-metadata (PEP-714)
2 participants