Filter wheels from lockfile based on architecture (#10584)

## Summary

After we resolve, we filter out any wheels that aren't applicable for
the target platforms. So, e.g., we remove macOS wheels if we find that
the user only asked to solve for Windows.

This PR extends the same logic to architectures, so that we filter out
ARM-only wheels when the user is only solving for x86, etc.

Closes #10571.
This commit is contained in:
Charlie Marsh 2025-01-14 09:39:21 -05:00 committed by GitHub
parent faa4481ccc
commit e3f6b9c5f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 550 additions and 28 deletions

View file

@ -73,6 +73,25 @@ static MAC_MARKERS: LazyLock<UniversalMarker> = LazyLock::new(|| {
let pep508 = MarkerTree::from_str("os_name == 'posix' and sys_platform == 'darwin'").unwrap();
UniversalMarker::new(pep508, ConflictMarker::TRUE)
});
static ARM_MARKERS: LazyLock<UniversalMarker> = LazyLock::new(|| {
let pep508 =
MarkerTree::from_str("platform_machine == 'aarch64' or platform_machine == 'arm64'")
.unwrap();
UniversalMarker::new(pep508, ConflictMarker::TRUE)
});
static X86_64_MARKERS: LazyLock<UniversalMarker> = LazyLock::new(|| {
let pep508 =
MarkerTree::from_str("platform_machine == 'x86_64' or platform_machine == 'amd64'")
.unwrap();
UniversalMarker::new(pep508, ConflictMarker::TRUE)
});
static X86_MARKERS: LazyLock<UniversalMarker> = LazyLock::new(|| {
let pep508 = MarkerTree::from_str(
"platform_machine == 'i686' or platform_machine == 'i386' or platform_machine == 'win32' or platform_machine == 'x86'",
)
.unwrap();
UniversalMarker::new(pep508, ConflictMarker::TRUE)
});
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(try_from = "LockWire")]
@ -275,25 +294,66 @@ impl Lock {
let platform_tags = &wheel.filename.platform_tag;
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_linux_compatible)
.all(uv_platform_tags::PlatformTag::is_linux)
{
!graph.graph[node_index].marker().is_disjoint(*LINUX_MARKERS)
} else if platform_tags
if graph.graph[node_index].marker().is_disjoint(*LINUX_MARKERS) {
return false;
}
}
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_windows_compatible)
.all(uv_platform_tags::PlatformTag::is_windows)
{
// TODO(charlie): This omits `win_ia64`, which is accepted by Warehouse.
!graph.graph[node_index]
if graph.graph[node_index]
.marker()
.is_disjoint(*WINDOWS_MARKERS)
} else if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_macos_compatible)
{
!graph.graph[node_index].marker().is_disjoint(*MAC_MARKERS)
} else {
true
{
return false;
}
}
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_macos)
{
if graph.graph[node_index].marker().is_disjoint(*MAC_MARKERS) {
return false;
}
}
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_arm)
{
if graph.graph[node_index].marker().is_disjoint(*ARM_MARKERS) {
return false;
}
}
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_x86_64)
{
if graph.graph[node_index]
.marker()
.is_disjoint(*X86_64_MARKERS)
{
return false;
}
}
if platform_tags
.iter()
.all(uv_platform_tags::PlatformTag::is_x86)
{
if graph.graph[node_index].marker().is_disjoint(*X86_MARKERS) {
return false;
}
}
true
});
}