Skip to content

Commit

Permalink
Misc. changes based on ABI explorations (#10458)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Jan 10, 2025
1 parent 8d25f29 commit bee2baa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 48 deletions.
4 changes: 2 additions & 2 deletions crates/uv-distribution-types/src/prioritized_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions crates/uv-platform-tags/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
}
Expand Down
34 changes: 11 additions & 23 deletions crates/uv-platform-tags/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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(_))
}
Expand Down Expand Up @@ -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((
Expand Down Expand Up @@ -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<Vec<String>, PlatformError> {
let os = platform.os();
let arch = platform.arch();
Expand All @@ -431,13 +430,13 @@ fn compatible_tags(platform: &Platform) -> Result<Vec<String>, PlatformError> {
}
}
}
// Non-manylinux is lowest priority
// Non-manylinux is given lowest priority.
// <https://github.com/pypa/packaging/blob/fd4f11139d1c884a637be8aa26bb60a31fbc9411/packaging/tags.py#L444>
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}")));
Expand Down Expand Up @@ -516,12 +515,7 @@ fn compatible_tags(platform: &Platform) -> Result<Vec<String>, 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
Expand All @@ -533,23 +527,17 @@ fn compatible_tags(platform: &Platform) -> Result<Vec<String>, 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!(
Expand Down
24 changes: 12 additions & 12 deletions crates/uv-resolver/src/version_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();

Expand Down

0 comments on commit bee2baa

Please sign in to comment.