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

Reduce WheelFilename to 48 bytes #10583

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 46 additions & 58 deletions crates/uv-build-backend/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::{debug, trace};
use walkdir::WalkDir;
use zip::{CompressionMethod, ZipWriter};

use uv_distribution_filename::{TagSet, WheelFilename};
use uv_distribution_filename::WheelFilename;
use uv_fs::Simplified;
use uv_globfilter::{parse_portable_glob, GlobDirFilter};
use uv_platform_tags::{AbiTag, LanguageTag, PlatformTag};
Expand All @@ -33,17 +33,16 @@ pub fn build_wheel(
}
crate::check_metadata_directory(source_tree, metadata_directory, &pyproject_toml)?;

let filename = WheelFilename {
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: TagSet::from_slice(&[LanguageTag::Python {
let filename = WheelFilename::new(
pyproject_toml.name().clone(),
pyproject_toml.version().clone(),
LanguageTag::Python {
major: 3,
minor: None,
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};
},
AbiTag::None,
PlatformTag::Any,
);

let wheel_path = wheel_dir.join(filename.to_string());
debug!("Writing wheel at {}", wheel_path.user_display());
Expand Down Expand Up @@ -71,17 +70,16 @@ pub fn list_wheel(
warn_user_once!("{warning}");
}

let filename = WheelFilename {
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: TagSet::from_slice(&[LanguageTag::Python {
let filename = WheelFilename::new(
pyproject_toml.name().clone(),
pyproject_toml.version().clone(),
LanguageTag::Python {
major: 3,
minor: None,
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};
},
AbiTag::None,
PlatformTag::Any,
);

let mut files = FileList::new();
let writer = ListWriter::new(&mut files);
Expand Down Expand Up @@ -253,17 +251,16 @@ pub fn build_editable(

crate::check_metadata_directory(source_tree, metadata_directory, &pyproject_toml)?;

let filename = WheelFilename {
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: TagSet::from_slice(&[LanguageTag::Python {
let filename = WheelFilename::new(
pyproject_toml.name().clone(),
pyproject_toml.version().clone(),
LanguageTag::Python {
major: 3,
minor: None,
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};
},
AbiTag::None,
PlatformTag::Any,
);

let wheel_path = wheel_dir.join(filename.to_string());
debug!("Writing wheel at {}", wheel_path.user_display());
Expand Down Expand Up @@ -308,17 +305,16 @@ pub fn metadata(
warn_user_once!("{warning}");
}

let filename = WheelFilename {
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: TagSet::from_slice(&[LanguageTag::Python {
let filename = WheelFilename::new(
pyproject_toml.name().clone(),
pyproject_toml.version().clone(),
LanguageTag::Python {
major: 3,
minor: None,
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};
},
AbiTag::None,
PlatformTag::Any,
);

debug!(
"Writing metadata files to {}",
Expand Down Expand Up @@ -568,9 +564,9 @@ fn wheel_info(filename: &WheelFilename, uv_version: &str) -> String {
("Generator", format!("uv {uv_version}")),
("Root-Is-Purelib", "true".to_string()),
];
for python_tag in &filename.python_tag {
for abi_tag in &filename.abi_tag {
for platform_tag in &filename.platform_tag {
for python_tag in filename.python_tags() {
for abi_tag in filename.abi_tags() {
for platform_tag in filename.platform_tags() {
wheel_info.push(("Tag", format!("{python_tag}-{abi_tag}-{platform_tag}")));
}
}
Expand Down Expand Up @@ -765,29 +761,21 @@ mod test {

#[test]
fn test_wheel() {
let filename = WheelFilename {
name: PackageName::from_str("foo").unwrap(),
version: Version::from_str("1.2.3").unwrap(),
build_tag: None,
python_tag: TagSet::from_slice(&[
LanguageTag::Python {
major: 2,
minor: None,
},
LanguageTag::Python {
major: 3,
minor: None,
},
]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};
let filename = WheelFilename::new(
PackageName::from_str("foo").unwrap(),
Version::from_str("1.2.3").unwrap(),
LanguageTag::Python {
major: 3,
minor: None,
},
AbiTag::None,
PlatformTag::Any,
);

assert_snapshot!(wheel_info(&filename, "1.0.0+test"), @r"
Wheel-Version: 1.0
Generator: uv 1.0.0+test
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any
");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-distribution-filename/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ mod tests {

#[test]
fn wheel_filename_size() {
assert_eq!(size_of::<WheelFilename>(), 128);
assert_eq!(size_of::<WheelFilename>(), 48);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ Ok(
"foo",
),
version: "1.2.3",
build_tag: Some(
BuildTag(
202206090410,
None,
),
),
python_tag: [
Python {
major: 3,
minor: None,
tags: Large {
large: WheelTagLarge {
build_tag: Some(
BuildTag(
202206090410,
None,
),
),
python_tag: [
Python {
major: 3,
minor: None,
},
],
abi_tag: [
None,
],
platform_tag: [
Any,
],
},
],
abi_tag: [
None,
],
platform_tag: [
Any,
],
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,37 @@ Ok(
"foo",
),
version: "1.2.3",
build_tag: None,
python_tag: [
CPython {
python_version: (
3,
11,
),
tags: Large {
large: WheelTagLarge {
build_tag: None,
python_tag: [
CPython {
python_version: (
3,
11,
),
},
],
abi_tag: [
CPython {
gil_disabled: false,
python_version: (
3,
11,
),
},
],
platform_tag: [
Manylinux {
major: 2,
minor: 17,
arch: X86_64,
},
Manylinux2014 {
arch: X86_64,
},
],
},
],
abi_tag: [
CPython {
gil_disabled: false,
python_version: (
3,
11,
),
},
],
platform_tag: [
Manylinux {
major: 2,
minor: 17,
arch: X86_64,
},
Manylinux2014 {
arch: X86_64,
},
],
},
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ Ok(
"foo",
),
version: "1.2.3",
build_tag: None,
python_tag: [
Python {
major: 3,
minor: None,
tags: Small {
small: WheelTagSmall {
python_tag: Python {
major: 3,
minor: None,
},
abi_tag: None,
platform_tag: Any,
},
],
abi_tag: [
None,
],
platform_tag: [
Any,
],
},
},
)
Loading
Loading