Skip to content

Commit

Permalink
Add PEP 714 support for JSON API client (#3698)
Browse files Browse the repository at this point in the history
## Summary

Closes #3689.

## Test Plan

Manually verified we pick up `core-metadata` from PyPI if I remove the
aliases.
  • Loading branch information
charliermarsh authored May 21, 2024
1 parent 95af1db commit 5205165
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
4 changes: 3 additions & 1 deletion crates/distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ impl File {
pub fn try_from(file: pypi_types::File, base: &Url) -> Result<Self, FileConversionError> {
Ok(Self {
dist_info_metadata: file
.dist_info_metadata
.core_metadata
.as_ref()
.or(file.dist_info_metadata.as_ref())
.or(file.data_dist_info_metadata.as_ref())
.is_some_and(DistInfoMetadata::is_available),
filename: file.filename,
hashes: file.hashes.into_digests(),
Expand Down
13 changes: 8 additions & 5 deletions crates/pypi-types/src/simple_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
34 changes: 33 additions & 1 deletion crates/uv-client/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ impl SimpleHtml {
};

Ok(File {
dist_info_metadata,
core_metadata: dist_info_metadata,
dist_info_metadata: None,
data_dist_info_metadata: None,
yanked,
requires_python,
hashes,
Expand Down Expand Up @@ -298,7 +300,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -354,7 +358,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: Some(
Expand Down Expand Up @@ -413,7 +419,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -469,7 +477,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2+233fca715f49-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -525,7 +535,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -581,7 +593,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "torchtext-0.17.0+cpu-cp39-cp39-win_amd64.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -635,7 +649,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -723,7 +739,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -777,7 +795,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -866,7 +886,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "jaxlib-0.1.52+cuda100-cp36-none-manylinux2010_x86_64.whl",
hashes: Hashes {
md5: None,
Expand All @@ -881,7 +903,9 @@ mod tests {
yanked: None,
},
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "jaxlib-0.1.52+cuda100-cp37-none-manylinux2010_x86_64.whl",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -945,7 +969,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Flask-0.1.tar.gz",
hashes: Hashes {
md5: None,
Expand All @@ -962,7 +988,9 @@ mod tests {
yanked: None,
},
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Flask-0.10.1.tar.gz",
hashes: Hashes {
md5: None,
Expand All @@ -979,7 +1007,9 @@ mod tests {
yanked: None,
},
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "flask-3.0.1.tar.gz",
hashes: Hashes {
md5: None,
Expand Down Expand Up @@ -1045,7 +1075,9 @@ mod tests {
),
files: [
File {
core_metadata: None,
dist_info_metadata: None,
data_dist_info_metadata: None,
filename: "Jinja2-3.1.2-py3-none-any.whl",
hashes: Hashes {
md5: None,
Expand Down

0 comments on commit 5205165

Please sign in to comment.