From 86d313a5f4b16fcb948d7d06be768a58246b23a8 Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Wed, 4 Nov 2026 14:09:30 -0700 Subject: [PATCH 1/2] Conditional Pythons 3.12-3.14 for lyrical From #193, on top of the vinca-rs stack: vinca-rs builds the packages with Python content for each Python (conditional_python_dependency) and the others once. A package's classification is overridden with python in add_host or remove_host in pkg_additional_info.yaml. rattler-build 0.81 has the fix the temporary pre-release pin was for (prefix-dev/rattler-build#2931, released in 0.80.1), and lyrical keeps the shared Qt 6.12. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 + README.md | 10 ++ distros/lyrical/conda_build_config.yaml | 11 +- distros/lyrical/distro.yaml | 19 ++- distros/lyrical/vinca.yaml | 7 +- tools/python_abi_audit.py | 216 ++++++++++++++++++++++++ tools/robostack.py | 2 + tools/tests/test_python_abi_audit.py | 30 ++++ 8 files changed, 291 insertions(+), 9 deletions(-) create mode 100644 tools/python_abi_audit.py create mode 100644 tools/tests/test_python_abi_audit.py diff --git a/AGENTS.md b/AGENTS.md index cb4f13126..ca5a5294f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,6 +22,10 @@ to read without Claude): into `distros//`. - Run everything per distribution with `pixi run rs `, from the repository root. Package names are `ros2-` (dashes), e.g. `ros2-rsl`. +- lyrical builds packages with Python content for Python 3.12-3.14 and the others once + (`conditional_python_dependency`, see README "Python versions"). A built-once package + that fails its `package_contents` test ships Python after all: add `python` to its + `add_host` in `pkg_additional_info.yaml`. - Never edit `conda_build_config.yaml` by hand: change `shared/pinning/` or the distribution's `distro.yaml`, then `pixi run rs render-pinning` (CI checks it). - A change outside `distros/` rebuilds every distribution in CI; keep such PRs focused. @@ -52,6 +56,7 @@ pixi run rs build --continue-on-failure # everything missing on the chan pixi run rs check-patches [--recipe ros2-] pixi run rs check-deps # pin conflicts, before building anything pixi run rs gap-report # recipes without artifacts and vice versa +pixi run rs python-audit [--elf] # per-Python vs built-once recipes against the published packages pixi run rs add-package ... [...] # select packages (as the bot does) pixi run rs check # sanity checks (CI) ``` diff --git a/README.md b/README.md index 669ed408c..2dbbd7773 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,16 @@ pixi run rs check # sanity checks (also run in CI) of a distribution uses `full_rebuild: true` there. A new build number goes into its `pkg_additional_info.yaml` (one package) or `vinca.yaml` (everything). +**Python versions:** a distribution's `pinning_overrides` can list several Pythons, as +lyrical does for 3.12-3.14. With `conditional_python_dependency: true` in its +`vinca.yaml`, only packages with Python content (Python modules, rosidl Python bindings, +extensions) get python in host/run and are built once per Python; the others are built +once, without a `python_abi` dependency, and fail their build if they ship +`site-packages` content or a CPython extension anyway. When vinca-rs's guess from +`package.xml` is wrong, add `python` to the package's `add_host` (or `remove_host`) in +`pkg_additional_info.yaml`. `pixi run rs python-audit [--elf]` compares the +guess with the published packages and lists the misses. + **Building only some distributions in a PR:** a PR builds the distributions it changes, and all of them as soon as it touches anything outside `distros//`. To limit that (e.g. a humble rebuild that also changes `shared/` or `tools/`), add the label diff --git a/distros/lyrical/conda_build_config.yaml b/distros/lyrical/conda_build_config.yaml index 939e50355..cab359277 100644 --- a/distros/lyrical/conda_build_config.yaml +++ b/distros/lyrical/conda_build_config.yaml @@ -998,8 +998,9 @@ pythia8: python: # conda-forge supports only 3.14+ for win-arm64 and linux-riscv64 # part of a zip_keys: python, is_python_min + - 3.12.* *_cpython # [not ((win and arm64) or riscv64)] + - 3.13.* *_cp313 # [not ((win and arm64) or riscv64)] - 3.14.* *_cp314 - - 3.12.* *_cpython python_impl: - cpython @@ -1007,14 +1008,16 @@ python_impl: python_min: # minimum supported python version per CFEP-25 # bump to next minor version when we drop python versions - - '3.11' # [not ((win and arm64) or riscv64)] + - '3.12' # [not ((win and arm64) or riscv64)] - '3.14' # [(win and arm64) or riscv64] is_freethreading: - false is_python_min: # part of a zip_keys: python, is_python_min - - false - - false + - true # [not ((win and arm64) or riscv64)] + - false # [not ((win and arm64) or riscv64)] + - false # [not ((win and arm64) or riscv64)] + - true # [(win and arm64) or riscv64] is_abi3: - true pytorch: diff --git a/distros/lyrical/distro.yaml b/distros/lyrical/distro.yaml index ce31e3f74..ea1dd1a6e 100644 --- a/distros/lyrical/distro.yaml +++ b/distros/lyrical/distro.yaml @@ -7,7 +7,18 @@ upload_to: [prefix, anaconda] read_from: prefix rosdistro_sync: lyrical/2026-10-05 pinning_overrides: - # build every python package for 3.14 (the shared default) and 3.12; - # is_python_min is zipped with python, so it needs one entry per version - python: [3.14.* *_cp314, 3.12.* *_cpython] - is_python_min: [false, false] + # Lyrical supports Python 3.12-3.14 (REP 2000). Packages with Python content are + # built for each (vinca.yaml: conditional_python_dependency), the others once. + # conda-forge has only 3.14+ for win-arm64 and linux-riscv64, so those get one variant. + python: + - 3.12.* *_cpython # [not ((win and arm64) or riscv64)] + - 3.13.* *_cp313 # [not ((win and arm64) or riscv64)] + - 3.14.* *_cp314 + is_python_min: + - true # [not ((win and arm64) or riscv64)] + - false # [not ((win and arm64) or riscv64)] + - false # [not ((win and arm64) or riscv64)] + - true # [(win and arm64) or riscv64] + python_min: + - '3.12' # [not ((win and arm64) or riscv64)] + - '3.14' # [(win and arm64) or riscv64] diff --git a/distros/lyrical/vinca.yaml b/distros/lyrical/vinca.yaml index 15070a041..6b5bf9f9d 100644 --- a/distros/lyrical/vinca.yaml +++ b/distros/lyrical/vinca.yaml @@ -3,7 +3,12 @@ ros_distro: lyrical patch_dir: patch rosdistro_snapshot: rosdistro_snapshot.yaml rosdistro_additional_recipes: rosdistro_additional_recipes.yaml -build_number: 30 +build_number: 31 +# Only packages with Python content get python in host/run, and with it the Python +# variants of distro.yaml (cp312-cp314); the others are built once, without a +# python_abi dependency. Override the classification per package with python in +# add_host (or remove_host) in pkg_additional_info.yaml. +conditional_python_dependency: true mutex_package: version: 0.22.0 diff --git a/tools/python_abi_audit.py b/tools/python_abi_audit.py new file mode 100644 index 000000000..3106729ee --- /dev/null +++ b/tools/python_abi_audit.py @@ -0,0 +1,216 @@ +"""Check vinca's Python classification (conditional_python_dependency) against the +published packages. + + pixi run rs lyrical python-audit # linux-64, info/paths.json only + pixi run rs lyrical python-audit --elf # also scan ELF files for libpython + pixi run rs lyrical python-audit --platform osx-arm64 --json audit.json + +A generated recipe (work/recipes) either has python in host, and is built for every +Python of the distribution's pinning, or not, and is built once. This compares that +with what the newest published build of each ros2-* package actually contains: + +- native: CPython extensions (*.cpython-*.so, *.pyd), rosidl_generator_py libraries, + or (--elf) ELF files that link libpython; +- pure: only Python modules (site-packages); +- none: no Python content. + +A recipe built once whose published package has Python content is a miss: that +content would only work with the Python it happened to be built with. Misses make +the exit status 1; fix them with `add_host: ["python"]` in pkg_additional_info.yaml. +Recipes built per Python without Python content in the package are only reported +(an unneeded rebuild per Python, not a broken package). + +Run it before the switch to per-Python builds, while the channel still has the +packages that were built with python in host (their content is complete). +""" + +from __future__ import annotations + +import argparse +import io +import json +import re +import sys +import tarfile +import urllib.request +import zipfile +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +import yaml +import zstandard + +UA = {"User-Agent": "robostack-python-audit"} +SITE_PACKAGES = re.compile(r"(^|/)(lib/python[0-9.]*/site-packages|Lib/site-packages)/") +EXTENSION = re.compile(r"\.cpython-[^/]*\.(so|dylib)$|\.pyd$") + + +class RangeReader(io.RawIOBase): + """A remote file read with HTTP range requests (zipfile only needs the end and + the info-*.tar.zst member of a .conda).""" + + def __init__(self, url: str): + with urllib.request.urlopen(urllib.request.Request(url, headers={**UA, "Range": "bytes=0-0"}), + timeout=120) as r: + self.url = r.url + content_range = r.headers.get("Content-Range") + if r.status != 206 or not content_range: + raise OSError(f"{url}: no range support") + self.size = int(content_range.split("/")[1]) + self.pos = 0 + + def readable(self) -> bool: + return True + + def seekable(self) -> bool: + return True + + def tell(self) -> int: + return self.pos + + def seek(self, offset: int, whence: int = 0) -> int: + self.pos = {0: offset, 1: self.pos + offset, 2: self.size + offset}[whence] + return self.pos + + def readinto(self, b) -> int: + n = min(len(b), self.size - self.pos) + if n <= 0: + return 0 + headers = {**UA, "Range": f"bytes={self.pos}-{self.pos + n - 1}"} + with urllib.request.urlopen(urllib.request.Request(self.url, headers=headers), timeout=300) as r: + data = r.read() + b[: len(data)] = data + self.pos += len(data) + return len(data) + + +def open_conda(url: str, whole: bool) -> zipfile.ZipFile: + if not whole: + try: + return zipfile.ZipFile(io.BufferedReader(RangeReader(url), buffer_size=1 << 16)) + except OSError: + pass + with urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=600) as r: + return zipfile.ZipFile(io.BytesIO(r.read())) + + +def members(z: zipfile.ZipFile, prefix: str): + name = next(n for n in z.namelist() if n.startswith(prefix)) + stream = zstandard.ZstdDecompressor().stream_reader(z.open(name)) + with tarfile.open(fileobj=stream, mode="r|") as tar: + for member in tar: + if member.isfile(): + yield member, tar.extractfile(member) + + +def inspect(url: str, elf: bool) -> dict: + """Classify by info/paths.json; with *elf*, a package without Python files is + downloaded whole and its ELF files are searched for libpython (embedding).""" + for attempt in range(3): + try: + z = open_conda(url, whole=False) + paths = [] + for member, f in members(z, "info-"): + if member.name == "info/paths.json": + paths = [p["_path"] for p in json.load(f)["paths"]] + break + result = classify(paths, []) + if elf and result["content"] == "none": + linked = [member.name for member, f in members(open_conda(url, whole=True), "pkg-") + if (data := f.read())[:4] == b"\x7fELF" and b"libpython3." in data] + result = classify(paths, linked) + return result + except Exception as err: # noqa: BLE001 - network or archive trouble: retried, then reported + error = err + return {"content": "error", "error": str(error)} + + +def classify(paths: list[str], linked: list[str]) -> dict: + site = [p for p in paths if SITE_PACKAGES.search(p)] + native = [p for p in paths if EXTENSION.search(p)] + native += [p for p in paths if "rosidl_generator_py" in p and re.search(r"\.(so|dylib|dll)$", p)] + native += linked + content = "native" if native else "pure" if site else "none" + return {"content": content, "examples": (native or site)[:3]} + + +def flatten(requirements) -> list[str]: + out = [] + for r in requirements or []: + if isinstance(r, dict): + out += flatten(r.get("then")) + flatten(r.get("else")) + else: + out.append(str(r)) + return out + + +def recipes_needing_python(recipes: Path) -> dict[str, bool]: + result = {} + for path in sorted(recipes.glob("ros2-*/recipe.yaml")): + recipe = yaml.safe_load(path.read_text()) + host = flatten((recipe.get("requirements") or {}).get("host")) + result[recipe["package"]["name"]] = "python" in host + return result + + +def newest_builds(repodata: dict) -> dict[str, str]: + records = {**repodata.get("packages", {}), **repodata.get("packages.conda", {})} + newest: dict[str, tuple] = {} + for fn, rec in records.items(): + key = (rec["build_number"], rec.get("timestamp", 0)) + if rec["name"].startswith("ros2-") and key > newest.get(rec["name"], ((-1, 0), ""))[0]: + newest[rec["name"]] = (key, fn) + return {name: fn for name, (_, fn) in newest.items()} + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--channel", required=True, help="channel URL, e.g. https://prefix.dev/robostack-lyrical") + parser.add_argument("--platform", default="linux-64") + parser.add_argument("--recipes", default="recipes", type=Path, help="generated recipes (default: ./recipes)") + parser.add_argument("--elf", action="store_true", + help="download the packages without Python files and look for libpython in their ELF files") + parser.add_argument("--json", type=Path, help="write the per-package results here") + args = parser.parse_args() + + needs = recipes_needing_python(args.recipes) + if not needs: + print(f"No ros2-* recipes in {args.recipes}: run generate-recipes first", file=sys.stderr) + return 1 + with urllib.request.urlopen(urllib.request.Request(f"{args.channel}/{args.platform}/repodata.json", headers=UA), + timeout=300) as r: + published = newest_builds(json.load(r)) + + names = [n for n in needs if n in published] + def work(name: str) -> tuple[str, dict]: + url = f"{args.channel}/{args.platform}/{published[name]}" + return name, {"file": published[name], **inspect(url, elf=args.elf)} + + with ThreadPoolExecutor(16) as pool: + results = dict(pool.map(work, names)) + + misses = sorted(n for n, r in results.items() if not needs[n] and r["content"] in ("native", "pure")) + unneeded = sorted(n for n, r in results.items() if needs[n] and r["content"] == "none") + errors = sorted(n for n, r in results.items() if r["content"] == "error") + counts: dict[tuple[bool, str], int] = {} + for n, r in results.items(): + counts[(needs[n], r["content"])] = counts.get((needs[n], r["content"]), 0) + 1 + + print(f"{len(needs)} recipes, {len(results)} with a published {args.platform} package, " + f"{len(needs) - len(results)} unpublished") + for (per_python, content), count in sorted(counts.items()): + print(f" {'per Python' if per_python else 'built once':10} package content {content:7} {count}") + for name in misses: + print(f"MISS {name}: built once, but ships {results[name]['content']} Python: {results[name]['examples']}") + if unneeded: + print(f"{len(unneeded)} recipes are built per Python without Python content: {', '.join(unneeded)}") + for name in errors: + print(f"ERROR {name}: {results[name]['error']}", file=sys.stderr) + if args.json: + args.json.write_text(json.dumps({n: {"per_python": needs[n], **r} for n, r in results.items()}, + indent=1, sort_keys=True) + "\n") + return 1 if misses or errors else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/robostack.py b/tools/robostack.py index 6dc653a90..3e5687e38 100644 --- a/tools/robostack.py +++ b/tools/robostack.py @@ -588,6 +588,8 @@ def task(distro: str, name: str, args: list[str]) -> int: return run(py + [str(TOOLS / "check_dependency_compat.py"), *args], w) if name == "gap-report": return run(py + [str(TOOLS / "build_gap_report.py"), *args], w) + if name == "python-audit": + return run(py + [str(TOOLS / "python_abi_audit.py"), "--channel", repodata_url(distro), *args], w) if name in ("build", "build-one"): if not (w / "recipes").is_dir(): print(f"No {(w / 'recipes').relative_to(ROOT)}: run `pixi run rs {distro} generate-recipes` first", diff --git a/tools/tests/test_python_abi_audit.py b/tools/tests/test_python_abi_audit.py new file mode 100644 index 000000000..580f858fd --- /dev/null +++ b/tools/tests/test_python_abi_audit.py @@ -0,0 +1,30 @@ +import python_abi_audit as audit + + +def test_classify_by_package_content(): + assert audit.classify(["share/a/package.xml", "share/a/launch/__pycache__/x.cpython-314.pyc"], [])["content"] == "none" + assert audit.classify(["lib/python3.14/site-packages/a/__init__.py"], [])["content"] == "pure" + assert audit.classify(["lib/python/site-packages/a/__init__.py"], [])["content"] == "pure" + assert audit.classify(["Lib/site-packages/a/__init__.py"], [])["content"] == "pure" + assert audit.classify(["lib/a/_a.cpython-314-x86_64-linux-gnu.so"], [])["content"] == "native" + assert audit.classify(["Lib/site-packages/a/_a.cp314-win_amd64.pyd"], [])["content"] == "native" + assert audit.classify(["lib/liba_msgs__rosidl_generator_py.so"], [])["content"] == "native" + assert audit.classify(["lib/a/node"], ["lib/a/node"])["content"] == "native" + + +def test_recipes_needing_python_reads_host(tmp_path): + for name, host in (("ros2-a", "[{if: unix, then: [python]}, ros2-b]"), + ("ros2-b", "[\"python ${{ python_min }}.*\"]"), + ("ros-lyrical-a", "[python]")): + (tmp_path / name).mkdir() + (tmp_path / name / "recipe.yaml").write_text(f"package: {{name: {name}}}\nrequirements:\n host: {host}\n") + assert audit.recipes_needing_python(tmp_path) == {"ros2-a": True, "ros2-b": False} + + +def test_newest_builds_takes_the_highest_build_number(): + def rec(name, number, timestamp=0): + return {"name": name, "build_number": number, "timestamp": timestamp} + + repodata = {"packages.conda": {"a-1-h_30.conda": rec("ros2-a", 30), "a-1-h_29.conda": rec("ros2-a", 29, 9), + "a-1-g_30.conda": rec("ros2-a", 30, 5), "x.conda": rec("ros-lyrical-a", 31)}} + assert audit.newest_builds(repodata) == {"ros2-a": "a-1-g_30.conda"} From 3c05ecac69b78d5872ad5d2d413101199aaa8024 Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Fri, 4 Dec 2026 10:58:15 +1000 Subject: [PATCH 2/2] Tools: py-rattler for versions, repodata and package archives From #211, without its reuse of vinca's code: py-rattler's Version and VersionSpec replace the hand-written version logic of check_dependency_compat (which got `~=` constraints wrong; tests for version ordering and constraints), the maintenance tasks and abi_check; abi_check, package_tests and python_abi_audit fetch repodata and download and read package archives with py-rattler, through one helper (tools/channel_repodata.py) instead of urllib, zipfile and zstandard. check_dependency_compat keeps reading local channels and repodata.json files itself. Co-Authored-By: Claude Opus 5.5 --- pixi.lock | 163 ++++++++++++++++++++++++++ pixi.toml | 4 +- tools/abi_check.py | 95 +++++---------- tools/channel_repodata.py | 30 +++++ tools/check_dependency_compat.py | 87 ++++---------- tools/maintenance.py | 21 ++-- tools/package_tests.py | 49 ++------ tools/python_abi_audit.py | 124 +++++--------------- tools/tests/test_dependency_compat.py | 28 +++++ tools/tests/test_package_tests.py | 31 ++--- tools/tests/test_python_abi_audit.py | 10 +- 11 files changed, 343 insertions(+), 299 deletions(-) create mode 100644 tools/channel_repodata.py create mode 100644 tools/tests/test_dependency_compat.py diff --git a/pixi.lock b/pixi.lock index 905cd84de..25611d0ff 100644 --- a/pixi.lock +++ b/pixi.lock @@ -69,6 +69,7 @@ environments: - conda: https://prefix.dev/conda-forge/linux-64/ncurses-6.6-hdb14827_1.conda - conda: https://prefix.dev/conda-forge/linux-64/openssl-3.6.5-h781a0a9_0.conda - conda: https://prefix.dev/conda-forge/linux-64/patchelf-0.19.2-hee9eb32_0.conda + - conda: https://prefix.dev/conda-forge/linux-64/py-rattler-0.29.0-py311hc91d8b8_1.conda - conda: https://prefix.dev/conda-forge/linux-64/python-3.14.7-hcd007b5_106_cp314.conda - conda: https://prefix.dev/conda-forge/linux-64/pyyaml-6.0.3-py314h93e9acf_4.conda - conda: https://prefix.dev/conda-forge/linux-64/rattler-build-0.81.0-hf01adef_1.conda @@ -78,14 +79,17 @@ environments: - conda: https://prefix.dev/conda-forge/linux-64/tk-8.6.13-noxft_h1df4ec4_4.conda - conda: https://prefix.dev/conda-forge/linux-64/yaml-0.2.5-hebe6cf0_3.conda - conda: https://prefix.dev/conda-forge/linux-64/zstd-1.5.7-hb78ec9c_7.conda + - conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://prefix.dev/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda - conda: https://prefix.dev/conda-forge/noarch/pluggy-1.6.0-pyhf9edf01_1.conda - conda: https://prefix.dev/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda - conda: https://prefix.dev/conda-forge/noarch/pytest-9.2.0-pyhc364b38_1.conda + - conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda - conda: https://prefix.dev/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda - conda: https://prefix.dev/conda-forge/noarch/tomli-2.5.0-pyh5ded981_0.conda @@ -150,6 +154,7 @@ environments: - conda: https://prefix.dev/conda-forge/linux-aarch64/ncurses-6.6-h2b6f883_1.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/openssl-3.6.5-he6ad1d5_0.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/patchelf-0.19.2-hfb11796_0.conda + - conda: https://prefix.dev/conda-forge/linux-aarch64/py-rattler-0.29.0-py311h40f29f8_1.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/python-3.14.7-hbec3b18_106_cp314.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/pyyaml-6.0.3-py314ha6eade7_4.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/rattler-build-0.81.0-hc342849_1.conda @@ -159,14 +164,17 @@ environments: - conda: https://prefix.dev/conda-forge/linux-aarch64/tk-8.6.13-noxft_hf03c496_4.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/yaml-0.2.5-h29ee22c_3.conda - conda: https://prefix.dev/conda-forge/linux-aarch64/zstd-1.5.7-h9d15635_7.conda + - conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://prefix.dev/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda - conda: https://prefix.dev/conda-forge/noarch/pluggy-1.6.0-pyhf9edf01_1.conda - conda: https://prefix.dev/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda - conda: https://prefix.dev/conda-forge/noarch/pytest-9.2.0-pyhc364b38_1.conda + - conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda - conda: https://prefix.dev/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda - conda: https://prefix.dev/conda-forge/noarch/tomli-2.5.0-pyh5ded981_0.conda @@ -199,14 +207,17 @@ environments: - pypi: https://files.pythonhosted.org/packages/e5/ca/78d423b324b8d77900030fa59c4aa9054261ef0925631cd2501dd015b7b7/boolean_py-5.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl osx-64: + - conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://prefix.dev/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda - conda: https://prefix.dev/conda-forge/noarch/pluggy-1.6.0-pyhf9edf01_1.conda - conda: https://prefix.dev/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda - conda: https://prefix.dev/conda-forge/noarch/pytest-9.2.0-pyhc364b38_1.conda + - conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda - conda: https://prefix.dev/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda - conda: https://prefix.dev/conda-forge/noarch/tomli-2.5.0-pyh5ded981_0.conda @@ -237,6 +248,7 @@ environments: - conda: https://prefix.dev/conda-forge/osx-64/libzlib-1.3.2-hbb4bfdb_3.conda - conda: https://prefix.dev/conda-forge/osx-64/ncurses-6.6-hcc0dc9a_1.conda - conda: https://prefix.dev/conda-forge/osx-64/openssl-3.6.5-h332eb6d_0.conda + - conda: https://prefix.dev/conda-forge/osx-64/py-rattler-0.29.0-py311h85c30bf_1.conda - conda: https://prefix.dev/conda-forge/osx-64/python-3.14.7-hafa0b4b_106_cp314.conda - conda: https://prefix.dev/conda-forge/osx-64/pyyaml-6.0.3-py314h5a040e6_4.conda - conda: https://prefix.dev/conda-forge/osx-64/rattler-build-0.81.0-h063bc13_1.conda @@ -273,14 +285,17 @@ environments: - pypi: https://files.pythonhosted.org/packages/e5/ca/78d423b324b8d77900030fa59c4aa9054261ef0925631cd2501dd015b7b7/boolean_py-5.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl osx-arm64: + - conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-hbd8a1cb_0.conda - conda: https://prefix.dev/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda - conda: https://prefix.dev/conda-forge/noarch/pluggy-1.6.0-pyhf9edf01_1.conda - conda: https://prefix.dev/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda - conda: https://prefix.dev/conda-forge/noarch/pytest-9.2.0-pyhc364b38_1.conda + - conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda - conda: https://prefix.dev/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda - conda: https://prefix.dev/conda-forge/noarch/tomli-2.5.0-pyh5ded981_0.conda @@ -311,6 +326,7 @@ environments: - conda: https://prefix.dev/conda-forge/osx-arm64/libzlib-1.3.2-h8088a28_3.conda - conda: https://prefix.dev/conda-forge/osx-arm64/ncurses-6.6-he64c551_1.conda - conda: https://prefix.dev/conda-forge/osx-arm64/openssl-3.6.5-h55eecbc_0.conda + - conda: https://prefix.dev/conda-forge/osx-arm64/py-rattler-0.29.0-py311h1e0e963_1.conda - conda: https://prefix.dev/conda-forge/osx-arm64/python-3.14.7-h0ae1c2c_106_cp314.conda - conda: https://prefix.dev/conda-forge/osx-arm64/pyyaml-6.0.3-py314he08ecf6_4.conda - conda: https://prefix.dev/conda-forge/osx-arm64/rattler-build-0.81.0-hab7db58_1.conda @@ -347,8 +363,10 @@ environments: - pypi: https://files.pythonhosted.org/packages/e5/ca/78d423b324b8d77900030fa59c4aa9054261ef0925631cd2501dd015b7b7/boolean_py-5.0-py3-none-any.whl - pypi: https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl win-64: + - conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-h4c7d964_0.conda - conda: https://prefix.dev/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + - conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/iniconfig-2.3.0-pyhd8ed1ab_0.conda - conda: https://prefix.dev/conda-forge/noarch/m2-msys2-runtime-3.6.11.4-ha3ae583_11.conda @@ -357,6 +375,7 @@ environments: - conda: https://prefix.dev/conda-forge/noarch/pluggy-1.6.0-pyhf9edf01_1.conda - conda: https://prefix.dev/conda-forge/noarch/pygments-2.21.0-pyhcf101f3_0.conda - conda: https://prefix.dev/conda-forge/noarch/pytest-9.2.0-pyhc364b38_1.conda + - conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda - conda: https://prefix.dev/conda-forge/noarch/setuptools-81.0.0-pyh332efcf_0.conda - conda: https://prefix.dev/conda-forge/noarch/tomli-2.5.0-pyh5ded981_0.conda @@ -383,6 +402,7 @@ environments: - conda: https://prefix.dev/conda-forge/win-64/libzlib-1.3.2-hfd05255_3.conda - conda: https://prefix.dev/conda-forge/win-64/m2-conda-epoch-20261029-0_x86_64.conda - conda: https://prefix.dev/conda-forge/win-64/openssl-3.6.5-hf411b9b_0.conda + - conda: https://prefix.dev/conda-forge/win-64/py-rattler-0.29.0-py311h5fa805c_1.conda - conda: https://prefix.dev/conda-forge/win-64/python-3.14.7-h53f6dd8_106_cp314.conda - conda: https://prefix.dev/conda-forge/win-64/pyyaml-6.0.3-py314h9aa99d3_4.conda - conda: https://prefix.dev/conda-forge/win-64/rattler-build-0.81.0-h9092e4c_1.conda @@ -891,6 +911,29 @@ packages: run_exports: {} size: 152126 timestamp: 1790866799280 +- conda: https://prefix.dev/conda-forge/linux-64/py-rattler-0.29.0-py311hc91d8b8_1.conda + noarch: python + sha256: 43eb93394a73dd06e89fd1e28de865d33290095fe1844e9287bc72c7cd4b8b8f + md5: f8fbe5b0a080466fbf2170db0e965733 + depends: + - python + - __glibc >=2.17,<3.0.a0 + - libgcc >=15 + - openssl >=3.5.9,<4.0a0 + - _python_abi3_support 1.* + - cpython >=3.11 + constrains: + - __glibc >=2.17 + extra_depends: + networkx: + - networkx + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/py-rattler?source=hash-mapping + run_exports: {} + size: 15589030 + timestamp: 1795333003947 - conda: https://prefix.dev/conda-forge/linux-64/python-3.14.7-hcd007b5_106_cp314.conda build_number: 106 sha256: 4cd05407d6b07d00fd5b6cc78bd2f60ae5e21f777eb26ead82be2e3751c610a1 @@ -1487,6 +1530,28 @@ packages: run_exports: {} size: 155583 timestamp: 1790866789930 +- conda: https://prefix.dev/conda-forge/linux-aarch64/py-rattler-0.29.0-py311h40f29f8_1.conda + noarch: python + sha256: 6d5a05e77344802bd6b817b144e2dd0dcec40b673fc0221f9fd6151c920cf217 + md5: b2854f6165b49cd6dae8088c637d649c + depends: + - python + - libgcc >=15 + - _python_abi3_support 1.* + - cpython >=3.11 + - openssl >=3.5.9,<4.0a0 + constrains: + - __glibc >=2.17 + extra_depends: + networkx: + - networkx + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/py-rattler?source=hash-mapping + run_exports: {} + size: 15136107 + timestamp: 1795333007205 - conda: https://prefix.dev/conda-forge/linux-aarch64/python-3.14.7-hbec3b18_106_cp314.conda build_number: 106 sha256: 39af053b358d0a6d53549c8cb7fa33b03da4f8a39e966e12a84d1235bdc7023f @@ -1636,6 +1701,18 @@ packages: - zstd >=1.5.7,<1.6.0a0 size: 615477 timestamp: 1786599613561 +- conda: https://prefix.dev/conda-forge/noarch/_python_abi3_support-1.0-hd8ed1ab_3.conda + sha256: 2a7204314663eeda5dec482a956f0e2eaf289bd5b9953eaaaad0e81aa64638f2 + md5: 3845f3d75991bae0fb90884662f4327c + depends: + - cpython + - python-gil + license: MIT + license_family: MIT + purls: [] + run_exports: {} + size: 8144 + timestamp: 1784221492234 - conda: https://prefix.dev/conda-forge/noarch/ca-certificates-2026.7.22-h4c7d964_0.conda sha256: 95e8e74062a5fe5f870ac8c90302b6e89945165fdaed7810606e84ddee6aac12 md5: e27d2ac27b096dc51fedfcf775a53f9b @@ -1668,6 +1745,18 @@ packages: run_exports: {} size: 27011 timestamp: 1733218222191 +- conda: https://prefix.dev/conda-forge/noarch/cpython-3.14.10-py314hd8ed1ab_101.conda + noarch: generic + sha256: aed178a6fdfae8c8abd2e3bcc2b16c1f05b84ca9ff95e76a7ff7a1df04ad80f0 + md5: 784c8f2fbce938e5f7e5bb9907826f06 + depends: + - python >=3.14,<3.15.0a0 + - python_abi * *_cp314 + license: Python-2.0 + purls: [] + run_exports: {} + size: 51726 + timestamp: 1795751094839 - conda: https://prefix.dev/conda-forge/noarch/exceptiongroup-1.3.1-pyhd8ed1ab_0.conda sha256: ee6cf346d017d954255bbcbdb424cddea4d14e4ed7e9813e429db1d795d01144 md5: 8e662bd460bda79b1ea39194e3c4c9ab @@ -1776,6 +1865,17 @@ packages: run_exports: {} size: 326683 timestamp: 1793214631903 +- conda: https://prefix.dev/conda-forge/noarch/python-gil-3.14.10-h4df99d1_101.conda + sha256: 8dd7d5e8a358131cbf19d0e592e34826f29bd3251e184ffe452f9001dbe174f7 + md5: a51727f7e81534fced3c51c8afdea93e + depends: + - cpython 3.14.10.* + - python_abi * *_cp314 + license: Python-2.0 + purls: [] + run_exports: {} + size: 51707 + timestamp: 1795751099396 - conda: https://prefix.dev/conda-forge/noarch/python_abi-3.14-9_cp314.conda build_number: 9 sha256: e7f8e965bbfb98e08feb2365cacdad8bb218fa5b5a0a2752f747287f425f213c @@ -2183,6 +2283,27 @@ packages: - openssl >=3.6.5,<4.0a0 size: 2786968 timestamp: 1791099439455 +- conda: https://prefix.dev/conda-forge/osx-64/py-rattler-0.29.0-py311h85c30bf_1.conda + noarch: python + sha256: 8117b8dae94c9bd656c6f947a633523eb97a9c875a97f266dd753b5636d42539 + md5: ef0edde73915aacda9cbf275ed18c44c + depends: + - python + - __osx >=11.0 + - _python_abi3_support 1.* + - cpython >=3.11 + constrains: + - __osx >=11.0 + extra_depends: + networkx: + - networkx + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/py-rattler?source=hash-mapping + run_exports: {} + size: 15186354 + timestamp: 1795333164314 - conda: https://prefix.dev/conda-forge/osx-64/python-3.14.7-hafa0b4b_106_cp314.conda build_number: 106 sha256: 74e72b101d4985b9919fcf01fec55ff9c82e862377d6be23b99bfe5562ffc207 @@ -2672,6 +2793,27 @@ packages: - openssl >=3.6.5,<4.0a0 size: 3111573 timestamp: 1791097959641 +- conda: https://prefix.dev/conda-forge/osx-arm64/py-rattler-0.29.0-py311h1e0e963_1.conda + noarch: python + sha256: d26f6f01bc6059250c44f23b698f5884ccb2821d8d7449232389ae6abd7cf479 + md5: 7d4eb00dd6581e87899556b8517eadef + depends: + - python + - __osx >=11.0 + - _python_abi3_support 1.* + - cpython >=3.11 + constrains: + - __osx >=11.0 + extra_depends: + networkx: + - networkx + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/py-rattler?source=hash-mapping + run_exports: {} + size: 13760454 + timestamp: 1795333028596 - conda: https://prefix.dev/conda-forge/osx-arm64/python-3.14.7-h0ae1c2c_106_cp314.conda build_number: 106 sha256: 5ffc8349ca089ec5ac39ad36a095323ad177ebe05cbfc690c1e135560cfd68b7 @@ -3122,6 +3264,27 @@ packages: - openssl >=3.6.5,<4.0a0 size: 9402647 timestamp: 1791099870810 +- conda: https://prefix.dev/conda-forge/win-64/py-rattler-0.29.0-py311h5fa805c_1.conda + noarch: python + sha256: be7c526dfe16471e23404fa404032183003c877abf895721d8e60439fd628221 + md5: 3d0c0dd0c49ad73cb47654368993a30b + depends: + - python + - vc >=14.3,<15 + - vc14_runtime >=14.44.35208 + - ucrt >=10.0.20348.0 + - _python_abi3_support 1.* + - cpython >=3.11 + extra_depends: + networkx: + - networkx + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/py-rattler?source=hash-mapping + run_exports: {} + size: 17128341 + timestamp: 1795332988398 - conda: https://prefix.dev/conda-forge/win-64/python-3.14.7-h53f6dd8_106_cp314.conda build_number: 106 sha256: 9fdcb8a5018d91a22484e67ac6c5ae9116f082f953328f43ed4421418740dfb1 diff --git a/pixi.toml b/pixi.toml index e1935208d..0329e5f4b 100644 --- a/pixi.toml +++ b/pixi.toml @@ -25,6 +25,8 @@ pyyaml = ">=6.0.3,<7" # Some git repos need git-lfs, see https://github.com/RoboStack/ros-jazzy/issues/118 git-lfs = ">=3.8.1,<4" pytest = ">=9.2.0,<10" +# conda channels and package archives in the tools (repodata, versions, downloads) +py-rattler = ">=0.29.0,<0.30" # gh for the workflows: one version everywhere (the runner's is not on PATH on Windows) gh = ">=2.106.0,<3" # built and published by vinca-rs's release workflow @@ -46,5 +48,5 @@ vinca = { git = "https://github.com/RoboStack/vinca.git", rev = "74d1e856d5b00c0 rs = { cmd = "python tools/robostack.py", description = "Run a task for one distribution: `pixi run rs ` (generate-recipes, build, build-one, check-patches, check-deps, create-snapshot, render-pinning, sort, ...)." } sort = { cmd = "sh -lc 'vinca-sort-vinca-lists $@ shared/vinca.yaml && vinca-sort-yaml-keys $@ shared/robostack.yaml shared/pkg_additional_info.yaml && for d in distros/*/; do [ -f $d/vinca.yaml ] || continue; (cd $d && vinca-sort-vinca-lists $@ vinca.yaml && vinca-sort-yaml-keys $@ pkg_additional_info.yaml rosdistro_additional_recipes.yaml) || exit 1; done' --", description = "Sort the YAML files of all distributions (`--check` to only check)." } test = { cmd = "python -m pytest tools/tests", description = "Unit tests of the repository tooling (tools/tests)." } -abi-check = { cmd = "pixi exec -s python=3.14 -s zstandard -s pyyaml -s pyelftools python tools/abi_check.py", description = "Compare the ABI of package builds with libabigail (Linux only): `pixi run abi-check --distro jazzy --latest-pairs 30`, `--old a.conda --new b.conda`, or `--pr-builds ` (a pull request's builds against the released ones)." } +abi-check = { cmd = "pixi exec -s python=3.14 -s py-rattler -s pyyaml -s pyelftools python tools/abi_check.py", description = "Compare the ABI of package builds with libabigail (Linux only): `pixi run abi-check --distro jazzy --latest-pairs 30`, `--old a.conda --new b.conda`, or `--pr-builds ` (a pull request's builds against the released ones)." } render-pinning = { cmd = "sh -lc 'for d in distros/*/; do [ -f $d/vinca.yaml ] || continue; python tools/robostack.py $(basename $d) render-pinning || exit 1; done'", description = "Regenerate every distribution's conda_build_config.yaml from shared/pinning and its distro.yaml." } diff --git a/tools/abi_check.py b/tools/abi_check.py index 20a51ff05..235564675 100644 --- a/tools/abi_check.py +++ b/tools/abi_check.py @@ -30,21 +30,20 @@ from __future__ import annotations import argparse -import io +import asyncio import re import json import os import shutil import subprocess import sys -import tarfile import tempfile -import urllib.error -import urllib.request -import zipfile from pathlib import Path -import zstandard +import rattler +from rattler.package_streaming import download_and_extract, download_to_path, extract + +from channel_repodata import channel_records as _channel_records # abidiff exit status bits (libabigail's abidiff_status) ABI_ERROR = 1 @@ -53,39 +52,15 @@ ABI_INCOMPATIBLE_CHANGE = 8 -def _open(url: str): - return urllib.request.urlopen(urllib.request.Request(url, headers={"User-Agent": "robostack-abi-check"}), timeout=300) - - -def extract_conda(path: Path, dest: Path) -> None: - """Unpack a .conda (zip with zstd-compressed tarballs) or .tar.bz2 package.""" - dest.mkdir(parents=True, exist_ok=True) - if path.suffix == ".conda": - with zipfile.ZipFile(path) as z: - for name in z.namelist(): - if name.startswith("pkg-") and name.endswith(".tar.zst"): - data = zstandard.ZstdDecompressor().stream_reader(io.BytesIO(z.read(name))) - with tarfile.open(fileobj=data, mode="r|") as tar: - tar.extractall(dest, filter="data") - else: - with tarfile.open(path, "r:bz2") as tar: - tar.extractall(dest, filter="data") +def read_index(path: Path) -> dict: + """The repodata record of a package file (its info/index.json).""" + return json.loads(asyncio.run(rattler.RepoDataRecord.from_package_archive(path)).to_json()) -def read_index(path: Path) -> dict: - """info/index.json of a package.""" - if path.suffix == ".conda": - with zipfile.ZipFile(path) as z: - name = next(n for n in z.namelist() if n.startswith("info-") and n.endswith(".tar.zst")) - data = zstandard.ZstdDecompressor().stream_reader(io.BytesIO(z.read(name))) - with tarfile.open(fileobj=data, mode="r|") as tar: - for member in tar: - if member.name == "info/index.json": - return json.load(tar.extractfile(member)) - else: - with tarfile.open(path, "r:bz2") as tar: - return json.load(tar.extractfile("info/index.json")) - raise ValueError(f"{path} has no info/index.json") +def channel_records(channel: str, platform: str) -> list[dict]: + """The repodata records of the channel for the platform (none when it has no + packages for it).""" + return _channel_records(channel, platform) or [] def libraries(prefix: Path) -> dict[str, Path]: @@ -125,8 +100,8 @@ def classify(rc: int, report: str) -> str: def compare(old_pkg: Path, new_pkg: Path, work: Path) -> dict: a, b = work / "old", work / "new" shutil.rmtree(work, ignore_errors=True) - extract_conda(old_pkg, a) - extract_conda(new_pkg, b) + extract(old_pkg, a) + extract(new_pkg, b) old_libs, new_libs = libraries(a), libraries(b) result = {"libraries": {}, "removed_libraries": sorted(set(old_libs) - set(new_libs)), "headers": header_changes(a, b)} @@ -225,10 +200,6 @@ def short_name(name: str, distro: str) -> str | None: return None -def _version_key(v: str): - return [int(p) if p.isdigit() else 0 for p in v.replace("-", ".").split(".")] - - def _belongs_to(rec: dict, distro: str) -> bool: """A record of this distribution: ros--* names, or ros2-* builds pinned to its mutex (a channel such as the test channel can hold several distributions).""" @@ -248,20 +219,12 @@ def released(channels: str | list[str], platform: str, distro: str) -> dict[str, empty compatibility packages are left out.""" builds: dict[str, dict[str, list[dict]]] = {} for channel in [channels] if isinstance(channels, str) else channels: - try: - with _open(f"{channel.rstrip('/')}/{platform}/repodata.json") as r: - data = json.load(r) - except urllib.error.HTTPError as error: - if error.code == 404: # no packages for this platform there - continue - raise - records = list(data.get("packages", {}).items()) + list(data.get("packages.conda", {}).items()) - for filename, rec in records: + for rec in channel_records(channel, platform): short = short_name(rec["name"], distro) if short is None or _is_compatibility_package(rec) or not _belongs_to(rec, distro): continue builds.setdefault(short, {}).setdefault(rec["version"], []).append( - {"file": filename, "channel": channel, **rec}) + {**rec, "file": rec["fn"], "channel": channel}) by_name: dict[str, dict[str, dict]] = {} for short, versions in builds.items(): for version, recs in versions.items(): @@ -284,7 +247,7 @@ def python_abi(rec): def newest(versions: dict[str, dict]) -> dict: - return versions[max(versions, key=_version_key)] + return versions[max(versions, key=rattler.Version)] def latest_pairs(channel: str, platform: str, count: int, distro: str) -> list[tuple[str, dict, dict]]: @@ -294,7 +257,7 @@ def latest_pairs(channel: str, platform: str, count: int, distro: str) -> list[t for short, versions in sorted(released(channel, platform, distro).items()): if len(versions) < 2: continue - ordered = sorted(versions, key=_version_key) + ordered = sorted(versions, key=rattler.Version) pairs.append((short, versions[ordered[-2]], versions[ordered[-1]])) # most recently uploaded new versions first pairs.sort(key=lambda p: p[2].get("timestamp", 0), reverse=True) @@ -362,11 +325,10 @@ def channel_for(distro: str) -> list[str]: return extra + [rs.repodata_url(distro)] -def download(channel: str, platform: str, filename: str, dest: Path) -> Path: - target = dest / filename +def download(rec: dict, dest: Path) -> Path: + target = dest / rec["file"] if not target.exists(): - with _open(f"{channel.rstrip('/')}/{platform}/{filename}") as r, open(target, "wb") as f: - shutil.copyfileobj(r, f) + asyncio.run(download_to_path(rattler.Client(), rec["url"], target)) return target @@ -374,19 +336,16 @@ def download(channel: str, platform: str, filename: str, dest: Path) -> Path: MAX_DEPENDENTS_TO_INSPECT = 40 -def linking_dependents(channel, platform, by_name, candidates, sonames, downloads: Path, tmp: Path) -> dict: +def linking_dependents(by_name, candidates, sonames, tmp: Path) -> dict: """Which of the dependents link to one of the SONAMEs (and so need a rebuild); metapackages, Python packages and configurations don't.""" if len(candidates) > MAX_DEPENDENTS_TO_INSPECT: return {"rebuild": candidates, "checked": False} rebuild = [] for name in candidates: - rec = newest(by_name[name]) - pkg = download(rec["channel"], platform, rec["file"], downloads) target = tmp / "dependent" shutil.rmtree(target, ignore_errors=True) - extract_conda(pkg, target) - pkg.unlink(missing_ok=True) + asyncio.run(download_and_extract(rattler.Client(), newest(by_name[name])["url"], target)) if needed(target) & set(sonames): rebuild.append(name) return {"rebuild": rebuild, "checked": True, "candidates": len(candidates)} @@ -426,14 +385,14 @@ def check_pr_builds(pr_dir: Path, channel: str, platform: str, distro: str, tmp: if old["file"] == pkg.name: continue print(f"{short}: {old['version']} (build {old.get('build_number', 0)}) -> {index['version']} (PR)", flush=True) - old_pkg = download(old["channel"], platform, old["file"], downloads) + old_pkg = download(old, downloads) res = compare(old_pkg, pkg, tmp / "work") old_pkg.unlink(missing_ok=True) res.update(old=f"{old['version']} (build {old.get('build_number', 0)})", new=index["version"], pins=pin_changes(old, index, distro)) if res["broken_sonames"]: res["dependents"] = linking_dependents( - channel, platform, by_name, dependents(by_name, short, distro), res["broken_sonames"], downloads, tmp + by_name, dependents(by_name, short, distro), res["broken_sonames"], tmp ) results[short] = res print(f" -> {res['verdict']}", flush=True) @@ -585,8 +544,8 @@ def main() -> int: downloads.mkdir() for name, old, new in latest_pairs(channel, args.platform, args.latest_pairs, args.distro): print(f"{name}: {old['version']} -> {new['version']}", flush=True) - old_pkg = download(old["channel"], args.platform, old["file"], downloads) - new_pkg = download(new["channel"], args.platform, new["file"], downloads) + old_pkg = download(old, downloads) + new_pkg = download(new, downloads) res = compare(old_pkg, new_pkg, tmp / "work") res.update(old=old["version"], new=new["version"]) results[name] = res diff --git a/tools/channel_repodata.py b/tools/channel_repodata.py new file mode 100644 index 000000000..da7742683 --- /dev/null +++ b/tools/channel_repodata.py @@ -0,0 +1,30 @@ +"""The repodata records of a conda channel, fetched with py-rattler (sharded repodata +where the channel has it, compressed and cached otherwise).""" + +from __future__ import annotations + +import asyncio +import json +import tempfile +from pathlib import Path + +import rattler +from rattler.exceptions import FetchRepoDataError + +REPODATA_CACHE = Path(tempfile.gettempdir()) / "robostack-repodata" + + +def channel_records(channel: str, platform: str) -> list[dict] | None: + """The records of the channel's platform subdir (each with its "fn" and "url"), + or None when the channel has no such subdir; network failures raise.""" + try: + [repodata] = asyncio.run(rattler.fetch_repo_data( + channels=[rattler.Channel(channel)], platforms=[rattler.Subdir(platform)], + cache_path=REPODATA_CACHE, callback=None, + )) + except FetchRepoDataError as error: + # network failures raise the same type + if not str(error).startswith("repodata not found"): + raise + return None + return [json.loads(record.to_json()) for record in repodata.load_all_records()] diff --git a/tools/check_dependency_compat.py b/tools/check_dependency_compat.py index 55162838e..d535213a8 100644 --- a/tools/check_dependency_compat.py +++ b/tools/check_dependency_compat.py @@ -47,6 +47,8 @@ from urllib.request import Request, urlopen import ruamel.yaml +from rattler import Version, VersionSpec +from rattler.exceptions import InvalidVersionError, InvalidVersionSpecError ROS_PREFIXES = ("ros-", "ros2-") DEFAULT_CHANNELS = ["https://repo.prefix.dev/conda-forge"] @@ -690,7 +692,7 @@ def report_conflicts( if any(len(spec.split()) > 1 for _, spec in specs): print(" note: the spec is version-restricted (dummy package in pkg_additional_info.yaml?);" " a newer conda-forge version may already be built against the pinned libraries.") - glibc_needs = sorted({m.group(1) for m in _GLIBC_NEED_RE.finditer(block)}, key=version_tuple) + glibc_needs = sorted({m.group(1) for m in _GLIBC_NEED_RE.finditer(block)}, key=Version) if (glibc_needs and host_names is not None and normalized(culprit) not in host_names and args.platform.startswith("linux") and solver.solve(f"glibc-{culprit}", pins, specs, glibc=glibc_needs[-1])[0]): @@ -824,74 +826,31 @@ def report_migrations( # ----------------------------------------------------------------------- stale -_VERSION_PART_RE = re.compile(r"^(\d+)(.*)$") - - -def version_tuple(version: str) -> tuple[int, ...]: - parts: list[int] = [] - for part in version.strip().split("."): - match = _VERSION_PART_RE.match(part) - if not match: - break - parts.append(int(match.group(1))) - if match.group(2): # pre-release suffix such as '0a0': stop here - break - return tuple(parts) - - -def _pad(t: tuple[int, ...], n: int) -> tuple[int, ...]: - return t + (0,) * (n - len(t)) - - -def _cmp(a: tuple[int, ...], b: tuple[int, ...]) -> int: - n = max(len(a), len(b)) - a, b = _pad(a, n), _pad(b, n) - return (a > b) - (a < b) - - -def pin_range(pin_version: str) -> tuple[tuple[int, ...], tuple[int, ...], bool]: - """Return (lowest, upper_exclusive, exact) for a pin such as '1.90', '7.35.1.*' or '11.*'.""" - text = pin_version.strip() - exact = not text.endswith(".*") and "*" not in text - prefix = version_tuple(text.rstrip("*").rstrip(".")) - if not prefix: - return (0,), (10**9,), False - upper = prefix[:-1] + (prefix[-1] + 1,) - return prefix, upper, exact +_SPEC_VERSION_RE = re.compile(r"\d[0-9A-Za-z_.+!]*") def constraint_compatible(constraint: str, pin_version: str) -> bool: - """Whether some version can satisfy both the dependency constraint and the pin.""" - low, upper_excl, _ = pin_range(pin_version) - constraint = constraint.strip() - if constraint in ("", "*"): + """Whether some version can satisfy both the dependency constraint and the pin + ('1.90', '1.90.*': every version starting with 1.90).""" + pin = pin_version.strip().rstrip("*").rstrip(".") + if not pin[:1].isdigit(): return True - if "|" in constraint: - return any(constraint_compatible(part, pin_version) for part in constraint.split("|")) - for clause in [c.strip() for c in constraint.split(",") if c.strip()]: - if clause.startswith(">="): - if _cmp(upper_excl, version_tuple(clause[2:])) <= 0: - return False - elif clause.startswith(">"): - if _cmp(upper_excl, version_tuple(clause[1:])) <= 0: - return False - elif clause.startswith("<="): - if _cmp(low, version_tuple(clause[2:])) > 0: - return False - elif clause.startswith("<"): - if _cmp(low, version_tuple(clause[1:])) >= 0: - return False - elif clause.startswith("!="): + try: + spec = VersionSpec(constraint.strip() or "*") + pinned = VersionSpec(f"{pin}.*") + except InvalidVersionSpecError: + return True + # rattler can't intersect specs; if the two overlap, the lowest version they share + # is the pin's, a bound of the constraint, or (for a > bound) just above one + bounds = [v.rstrip(".") for v in _SPEC_VERSION_RE.findall(constraint)] + for candidate in [pin, *bounds, *(f"{v}.1" for v in bounds)]: + try: + version = Version(candidate) + except InvalidVersionError: continue - else: - other = clause[2:] if clause.startswith("==") else clause - other_low, other_upper, _ = pin_range(other) - n = max(len(low), len(other_low)) - a, b = _pad(low, n), _pad(other_low, n) - k = min(len(low), len(other_low)) - if a[:k] != b[:k]: - return False - return True + if spec.matches(version) and pinned.matches(version): + return True + return False _CBC_KEY_RE = re.compile(r"^([A-Za-z0-9_.-]+):\s*(?:#\s*\[(.+?)\])?\s*$") diff --git a/tools/maintenance.py b/tools/maintenance.py index 7e737d5ba..8268a28d7 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -107,23 +107,17 @@ def fold(title: str, body: list[str]) -> None: def released_builds(distro: str) -> dict[str, int] | None: """Highest build number of every package on the distribution's channel (all platforms), or None when the channel can't be read.""" - import urllib.error - import urllib.request + from channel_repodata import channel_records base = rs.repodata_url(distro) builds: dict[str, int] = {} read = False for subdir in REPODATA_SUBDIRS: - try: - request = urllib.request.Request(f"{base}/{subdir}/repodata.json", headers={"User-Agent": "robostack-bot"}) - with urllib.request.urlopen(request, timeout=300) as response: - data = json.load(response) - except urllib.error.HTTPError as error: - if error.code == 404: - continue - raise + records = channel_records(base, subdir) + if records is None: + continue read = True - for record in [*data.get("packages", {}).values(), *data.get("packages.conda", {}).values()]: + for record in records: builds[record["name"]] = max(builds.get(record["name"], 0), int(record.get("build_number", 0))) return builds if read else None @@ -359,11 +353,12 @@ def rosdistro_syncs() -> list[dict]: def _newer(a: str, b: str) -> bool: - from packaging.version import InvalidVersion, Version + from rattler import Version + from rattler.exceptions import InvalidVersionError try: return Version(a) > Version(b) - except InvalidVersion: + except InvalidVersionError: return False diff --git a/tools/package_tests.py b/tools/package_tests.py index 675be12fb..d021184c7 100644 --- a/tools/package_tests.py +++ b/tools/package_tests.py @@ -21,6 +21,7 @@ from __future__ import annotations import argparse +import asyncio import json import os import re @@ -30,9 +31,12 @@ import sys import tempfile import time -import urllib.request from pathlib import Path +import rattler +from rattler.package_streaming import download_to_path +from channel_repodata import channel_records + sys.path.insert(0, str(Path(__file__).resolve().parent)) import robostack as rs @@ -41,9 +45,6 @@ REPORT_TITLE = "Package tests" # the issues of before, one per distribution: closed in favour of the one issue OLD_TITLE = re.compile(r"^\S+: package tests$") -# packages.prefix.dev (where repo.prefix.dev redirects) answers Python-urllib's default -# User-Agent with 403 Forbidden -USER_AGENT = "robostack-package-tests" MAX_ISSUE_BODY = 60000 # GitHub's limit is 65536 characters LOG_TAIL = 60 # lines of a failed test's output kept in the results # a package's tests that run longer are stopped and reported as failed: a test that hangs @@ -65,44 +66,21 @@ def tested_packages(distro: str) -> list[str]: return sorted(names) -def request(url: str) -> urllib.request.Request: - return urllib.request.Request(url, headers={"User-Agent": USER_AGENT}) - - def download(url: str, path: Path) -> None: - with urllib.request.urlopen(request(url), timeout=600) as response, path.open("wb") as fh: - shutil.copyfileobj(response, fh) + asyncio.run(download_to_path(rattler.Client(), url, path)) def free_space(path: str) -> str: return f"{shutil.disk_usage(path).free / 2**30:.1f} GiB free" -def fetch_json(url: str, attempts: int = 3) -> dict: - for attempt in range(1, attempts + 1): - try: - with urllib.request.urlopen(request(url), timeout=120) as response: - return json.load(response) - except urllib.error.HTTPError as error: - if error.code == 404: - return {} - if attempt == attempts: - raise - except OSError: - if attempt == attempts: - raise - time.sleep(10 * attempt) - return {} - - -def newest_builds(repodata: dict, names: list[str]) -> list[dict]: +def newest_builds(channel_records: list[dict], names: list[str]) -> list[dict]: """For each name, every variant of its newest build: the records with the version and build number of the newest upload (one per build string, e.g. per Python).""" records: dict[str, list[dict]] = {} - for section in ("packages", "packages.conda"): - for filename, record in (repodata.get(section) or {}).items(): - if record.get("name") in names: - records.setdefault(record["name"], []).append({**record, "fn": filename}) + for record in channel_records: + if record.get("name") in names: + records.setdefault(record["name"], []).append(record) selected = [] for name in sorted(records): newest = max(records[name], key=lambda r: (r.get("build_number", 0), r.get("timestamp", 0))) @@ -123,10 +101,9 @@ def select(distro: str, platform: str) -> list[dict]: base = rs.repodata_url(distro) selected = [] for subdir in (platform, "noarch"): - repodata = fetch_json(f"{base}/{subdir}/repodata.json") - for record in newest_builds(repodata, names): + for record in newest_builds(channel_records(base, subdir) or [], names): selected.append({"name": record["name"], "version": record["version"], "build": record["build"], - "subdir": subdir, "url": f"{base}/{subdir}/{record['fn']}"}) + "subdir": subdir, "url": record["url"]}) return selected @@ -196,7 +173,7 @@ def run(distro: str, platform: str, results: Path, only: list[str] | None = None print(log, "\n❌ failed, trying again", flush=True) ok, log, count = test_package(distro, package_file) flaky = ok - except OSError as error: + except (OSError, RuntimeError) as error: # rattler's download errors are RuntimeErrors ok, log, count, flaky = False, f"download failed: {error}", 0, False finally: package_file.unlink(missing_ok=True) diff --git a/tools/python_abi_audit.py b/tools/python_abi_audit.py index 3106729ee..8f400a4b2 100644 --- a/tools/python_abi_audit.py +++ b/tools/python_abi_audit.py @@ -27,97 +27,34 @@ from __future__ import annotations import argparse -import io +import asyncio import json import re import sys -import tarfile -import urllib.request -import zipfile -from concurrent.futures import ThreadPoolExecutor from pathlib import Path +import rattler import yaml -import zstandard +from rattler.package_streaming import PackageArchive +from channel_repodata import channel_records -UA = {"User-Agent": "robostack-python-audit"} SITE_PACKAGES = re.compile(r"(^|/)(lib/python[0-9.]*/site-packages|Lib/site-packages)/") EXTENSION = re.compile(r"\.cpython-[^/]*\.(so|dylib)$|\.pyd$") +CONCURRENCY = 16 -class RangeReader(io.RawIOBase): - """A remote file read with HTTP range requests (zipfile only needs the end and - the info-*.tar.zst member of a .conda).""" - - def __init__(self, url: str): - with urllib.request.urlopen(urllib.request.Request(url, headers={**UA, "Range": "bytes=0-0"}), - timeout=120) as r: - self.url = r.url - content_range = r.headers.get("Content-Range") - if r.status != 206 or not content_range: - raise OSError(f"{url}: no range support") - self.size = int(content_range.split("/")[1]) - self.pos = 0 - - def readable(self) -> bool: - return True - - def seekable(self) -> bool: - return True - - def tell(self) -> int: - return self.pos - - def seek(self, offset: int, whence: int = 0) -> int: - self.pos = {0: offset, 1: self.pos + offset, 2: self.size + offset}[whence] - return self.pos - - def readinto(self, b) -> int: - n = min(len(b), self.size - self.pos) - if n <= 0: - return 0 - headers = {**UA, "Range": f"bytes={self.pos}-{self.pos + n - 1}"} - with urllib.request.urlopen(urllib.request.Request(self.url, headers=headers), timeout=300) as r: - data = r.read() - b[: len(data)] = data - self.pos += len(data) - return len(data) - - -def open_conda(url: str, whole: bool) -> zipfile.ZipFile: - if not whole: - try: - return zipfile.ZipFile(io.BufferedReader(RangeReader(url), buffer_size=1 << 16)) - except OSError: - pass - with urllib.request.urlopen(urllib.request.Request(url, headers=UA), timeout=600) as r: - return zipfile.ZipFile(io.BytesIO(r.read())) - - -def members(z: zipfile.ZipFile, prefix: str): - name = next(n for n in z.namelist() if n.startswith(prefix)) - stream = zstandard.ZstdDecompressor().stream_reader(z.open(name)) - with tarfile.open(fileobj=stream, mode="r|") as tar: - for member in tar: - if member.isfile(): - yield member, tar.extractfile(member) - - -def inspect(url: str, elf: bool) -> dict: - """Classify by info/paths.json; with *elf*, a package without Python files is - downloaded whole and its ELF files are searched for libpython (embedding).""" +async def inspect(client: rattler.Client, url: str, elf: bool) -> dict: + """Classify by info/paths.json (read with range requests); with *elf*, the ELF + files of a package without Python files are searched for libpython (embedding).""" for attempt in range(3): try: - z = open_conda(url, whole=False) - paths = [] - for member, f in members(z, "info-"): - if member.name == "info/paths.json": - paths = [p["_path"] for p in json.load(f)["paths"]] - break + archive = await PackageArchive.from_url(client, url) + paths = [entry.relative_path.as_posix() for entry in (await archive.paths_json()).paths] result = classify(paths, []) if elf and result["content"] == "none": - linked = [member.name for member, f in members(open_conda(url, whole=True), "pkg-") - if (data := f.read())[:4] == b"\x7fELF" and b"libpython3." in data] + linked = [entry.name async for entry in archive.stream("pkg") + if entry.is_file and (data := await entry.read())[:4] == b"\x7fELF" + and b"libpython3." in data] result = classify(paths, linked) return result except Exception as err: # noqa: BLE001 - network or archive trouble: retried, then reported @@ -125,6 +62,17 @@ def inspect(url: str, elf: bool) -> dict: return {"content": "error", "error": str(error)} +async def inspect_all(published: dict[str, dict], elf: bool) -> dict[str, dict]: + client = rattler.Client() + limit = asyncio.Semaphore(CONCURRENCY) + + async def one(name: str, record: dict) -> tuple[str, dict]: + async with limit: + return name, {"file": record["fn"], **await inspect(client, record["url"], elf)} + + return dict(await asyncio.gather(*(one(name, record) for name, record in published.items()))) + + def classify(paths: list[str], linked: list[str]) -> dict: site = [p for p in paths if SITE_PACKAGES.search(p)] native = [p for p in paths if EXTENSION.search(p)] @@ -153,14 +101,13 @@ def recipes_needing_python(recipes: Path) -> dict[str, bool]: return result -def newest_builds(repodata: dict) -> dict[str, str]: - records = {**repodata.get("packages", {}), **repodata.get("packages.conda", {})} +def newest_builds(records: list[dict]) -> dict[str, dict]: newest: dict[str, tuple] = {} - for fn, rec in records.items(): + for rec in records: key = (rec["build_number"], rec.get("timestamp", 0)) - if rec["name"].startswith("ros2-") and key > newest.get(rec["name"], ((-1, 0), ""))[0]: - newest[rec["name"]] = (key, fn) - return {name: fn for name, (_, fn) in newest.items()} + if rec["name"].startswith("ros2-") and key > newest.get(rec["name"], ((-1, 0), None))[0]: + newest[rec["name"]] = (key, rec) + return {name: rec for name, (_, rec) in newest.items()} def main() -> int: @@ -177,17 +124,8 @@ def main() -> int: if not needs: print(f"No ros2-* recipes in {args.recipes}: run generate-recipes first", file=sys.stderr) return 1 - with urllib.request.urlopen(urllib.request.Request(f"{args.channel}/{args.platform}/repodata.json", headers=UA), - timeout=300) as r: - published = newest_builds(json.load(r)) - - names = [n for n in needs if n in published] - def work(name: str) -> tuple[str, dict]: - url = f"{args.channel}/{args.platform}/{published[name]}" - return name, {"file": published[name], **inspect(url, elf=args.elf)} - - with ThreadPoolExecutor(16) as pool: - results = dict(pool.map(work, names)) + published = newest_builds(channel_records(args.channel, args.platform) or []) + results = asyncio.run(inspect_all({n: published[n] for n in needs if n in published}, args.elf)) misses = sorted(n for n, r in results.items() if not needs[n] and r["content"] in ("native", "pure")) unneeded = sorted(n for n, r in results.items() if needs[n] and r["content"] == "none") diff --git a/tools/tests/test_dependency_compat.py b/tools/tests/test_dependency_compat.py new file mode 100644 index 000000000..cd465de99 --- /dev/null +++ b/tools/tests/test_dependency_compat.py @@ -0,0 +1,28 @@ +import pytest + +import abi_check +from check_dependency_compat import constraint_compatible + + +@pytest.mark.parametrize("constraint, pin, compatible", [ + (">=1.88.0,<1.89.0a0", "1.88", True), + (">=1.88.0,<1.89.0a0", "1.90", False), + (">=3.12,<3.13.0a0", "3.12.*", True), + (">=11.2,<12", "11.*", True), + (">=2.0.2,<3", "2", True), + (">1.88,<1.89", "1.88", True), + ("<1.88.0a0", "1.88", False), + (">=1.86|>=2", "2", True), + ("==1.88.1", "1.88", True), + ("==1.88.1", "1.90", False), + ("~=1.88.1", "1.88", True), + ("", "1.88", True), + ("==1.88.1", "gcc", True), +]) +def test_constraint_compatible(constraint, pin, compatible): + assert constraint_compatible(constraint, pin) is compatible + + +def test_newest_orders_conda_versions(): + versions = {v: {"version": v} for v in ("1.10.0", "1.9.2", "1.10.0rc1", "1.2")} + assert abi_check.newest(versions)["version"] == "1.10.0" diff --git a/tools/tests/test_package_tests.py b/tools/tests/test_package_tests.py index 4a18793b3..79e152ce2 100644 --- a/tools/tests/test_package_tests.py +++ b/tools/tests/test_package_tests.py @@ -6,8 +6,8 @@ import package_tests -def record(name, version, build, number, timestamp=0): - return {"name": name, "version": version, "build": build, "build_number": number, "timestamp": timestamp} +def record(fn, name, version, build, number, timestamp=0): + return {"fn": fn, "name": name, "version": version, "build": build, "build_number": number, "timestamp": timestamp} def test_tested_packages_are_the_test_files(tmp_path, monkeypatch): @@ -23,24 +23,22 @@ def test_tested_packages_are_the_test_files(tmp_path, monkeypatch): def test_newest_builds_keeps_every_variant_of_the_newest_build(): - repodata = { - "packages.conda": { - "a-1-py312_25.conda": record("ros2-a", "1", "py312_25", 25, 1), - "a-1-py314_27.conda": record("ros2-a", "1", "py314_27", 27, 2), - "a-1-py313_27.conda": record("ros2-a", "1", "py313_27", 27, 3), - "b-2-h1_3.conda": record("ros2-b", "2", "h1_3", 3), - "c-1-h_1.conda": record("ros2-untested", "1", "h_1", 1), - }, + records = [ + record("a-1-py312_25.conda", "ros2-a", "1", "py312_25", 25, 1), + record("a-1-py314_27.conda", "ros2-a", "1", "py314_27", 27, 2), # the same build in the old format too: the .conda one is tested - "packages": {"a-1-py314_27.tar.bz2": record("ros2-a", "1", "py314_27", 27, 2)}, - } - selected = package_tests.newest_builds(repodata, ["ros2-a", "ros2-b"]) + record("a-1-py314_27.tar.bz2", "ros2-a", "1", "py314_27", 27, 2), + record("a-1-py313_27.conda", "ros2-a", "1", "py313_27", 27, 3), + record("b-2-h1_3.conda", "ros2-b", "2", "h1_3", 3), + record("c-1-h_1.conda", "ros2-untested", "1", "h_1", 1), + ] + selected = package_tests.newest_builds(records, ["ros2-a", "ros2-b"]) assert [(r["name"], r["build"], r["fn"]) for r in selected] == [ ("ros2-a", "py313_27", "a-1-py313_27.conda"), ("ros2-a", "py314_27", "a-1-py314_27.conda"), ("ros2-b", "h1_3", "b-2-h1_3.conda"), ] - assert package_tests.newest_builds({}, ["ros2-a"]) == [] + assert package_tests.newest_builds([], ["ros2-a"]) == [] def test_ran_test_counts_the_tests_rattler_build_ran(): @@ -109,11 +107,6 @@ def gh(args): assert closed == [["api", "-X", "PATCH", "repos/o/r/issues/149", "-f", "state=closed", "-f", "state_reason=not_planned"]] -def test_requests_send_a_user_agent(): - # packages.prefix.dev answers Python-urllib's default User-Agent with 403 - assert package_tests.request("https://repo.prefix.dev/x").get_header("User-agent") == package_tests.USER_AGENT - - def test_a_test_that_hangs_is_stopped_and_failed(monkeypatch): # the test leaves a process behind that ignores SIGTERM and keeps the output open, # like a node the test didn't stop: the whole process group is killed at the timeout diff --git a/tools/tests/test_python_abi_audit.py b/tools/tests/test_python_abi_audit.py index 580f858fd..2ec720d8c 100644 --- a/tools/tests/test_python_abi_audit.py +++ b/tools/tests/test_python_abi_audit.py @@ -22,9 +22,9 @@ def test_recipes_needing_python_reads_host(tmp_path): def test_newest_builds_takes_the_highest_build_number(): - def rec(name, number, timestamp=0): - return {"name": name, "build_number": number, "timestamp": timestamp} + def rec(fn, name, number, timestamp=0): + return {"fn": fn, "name": name, "build_number": number, "timestamp": timestamp} - repodata = {"packages.conda": {"a-1-h_30.conda": rec("ros2-a", 30), "a-1-h_29.conda": rec("ros2-a", 29, 9), - "a-1-g_30.conda": rec("ros2-a", 30, 5), "x.conda": rec("ros-lyrical-a", 31)}} - assert audit.newest_builds(repodata) == {"ros2-a": "a-1-g_30.conda"} + records = [rec("a-1-h_30.conda", "ros2-a", 30), rec("a-1-h_29.conda", "ros2-a", 29, 9), + rec("a-1-g_30.conda", "ros2-a", 30, 5), rec("x.conda", "ros-lyrical-a", 31)] + assert {name: r["fn"] for name, r in audit.newest_builds(records).items()} == {"ros2-a": "a-1-g_30.conda"}