Skip to content

Commit

Permalink
Fix up remaining sites
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 12, 2025
1 parent bf6527a commit 17241c3
Show file tree
Hide file tree
Showing 13 changed files with 878 additions and 889 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 19 additions & 5 deletions crates/uv-bench/benches/distribution_filename.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::str::FromStr;

use uv_bench::criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkId, Criterion, Throughput,
};
use uv_distribution_filename::WheelFilename;
use uv_platform_tags::Tags;
use uv_platform_tags::{AbiTag, LanguageTag, PlatformTag, Tags};

/// A set of platform tags extracted from burntsushi's Archlinux workstation.
/// We could just re-create these via `Tags::from_env`, but those might differ
Expand Down Expand Up @@ -73,9 +75,15 @@ const INVALID_WHEEL_NAMES: &[(&str, &str)] = &[
/// extra processing. We thus expect construction to become slower, but we
/// write a benchmark to ensure it is still "reasonable."
fn benchmark_build_platform_tags(c: &mut Criterion<WallTime>) {
let tags: Vec<(String, String, String)> = PLATFORM_TAGS
let tags: Vec<(LanguageTag, AbiTag, PlatformTag)> = PLATFORM_TAGS
.iter()
.map(|&(py, abi, plat)| (py.to_string(), abi.to_string(), plat.to_string()))
.map(|&(py, abi, plat)| {
(
LanguageTag::from_str(py).unwrap(),
AbiTag::from_str(abi).unwrap(),
PlatformTag::from_str(plat).unwrap(),
)
})
.collect();

let mut group = c.benchmark_group("build_platform_tags");
Expand Down Expand Up @@ -132,9 +140,15 @@ fn benchmark_wheelname_parsing_failure(c: &mut Criterion<WallTime>) {
/// implementation did an exhaustive search over each of them for each tag in
/// the wheel filename.
fn benchmark_wheelname_tag_compatibility(c: &mut Criterion<WallTime>) {
let tags: Vec<(String, String, String)> = PLATFORM_TAGS
let tags: Vec<(LanguageTag, AbiTag, PlatformTag)> = PLATFORM_TAGS
.iter()
.map(|&(py, abi, plat)| (py.to_string(), abi.to_string(), plat.to_string()))
.map(|&(py, abi, plat)| {
(
LanguageTag::from_str(py).unwrap(),
AbiTag::from_str(abi).unwrap(),
PlatformTag::from_str(plat).unwrap(),
)
})
.collect();
let tags = Tags::new(tags);

Expand Down
59 changes: 31 additions & 28 deletions crates/uv-build-backend/src/wheel.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use crate::metadata::{BuildBackendSettings, DEFAULT_EXCLUDES};
use crate::{DirectoryWriter, Error, FileList, ListWriter, PyProjectToml};
use std::io::{BufReader, Read, Write};
use std::path::{Path, PathBuf};
use std::{io, mem};

use fs_err::File;
use globset::{GlobSet, GlobSetBuilder};
use itertools::Itertools;
use sha2::{Digest, Sha256};
use std::io::{BufReader, Read, Write};
use std::path::{Path, PathBuf};
use std::{io, mem};
use tracing::{debug, trace};
use uv_distribution_filename::WheelFilename;
use walkdir::WalkDir;
use zip::{CompressionMethod, ZipWriter};

use uv_distribution_filename::{TagSet, WheelFilename};
use uv_fs::Simplified;
use uv_globfilter::{parse_portable_glob, GlobDirFilter};
use uv_platform_tags::{AbiTag, LanguageTag, PlatformTag};
use uv_warnings::warn_user_once;
use walkdir::WalkDir;
use zip::{CompressionMethod, ZipWriter};

use crate::metadata::{BuildBackendSettings, DEFAULT_EXCLUDES};
use crate::{DirectoryWriter, Error, FileList, ListWriter, PyProjectToml};

/// Build a wheel from the source tree and place it in the output directory.
pub fn build_wheel(
Expand All @@ -34,12 +37,12 @@ pub fn build_wheel(
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: vec![LanguageTag::Python {
python_tag: TagSet::from_slice(&[LanguageTag::Python {
major: 3,
minor: None,
}],
abi_tag: vec![AbiTag::None],
platform_tag: vec![PlatformTag::Any],
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};

let wheel_path = wheel_dir.join(filename.to_string());
Expand Down Expand Up @@ -72,12 +75,12 @@ pub fn list_wheel(
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: vec![LanguageTag::Python {
python_tag: TagSet::from_slice(&[LanguageTag::Python {
major: 3,
minor: None,
}],
abi_tag: vec![AbiTag::None],
platform_tag: vec![PlatformTag::Any],
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};

let mut files = FileList::new();
Expand Down Expand Up @@ -254,12 +257,12 @@ pub fn build_editable(
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: vec![LanguageTag::Python {
python_tag: TagSet::from_slice(&[LanguageTag::Python {
major: 3,
minor: None,
}],
abi_tag: vec![AbiTag::None],
platform_tag: vec![PlatformTag::Any],
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};

let wheel_path = wheel_dir.join(filename.to_string());
Expand Down Expand Up @@ -309,12 +312,12 @@ pub fn metadata(
name: pyproject_toml.name().clone(),
version: pyproject_toml.version().clone(),
build_tag: None,
python_tag: vec![LanguageTag::Python {
python_tag: TagSet::from_slice(&[LanguageTag::Python {
major: 3,
minor: None,
}],
abi_tag: vec![AbiTag::None],
platform_tag: vec![PlatformTag::Any],
}]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};

debug!(
Expand Down Expand Up @@ -766,7 +769,7 @@ mod test {
name: PackageName::from_str("foo").unwrap(),
version: Version::from_str("1.2.3").unwrap(),
build_tag: None,
python_tag: vec![
python_tag: TagSet::from_slice(&[
LanguageTag::Python {
major: 2,
minor: None,
Expand All @@ -775,9 +778,9 @@ mod test {
major: 3,
minor: None,
},
],
abi_tag: vec![AbiTag::None],
platform_tag: vec![PlatformTag::Any],
]),
abi_tag: TagSet::from_buf([AbiTag::None]),
platform_tag: TagSet::from_buf([PlatformTag::Any]),
};

assert_snapshot!(wheel_info(&filename, "1.0.0+test"), @r"
Expand Down
3 changes: 2 additions & 1 deletion crates/uv-distribution-filename/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ uv-normalize = { workspace = true }
uv-pep440 = { workspace = true }
uv-platform-tags = { workspace = true }

rkyv = { workspace = true }
rkyv = { workspace = true, features = ["smallvec-1"] }
serde = { workspace = true }
smallvec = { workspace = true }
thiserror = { workspace = true }
url = { workspace = true }

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 @@ -7,7 +7,7 @@ pub use build_tag::{BuildTag, BuildTagError};
pub use egg::{EggInfoFilename, EggInfoFilenameError};
pub use extension::{DistExtension, ExtensionError, SourceDistExtension};
pub use source_dist::{SourceDistFilename, SourceDistFilenameError};
pub use wheel::{WheelFilename, WheelFilenameError};
pub use wheel::{TagSet, WheelFilename, WheelFilenameError};

mod build_tag;
mod egg;
Expand Down
55 changes: 44 additions & 11 deletions crates/uv-distribution-filename/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ use url::Url;

use uv_normalize::{InvalidNameError, PackageName};
use uv_pep440::{Version, VersionParseError};
use uv_platform_tags::{AbiTag, LanguageTag, ParseAbiTagError, ParseLanguageTagError, ParsePlatformTagError, PlatformTag, TagCompatibility, Tags};
use uv_platform_tags::{
AbiTag, LanguageTag, ParseAbiTagError, ParseLanguageTagError, ParsePlatformTagError,
PlatformTag, TagCompatibility, Tags,
};

use crate::{BuildTag, BuildTagError};

/// A [`SmallVec`] type for storing tags.
///
/// Wheels tend to include a single language, ABI, and platform tag, so we use a [`SmallVec`] with a
/// capacity of 1 to optimize for this common case.
pub type TagSet<T> = smallvec::SmallVec<[T; 1]>;

#[derive(
Debug,
Clone,
Expand All @@ -28,9 +37,9 @@ pub struct WheelFilename {
pub name: PackageName,
pub version: Version,
pub build_tag: Option<BuildTag>,
pub python_tag: Vec<LanguageTag>,
pub abi_tag: Vec<AbiTag>,
pub platform_tag: Vec<PlatformTag>,
pub python_tag: TagSet<LanguageTag>,
pub abi_tag: TagSet<AbiTag>,
pub platform_tag: TagSet<PlatformTag>,
}

impl FromStr for WheelFilename {
Expand Down Expand Up @@ -87,12 +96,32 @@ impl WheelFilename {

/// Get the tag for this wheel.
fn get_tag(&self) -> String {
format!(
"{}-{}-{}",
self.python_tag[0],
self.abi_tag[0],
self.platform_tag[0],
)
if let ([python_tag], [abi_tag], [platform_tag]) = (
self.python_tag.as_slice(),
self.abi_tag.as_slice(),
self.platform_tag.as_slice(),
) {
format!("{python_tag}-{abi_tag}-{platform_tag}",)
} else {
format!(
"{}-{}-{}",
self.python_tag
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("."),
self.abi_tag
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("."),
self.platform_tag
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("."),
)
}
}

/// Parse a wheel filename from the stem (e.g., `foo-1.2.3-py3-none-any`).
Expand Down Expand Up @@ -189,7 +218,11 @@ impl WheelFilename {
.map(AbiTag::from_str)
.collect::<Result<_, _>>()
.map_err(|err| WheelFilenameError::InvalidAbiTag(filename.to_string(), err))?,
platform_tag: platform_tag.split('.').map(PlatformTag::from_str).collect::<Result<_, _>>().map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?,
platform_tag: platform_tag
.split('.')
.map(PlatformTag::from_str)
.collect::<Result<_, _>>()
.map_err(|err| WheelFilenameError::InvalidPlatformTag(filename.to_string(), err))?,
})
}
}
Expand Down
Loading

0 comments on commit 17241c3

Please sign in to comment.