diff --git a/crates/uv-bench/Cargo.toml b/crates/uv-bench/Cargo.toml index 81f6d973dc90..481d0912eadb 100644 --- a/crates/uv-bench/Cargo.toml +++ b/crates/uv-bench/Cargo.toml @@ -23,10 +23,10 @@ name = "distribution-filename" path = "benches/distribution_filename.rs" harness = false -[[bench]] -name = "uv" -path = "benches/uv.rs" -harness = false +# [[bench]] +# name = "uv" +# path = "benches/uv.rs" +# harness = false [dependencies] uv-cache = { workspace = true } diff --git a/crates/uv-bench/benches/distribution_filename.rs b/crates/uv-bench/benches/distribution_filename.rs index 7d166962166d..05b0f13166b9 100644 --- a/crates/uv-bench/benches/distribution_filename.rs +++ b/crates/uv-bench/benches/distribution_filename.rs @@ -168,9 +168,9 @@ fn benchmark_wheelname_tag_compatibility(c: &mut Criterion) { criterion_group!( uv_distribution_filename, - benchmark_build_platform_tags, + // benchmark_build_platform_tags, benchmark_wheelname_parsing, benchmark_wheelname_parsing_failure, - benchmark_wheelname_tag_compatibility, + // benchmark_wheelname_tag_compatibility, ); criterion_main!(uv_distribution_filename); diff --git a/crates/uv-distribution-filename/src/wheel.rs b/crates/uv-distribution-filename/src/wheel.rs index 22aff55f0652..fb64504534df 100644 --- a/crates/uv-distribution-filename/src/wheel.rs +++ b/crates/uv-distribution-filename/src/wheel.rs @@ -72,6 +72,8 @@ impl WheelTag { } } + + pub fn python_tags(&self) -> &[LanguageTag] { match self { Self::Small { small } => std::slice::from_ref(&small.python_tag), @@ -150,9 +152,9 @@ impl Display for WheelTagSmall { #[rkyv(derive(Debug))] pub struct WheelTagLarge { build_tag: Option, - python_tag: TagSet, - abi_tag: TagSet, - platform_tag: TagSet, + python_tag: Vec, + abi_tag: Vec, + platform_tag: Vec, } impl Display for WheelTagLarge { @@ -311,39 +313,92 @@ impl WheelFilename { }) .transpose()?; - let tags = if build_tag.is_some() || python_tag.contains('.') || abi_tag.contains('.') || platform_tag.contains('.') { - WheelTag::Large { + let mut python_tags = python_tag.split('.').map(LanguageTag::from_str); + let mut abi_tags = abi_tag.split('.').map(AbiTag::from_str); + let mut platform_tags = platform_tag.split('.').map(PlatformTag::from_str); + + // Identify the first tag of each type. + let python_tag = python_tags + .next() + .ok_or_else(|| WheelFilenameError::MissingLanguageTag(filename.to_string()))? + .map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?; + let abi_tag = abi_tags + .next() + .ok_or_else(|| WheelFilenameError::MissingAbiTag(filename.to_string()))? + .map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?; + let platform_tag = platform_tags + .next() + .ok_or_else(|| WheelFilenameError::MissingPlatformTag(filename.to_string()))? + .map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?; + + let tags = match ( + python_tags.next(), + abi_tags.next(), + platform_tags.next(), + ) { + (None, None, None) if build_tag.is_none() => WheelTag::Small { + small: WheelTagSmall { + python_tag, + abi_tag, + platform_tag + }, + }, + (next_python_tag, next_abi_tag, next_platform_tag) => WheelTag::Large { large: Box::new(WheelTagLarge { build_tag, - python_tag: python_tag - .split('.') - .map(LanguageTag::from_str) + python_tag: std::iter::once(python_tag) + .chain(next_python_tag.transpose().map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?) + .chain(python_tags) .collect::>() .map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?, - abi_tag: abi_tag - .split('.') - .map(AbiTag::from_str) + abi_tag: std::iter::once(abi_tag) + .chain(next_abi_tag.transpose()?) + .chain(abi_tags) .collect::>() .map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?, - platform_tag: platform_tag - .split('.') - .map(PlatformTag::from_str) + platform_tag: std::iter::once(platform_tag) + .chain(next_platform_tag.transpose()?) + .chain(platform_tags) .collect::>() .map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?, }), - } - } else { - WheelTag::Small { - small: WheelTagSmall { - python_tag: LanguageTag::from_str(python_tag) - .map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?, - abi_tag: AbiTag::from_str(abi_tag) - .map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?, - platform_tag: PlatformTag::from_str(platform_tag) - .map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?, - }, - } + }, }; + // + // + // let tags = if build_tag.is_some() || python_tag.contains('.') || abi_tag.contains('.') || platform_tag.contains('.') { + // WheelTag::Large { + // large: Box::new(WheelTagLarge { + // build_tag, + // python_tag: python_tag + // .split('.') + // .map(LanguageTag::from_str) + // .collect::>() + // .map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?, + // abi_tag: abi_tag + // .split('.') + // .map(AbiTag::from_str) + // .collect::>() + // .map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?, + // platform_tag: platform_tag + // .split('.') + // .map(PlatformTag::from_str) + // .collect::>() + // .map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?, + // }), + // } + // } else { + // WheelTag::Small { + // small: WheelTagSmall { + // python_tag: LanguageTag::from_str(python_tag) + // .map_err(|err| WheelFilenameError::InvalidLanguageTag(filename.to_string(), err))?, + // abi_tag: AbiTag::from_str(abi_tag) + // .map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?, + // platform_tag: PlatformTag::from_str(platform_tag) + // .map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?, + // }, + // } + // }; Ok(Self { name,