Quickly sandbox your AI agent.
Python
fix(build): Filter dep wheels by platform to prevent Rosetta mismatch
Tyler Paynec0326a26a11d
diff --git a/scripts/ci/filter_deps_platform.py b/scripts/ci/filter_deps_platform.pynew file mode 100644index 0000000..16d9200--- /dev/null+++ b/scripts/ci/filter_deps_platform.py@@ -0,0 +1,69 @@+#!/usr/bin/env python3+"""Remove wheels from a directory that don't match the current platform.++uv incorrectly prefers linux_aarch64 over macosx_arm64 when both are in+--find-links. This script removes non-native platform-specific wheels+so only compatible ones remain.++Usage:+ python scripts/ci/filter_deps_platform.py deps/+"""++from __future__ import annotations++import platform+import re+import sys+from pathlib import Path++_WHEEL_RE = re.compile(r"^.+?-.+?-\w+-\w+-(?P<platform>.+)\.whl$")++# Map (system, machine) to platform tag prefixes that are compatible.+# Use exact platform tags (not just prefix) to avoid e.g. uv selecting+# macosx_10_13_x86_64 on arm64 via Rosetta compatibility.+_PLATFORM_TAGS: dict[tuple[str, str], list[str]] = {+ ("Darwin", "arm64"): ["macosx_11_0_arm64", "any"],+ ("Darwin", "x86_64"): ["macosx_10_13_x86_64", "any"],+ ("Linux", "x86_64"): ["linux_x86_64", "any"],+ ("Linux", "aarch64"): ["linux_aarch64", "any"],+ ("Windows", "AMD64"): ["win_amd64", "any"],+ ("Windows", "ARM64"): ["win_arm64", "any"],+}+++def main() -> int:+ if len(sys.argv) < 2:+ print("Usage: filter_deps_platform.py <directory>", file=sys.stderr)+ return 1++ deps_dir = Path(sys.argv[1])+ if not deps_dir.exists():+ return 0++ system = platform.system()+ machine = platform.machine()+ tags = _PLATFORM_TAGS.get((system, machine))+ if not tags:+ print(f"Unknown platform ({system}, {machine}), skipping filter")+ return 0++ removed = 0+ for whl in sorted(deps_dir.glob("*.whl")):+ m = _WHEEL_RE.match(whl.name)+ if not m:+ continue+ plat = m.group("platform")+ if plat == "any":+ continue+ if plat not in tags:+ print(f" Removing incompatible wheel: {whl.name}")+ whl.unlink()+ removed += 1++ if removed:+ print(f"Removed {removed} incompatible wheel(s) from {deps_dir}")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/uvr_hooks.py b/uvr_hooks.pyindex e02e131..610363d 100644--- a/uvr_hooks.py+++ b/uvr_hooks.py@@ -122,11 +122,34 @@ class Hooks(ReleaseHook):update={"test_install": {vm: install for vm in ("ubuntu", "alpine")}})- # Wire the build pre-hook to ensure gh CLI is available.+ # Wire the build pre-hook to ensure gh CLI is available, and+ # inject a platform-filter command after dep downloads. uv+ # incorrectly picks linux_aarch64 over macosx_arm64 from find-links+ # when both are present, so we remove non-native wheels after download.+ from uv_release.commands import ShellCommand+new_jobs = []for job in plan.jobs:- if job.name == "build" and not job.pre_hook:- job = job.model_copy(update={"pre_hook": "ensure_gh"})+ if job.name == "build":+ if not job.pre_hook:+ job = job.model_copy(update={"pre_hook": "ensure_gh"})+ # Insert platform filter after download_wheels+ new_cmds = []+ for cmd in job.commands:+ new_cmds.append(cmd)+ if getattr(cmd, "type", None) == "download_wheels":+ new_cmds.append(+ ShellCommand(+ label="Remove non-native wheels from deps",+ check=False,+ args=[+ "python3",+ "scripts/ci/filter_deps_platform.py",+ "deps",+ ],+ )+ )+ job = job.model_copy(update={"commands": new_cmds})new_jobs.append(job)plan = plan.model_copy(update={"jobs": new_jobs})