Add PEP 714 support for JSON API client (#3698)

## Summary

Closes https://github.com/astral-sh/uv/issues/3689.

## Test Plan

Manually verified we pick up `core-metadata` from PyPI if I remove the
aliases.
This commit is contained in:
Charlie Marsh 2024-05-21 11:52:37 -04:00 committed by GitHub
parent 95af1db0bb
commit 5205165d42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 7 deletions

View file

@ -37,14 +37,17 @@ fn sorted_simple_json_files<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<File>
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct File {
// Non-PEP 691-compliant alias used by PyPI.
#[serde(alias = "data-dist-info-metadata")]
// PEP 714-renamed field, followed by PEP 691-compliant field, followed by non-PEP 691-compliant
// alias used by PyPI.
pub core_metadata: Option<DistInfoMetadata>,
pub dist_info_metadata: Option<DistInfoMetadata>,
pub data_dist_info_metadata: Option<DistInfoMetadata>,
pub filename: String,
pub hashes: Hashes,
/// There are a number of invalid specifiers on pypi, so we first try to parse it into a [`VersionSpecifiers`]
/// according to spec (PEP 440), then a [`LenientVersionSpecifiers`] with fixup for some common problems and if this
/// still fails, we skip the file when creating a version map.
/// There are a number of invalid specifiers on PyPI, so we first try to parse it into a
/// [`VersionSpecifiers`] according to spec (PEP 440), then a [`LenientVersionSpecifiers`] with
/// fixup for some common problems and if this still fails, we skip the file when creating a
/// version map.
#[serde(default, deserialize_with = "deserialize_version_specifiers_lenient")]
pub requires_python: Option<Result<VersionSpecifiers, VersionSpecifiersParseError>>,
pub size: Option<u64>,