Files
VoiceStudio/scripts/build_vendored_wheels.py
Palash Debnath 409c893449 fix(setup): ship wheels for source-only deps so setup never compiles (#4253) (#4268)
* fix(setup): ship wheels for source-only deps so first-run setup never compiles (#4253)

* docs(changelog): add fragment for #4268

* fix(setup): make vendored wheels verifiable and shipped by every consumer (#4253)

* chore(vendor): ship the ANTLR BSD notice with the vendored runtime wheel

BSD-3 requires the copyright notice to accompany binary redistribution; the antlr4-python3-runtime sdist ships none, so keep the project notice beside the wheel and package it.

* test(install): accept vendored wheel paths in the frozen export

uv export emits the vendored wheels (#4253) as ./vendor/wheels/*.whl paths, which packaging.Requirement rejects.

* test(lock): check per-target wheel tags and extras; ship the ANTLR notice in Nix

The wheel-only guard now follows extra-activated dependencies and requires a wheel whose tags match each tested platform and Python, not just any wheel. sphn 0.2.1 has no Linux ARM64 wheel upstream and is allowlisted for that source-only target. The Nix output now installs the ANTLR licence beside the vendored wheel.

* ci(dagger): copy the vendored wheels before the dependency sync

[tool.uv.sources] points docopt, antlr4-python3-runtime and dora-search at vendor/wheels (#4253); the manifest-only layer copied pyproject.toml and uv.lock without them, so dagger python-tests and check could not install.

* ci(install): run the install smoke when the vendored wheels change

The installer ships vendor/wheels (#4253), so tests/test_install_smoke_workflow.py requires it among the install-smoke triggers.
2026-11-20 11:39:13 +05:30

87 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Rebuild, or verify, the wheels vendored under ``vendor/wheels/`` (#4253).
Each wheel is built from the PyPI sdist recorded in ``vendor/wheels/SOURCES.json``
(URL plus sha256, copied from the former ``uv.lock`` entry) with the build
backend pinned in ``vendor/wheels/build-constraints.txt``.
uv run python scripts/build_vendored_wheels.py # rebuild all wheels
uv run python scripts/build_vendored_wheels.py --verify # rebuild to a temp dir and
# compare every file's content
After a rebuild run ``uv lock`` so the wheel hashes in ``uv.lock`` follow.
Downloads only the sdist URLs listed in SOURCES.json (the URLs ``uv.lock`` used
to pin); nothing else.
"""
from __future__ import annotations
import argparse
import hashlib
import json
import subprocess
import sys
import tarfile
import tempfile
import urllib.request
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
WHEELS = ROOT / "vendor" / "wheels"
SOURCES = WHEELS / "SOURCES.json"
CONSTRAINTS = WHEELS / "build-constraints.txt"
def _build(entry: dict, work: Path, out: Path) -> Path:
sdist = work / entry["sdist_url"].rsplit("/", 1)[1]
with urllib.request.urlopen(entry["sdist_url"], timeout=60) as response: # noqa: S310 - pinned https URL
data = response.read()
digest = hashlib.sha256(data).hexdigest()
if digest != entry["sdist_sha256"]:
raise SystemExit(f"{entry['name']}: sdist sha256 {digest} != pinned {entry['sdist_sha256']}")
sdist.write_bytes(data)
src = work / entry["name"]
with tarfile.open(sdist) as tar:
tar.extractall(src, filter="data")
(project,) = [p for p in src.iterdir() if p.is_dir()]
subprocess.run(
["uv", "build", "--wheel", "--out-dir", str(out), "--build-constraints", str(CONSTRAINTS), str(project)],
check=True,
)
(wheel,) = out.glob(f"{entry['name'].replace('-', '_')}-{entry['version']}-*.whl")
return wheel
def _contents(path: Path) -> dict[str, bytes]:
with zipfile.ZipFile(path) as z:
return {n: z.read(n) for n in z.namelist() if not n.endswith("/RECORD")}
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--verify", action="store_true", help="compare to the committed wheels, change nothing")
args = parser.parse_args()
entries = json.loads(SOURCES.read_text(encoding="utf-8"))["wheels"]
bad = 0
for entry in entries:
with tempfile.TemporaryDirectory() as tmp:
work, out = Path(tmp, "work"), Path(tmp, "out")
work.mkdir()
built = _build(entry, work, out)
target = WHEELS / entry["wheel"]
if args.verify:
same = _contents(built) == _contents(target)
print(f"{entry['name']}: {'identical contents' if same else 'DIFFERS'}")
bad += not same
else:
if built.name != entry["wheel"]:
raise SystemExit(f"built {built.name}, SOURCES.json expects {entry['wheel']}")
target.write_bytes(built.read_bytes())
print(f"wrote {target.relative_to(ROOT)}")
return 1 if bad else 0
if __name__ == "__main__":
sys.exit(main())