diff --git a/crates/uv-distribution-types/src/prioritized_distribution.rs b/crates/uv-distribution-types/src/prioritized_distribution.rs index c6261076a..61b010df2 100644 --- a/crates/uv-distribution-types/src/prioritized_distribution.rs +++ b/crates/uv-distribution-types/src/prioritized_distribution.rs @@ -222,7 +222,7 @@ impl Display for IncompatibleDist { } } -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum PythonRequirementKind { /// The installed version of Python. Installed, @@ -266,7 +266,7 @@ pub enum IncompatibleSource { NoBuild, } -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum HashComparison { /// The hash is present, but does not match the expected value. Mismatched, diff --git a/crates/uv-platform-tags/src/platform.rs b/crates/uv-platform-tags/src/platform.rs index 697891b19..b82335036 100644 --- a/crates/uv-platform-tags/src/platform.rs +++ b/crates/uv-platform-tags/src/platform.rs @@ -56,17 +56,17 @@ pub enum Os { impl fmt::Display for Os { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Self::Manylinux { .. } => write!(f, "Manylinux"), - Self::Musllinux { .. } => write!(f, "Musllinux"), - Self::Windows => write!(f, "Windows"), - Self::Macos { .. } => write!(f, "MacOS"), - Self::FreeBsd { .. } => write!(f, "FreeBSD"), - Self::NetBsd { .. } => write!(f, "NetBSD"), - Self::OpenBsd { .. } => write!(f, "OpenBSD"), - Self::Dragonfly { .. } => write!(f, "DragonFly"), - Self::Illumos { .. } => write!(f, "Illumos"), - Self::Haiku { .. } => write!(f, "Haiku"), - Self::Android { .. } => write!(f, "Android"), + Self::Manylinux { .. } => write!(f, "manylinux"), + Self::Musllinux { .. } => write!(f, "musllinux"), + Self::Windows => write!(f, "windows"), + Self::Macos { .. } => write!(f, "macos"), + Self::FreeBsd { .. } => write!(f, "freebsd"), + Self::NetBsd { .. } => write!(f, "netbsd"), + Self::OpenBsd { .. } => write!(f, "openbsd"), + Self::Dragonfly { .. } => write!(f, "dragonfly"), + Self::Illumos { .. } => write!(f, "illumos"), + Self::Haiku { .. } => write!(f, "haiku"), + Self::Android { .. } => write!(f, "android"), } } } diff --git a/crates/uv-platform-tags/src/tags.rs b/crates/uv-platform-tags/src/tags.rs index 9dc99c618..8a15f6f13 100644 --- a/crates/uv-platform-tags/src/tags.rs +++ b/crates/uv-platform-tags/src/tags.rs @@ -21,7 +21,7 @@ pub enum TagsError { GilIsACPythonProblem(String), } -#[derive(Debug, Eq, Ord, PartialEq, PartialOrd, Clone)] +#[derive(Debug, Eq, Ord, PartialEq, PartialOrd, Copy, Clone)] pub enum IncompatibleTag { /// The tag is invalid and cannot be used. Invalid, @@ -35,7 +35,7 @@ pub enum IncompatibleTag { Platform, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum TagCompatibility { Incompatible(IncompatibleTag), Compatible(TagPriority), @@ -59,6 +59,7 @@ impl PartialOrd for TagCompatibility { } impl TagCompatibility { + /// Returns `true` if the tag is compatible. pub fn is_compatible(&self) -> bool { matches!(self, Self::Compatible(_)) } @@ -128,7 +129,7 @@ impl Tags { if let Implementation::CPython { gil_disabled } = implementation { // For some reason 3.2 is the minimum python for the cp abi for minor in (2..=python_version.1).rev() { - // No abi3 for freethreading python + // No abi3 for free-threading python if !gil_disabled { for platform_tag in &platform_tags { tags.push(( @@ -406,8 +407,6 @@ impl Implementation { /// /// We have two cases: Actual platform specific tags (including "merged" tags such as universal2) /// and "any". -/// -/// Bit of a mess, needs to be cleaned up. fn compatible_tags(platform: &Platform) -> Result, PlatformError> { let os = platform.os(); let arch = platform.arch(); @@ -431,13 +430,13 @@ fn compatible_tags(platform: &Platform) -> Result, PlatformError> { } } } - // Non-manylinux is lowest priority + // Non-manylinux is given lowest priority. // platform_tags.push(format!("linux_{arch}")); platform_tags } (Os::Musllinux { major, minor }, _) => { - let mut platform_tags = vec![format!("linux_{}", arch)]; + let mut platform_tags = vec![format!("linux_{arch}")]; // musl 1.1 is the lowest supported version in musllinux platform_tags .extend((1..=*minor).map(|minor| format!("musllinux_{major}_{minor}_{arch}"))); @@ -516,12 +515,7 @@ fn compatible_tags(platform: &Platform) -> Result, PlatformError> { _, ) => { let release = release.replace(['.', '-'], "_"); - vec![format!( - "{}_{}_{}", - os.to_string().to_lowercase(), - release, - arch - )] + vec![format!("{os}_{release}_{arch}")] } (Os::Illumos { release, arch }, _) => { // See https://github.com/python/cpython/blob/46c8d915715aa2bd4d697482aa051fe974d440e1/Lib/sysconfig.py#L722-L730 @@ -533,23 +527,17 @@ fn compatible_tags(platform: &Platform) -> Result, PlatformError> { })?; if major_ver >= 5 { // SunOS 5 == Solaris 2 - let os = "solaris".to_string(); + let os = "solaris"; let release = format!("{}_{}", major_ver - 3, other); let arch = format!("{arch}_64bit"); - return Ok(vec![format!("{}_{}_{}", os, release, arch)]); + return Ok(vec![format!("{os}_{release}_{arch}")]); } } - let os = os.to_string().to_lowercase(); - vec![format!("{}_{}_{}", os, release, arch)] + vec![format!("{os}_{release}_{arch}")] } (Os::Android { api_level }, _) => { - vec![format!( - "{}_{}_{}", - os.to_string().to_lowercase(), - api_level, - arch - )] + vec![format!("{os}_{api_level}_{arch}")] } _ => { return Err(PlatformError::OsVersionDetectionError(format!( diff --git a/crates/uv-resolver/src/version_map.rs b/crates/uv-resolver/src/version_map.rs index 715d9ab5d..505691673 100644 --- a/crates/uv-resolver/src/version_map.rs +++ b/crates/uv-resolver/src/version_map.rs @@ -521,14 +521,22 @@ impl VersionMapLazy { } // Determine a compatibility for the wheel based on tags. - let priority = match &self.tags { - Some(tags) => match filename.compatibility(tags) { + let priority = if let Some(tags) = &self.tags { + match filename.compatibility(tags) { TagCompatibility::Incompatible(tag) => { return WheelCompatibility::Incompatible(IncompatibleWheel::Tag(tag)) } TagCompatibility::Compatible(priority) => Some(priority), - }, - None => None, + } + } else { + // Check if the wheel is compatible with the `requires-python` (i.e., the Python + // ABI tag is not less than the `requires-python` minimum version). + if !self.requires_python.matches_wheel_tag(filename) { + return WheelCompatibility::Incompatible(IncompatibleWheel::Tag( + IncompatibleTag::AbiPythonVersion, + )); + } + None }; // Check if hashes line up. If hashes aren't required, they're considered matching. @@ -546,14 +554,6 @@ impl VersionMapLazy { } }; - // Check if the wheel is compatible with the `requires-python` (i.e., the Python ABI tag - // is not less than the `requires-python` minimum version). - if !self.requires_python.matches_wheel_tag(filename) { - return WheelCompatibility::Incompatible(IncompatibleWheel::Tag( - IncompatibleTag::AbiPythonVersion, - )); - } - // Break ties with the build tag. let build_tag = filename.build_tag.clone();