diff --git a/README.md b/README.md index c3825a728..0c89a8e81 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ waiting for the macOS runners; remove them for a full build before merging. | `rebuild ... [... \| all] [--with-dependents]` | maintainers | New builds of ROS packages (dashes or underscores, `ros--` / `ros2-` prefixes accepted) in the given distributions (default: every one that builds them): per-package build numbers in `distros//pkg_additional_info.yaml`, above every released build. `--with-dependents` also rebuilds every package that depends on them (host or run, transitively; vinca's rebuild planner). Opens a PR listing the rebuilt packages. | | `rebuild-dependents` | maintainers | Only as a comment on a pull request: commits the build-number entries the ABI check's comment suggests (its `yaml` blocks per distribution) to the pull request's branch, keeping existing entries' other keys. Pull requests from forks can't be pushed to: the bot replies with the entries to add instead. | | `update-vinca []` | maintainers | Moves the vinca pin in `pixi.toml` to the newest commit of the pinned repository's branch (`robostack-integration` for Tobias-Fischer/vinca, else its default branch) or of ``, runs `pixi lock`, re-renders the pinning and runs `rs check`. The PR links the comparison and lists the vinca commits. Labelled `build:none` (see below). | -| `dependency-report [... \| all]` | maintainers | Runs the dependency check (`check-deps`, linux-64) and keeps one issue per distribution, *``: dependency report* (label `dependency-report`), up to date with the conflicts, notes and conda-forge migration status; the issue is closed when nothing conflicts. Runs weekly (Mondays). | +| `dependency-report [... \| all]` | maintainers | Runs the dependency check (`check-deps`, linux-64) and keeps one issue per distribution, *``: dependency report* (label `dependency-report`), up to date with the conflicts, notes and conda-forge migration status, and its pinning overrides next to conda-forge: the value of the distribution's conda-forge-pinning and the newest version (overrides that can be dropped, keys conda-forge doesn't pin, pins behind), and whether `qt6_main` / `libzenohc` still match conda-forge's newest pyqt6 / its libgz-transport builds (⚠️ when not). Report only: it changes nothing. The issue is closed when nothing conflicts. Runs weekly (Mondays). | | `update-build-timings` | maintainers | Merges the build times the last week's build-branch runs recorded (`rs build-ci`, kept as each job's artifact) into `shared/build_timings/.json` and opens a PR. The build workflows pack each stage's recipes into jobs by these times. Runs weekly (Mondays). Labelled `build:none` (see below). | | `update-pixi` | maintainers | Runs `pixi upgrade`: the newest versions of the tooling's dependencies in `pixi.toml` and `pixi.lock` (rattler-build, rattler-index, gh, pytest, ...), except Python (moved by hand) and requirements that are only an upper bound (`cmake = "<4.0"`: capped on purpose); the vinca pin is `update-vinca`'s. Runs `rs check`; the PR lists the changes as a table (pixi-diff-to-markdown). Runs monthly (on the 1st). Labelled `build:none` (see below). | diff --git a/tools/maintenance.py b/tools/maintenance.py index 3d24ae22b..6b163586a 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -1130,7 +1130,148 @@ def migration_status(output: str) -> str: return m.group(0).strip() if m else "" -def report_issue_body(distro: str, data: dict, migrations: str = "", run_url: str = "") -> str: +# ---------------------------------------------------------------- pinning overrides +# Keys that are not one package's version (or are set together with others): listed, not compared. +OVERRIDE_UNCOMPARED = {"channel_sources", "channel_targets", "python", "is_python_min", "python_impl"} +GZ_TRANSPORT_PLATFORMS = ("linux-64", "linux-aarch64", "osx-64", "osx-arm64", "win-64") + + +def conda_forge_package(name: str, cache: dict) -> dict | None: + """anaconda.org's record of a conda-forge package (latest_version, and its files + with subdir and depends); None if it can't be fetched.""" + import urllib.request + + if name not in cache: + url = f"https://api.anaconda.org/package/conda-forge/{name}" + try: + with urllib.request.urlopen(urllib.request.Request(url, headers={"User-Agent": "robostack-bot"}), + timeout=120) as response: + cache[name] = json.load(response) + except Exception: + cache[name] = None + return cache[name] + + +def effective_overrides(distro: str) -> dict[str, tuple[list[str] | None, str, str]]: + """The pinning overrides that apply to the distribution: {key: (values or None + for a dropped key, "shared" or "distro.yaml", the comment above the shared entry)}.""" + yaml_rt = rs.ruamel_yaml() + shared = yaml_rt.load((rs.SHARED / "pinning" / "overrides.yaml").read_text())["pinning_overrides"] + comments = rs.key_comments(shared) + own = (yaml_rt.load((rs.DISTROS / distro / "distro.yaml").read_text()) or {}).get("pinning_overrides") or {} + + def values(value) -> list[str] | None: + return None if value is None else [str(v) for v in (value if isinstance(value, list) else [value])] + + out = {key: (values(value), "shared", comments.get(key, "")) for key, value in shared.items()} + out.update({key: (values(value), "distro.yaml", "") for key, value in own.items()}) + return out + + +def _matches(pin: str, version: str) -> bool: + """Whether a pin like '3.4' or '6.12.0' covers this version.""" + return version == pin or version.startswith(pin + ".") + + +def coupled_pin_checks(overrides: dict, cache: dict) -> list[str]: + """Pins that have to match another package exactly: qt6_main must be the qt6-main + conda-forge's newest pyqt6 is built for (pyqt6 requires qt6-main X.Y.Z.*), and + libzenohc must have libgz-transport builds (gz-transport 15 is built per zenoh + patch release, none was built for 1.10.0).""" + lines = [] + qt = (overrides.get("qt6_main") or (None,))[0] + pyqt6 = conda_forge_package("pyqt6", cache) + if qt and len(qt) == 1 and pyqt6: + newest = pyqt6.get("latest_version") + wanted = sorted({m.group(1) for f in pyqt6.get("files", []) if f.get("version") == newest + for d in f.get("attrs", {}).get("depends", []) if (m := re.match(r"qt6-main (\S+)\.\*$", d))}) + if wanted: + ok = qt[0] in wanted + lines.append(f"- {'✅' if ok else '⚠️'} `qt6_main` `{qt[0]}`: conda-forge's newest pyqt6 ({newest}) is built " + f"for qt6-main {', '.join(wanted)}" + ("" if ok else ": move the pin to it, or qt packages " + "and pyqt6 can't be installed together.")) + zenoh = (overrides.get("libzenohc") or (None,))[0] + libzenohc, transport = conda_forge_package("libzenohc", cache), conda_forge_package("libgz-transport", cache) + if zenoh and len(zenoh) == 1 and libzenohc and transport: + def platforms(version: str) -> list[str]: + return sorted({f["attrs"].get("subdir") for f in transport.get("files", []) + if any(re.match(rf"libzenohc >={re.escape(version)},", d) for d in f["attrs"].get("depends", []))}) + newest = libzenohc.get("latest_version") + line = f"- `libzenohc` `{zenoh[0]}`" + if newest and _matches(zenoh[0], newest): + line = f"- ✅ {line[2:]}: conda-forge's newest." + elif newest: + have = platforms(newest) + missing = [p for p in GZ_TRANSPORT_PLATFORMS if p not in have] + line = (f"- ⚠️ {line[2:]}: {newest} is out" + ( + f"; libgz-transport is built for it on all {len(GZ_TRANSPORT_PLATFORMS)} platforms, so it can move" + if not missing else f", but libgz-transport has no build for it on {', '.join(missing)} yet: wait") + ".") + lines.append(line) + return lines + + +def override_report(distro: str, cache: dict | None = None) -> list[str]: + """The distribution's pinning overrides next to conda-forge's newest pinning and + newest package versions: overrides that conda-forge has caught up with (can be + dropped), keys conda-forge doesn't pin, and pins behind the newest version (with + the comment saying why), plus the coupled pins (coupled_pin_checks).""" + from vinca import pinning + + cache = {} if cache is None else cache + overrides = effective_overrides(distro) + # what dropping an override gives is the distribution's own conda-forge-pinning; the + # newest one only shows where the next pinning update would take it + current = str(rs.settings(distro).get("conda_forge_pinning_version") or + (yaml.safe_load((rs.SHARED / "pinning" / "conda_forge.yaml").read_text()) or {})["conda_forge_pinning_version"]) + try: + newest_version, url = pinning.get_latest_pinning_distribution() + base = yaml.safe_load(pinning.download_pinning_package(current)[0]) or {} + newest_base = base if newest_version == current else ( + yaml.safe_load(pinning.download_pinning_package(newest_version, artifact_url=url)[0]) or {}) + except Exception as exc: # the report is still useful without this section + return [f"Pinning overrides: could not download conda-forge-pinning ({exc})."] + + def pin(cbc: dict, key: str) -> str | None: + value = cbc.get(key) + return None if value is None else str(value[0]) if isinstance(value, list) and len(value) == 1 else "several values" + + rows, uncompared = [], [] + for key, (values, where, comment) in sorted(overrides.items()): + if values is None: + continue + if key in OVERRIDE_UNCOMPARED or len(values) != 1: + uncompared.append(f"`{key}`") + continue + ours = values[0] + cf, cf_next = pin(base, key), pin(newest_base, key) + info = conda_forge_package(key.replace("_", "-"), cache) + newest = info.get("latest_version") if info else None + if key in ("qt6_main", "libzenohc", "libzenohcxx"): + status = "has to match another package, see below" + elif cf == ours: + status = "same as conda-forge: can be dropped" + elif cf is None: + status = "conda-forge doesn't pin it" + ("" if not newest or _matches(ours, newest) else f"; {newest} is out") + elif newest and not _matches(ours, newest): + status = f"behind: conda-forge pins {cf}, {newest} is out" + else: + status = f"differs from conda-forge ({cf})" + if cf_next != cf: + status += f" (conda-forge-pinning {newest_version}: {cf_next or 'not pinned'})" + why = comment.replace("\n", " ").replace("|", "\\|") + rows.append(f"| `{key}` | `{ours}` ({where}) | {f'`{cf}`' if cf else '–'} | {newest or '?'} | {status} | {why} |") + lines = [f"Compared with conda-forge-pinning {current} (the one {distro} is on; without its migrations) and the " + "newest versions on conda-forge:", "", + "| override | ours | conda-forge pins | newest | | why (comment) |", "|---|---|---|---|---|---|", *rows] + if uncompared: + lines += ["", "Not compared (several values, selectors, or not one package): " + ", ".join(uncompared)] + if coupled := coupled_pin_checks(overrides, cache): + lines += ["", "Pins that have to match another package:", "", *coupled] + return lines + + +def report_issue_body(distro: str, data: dict, migrations: str = "", run_url: str = "", + overrides: list[str] | None = None) -> str: """The dependency-report issue of a distribution, from check_dependency_compat.py's --json output (pin_conflicts, conflicts, notes) and its migration status.""" conflicts, pins, notes = data.get("conflicts") or {}, data.get("pin_conflicts") or {}, data.get("notes") or {} @@ -1159,6 +1300,11 @@ def report_issue_body(distro: str, data: dict, migrations: str = "", run_url: st if notes: lines += ["Notes (run requirements built for a newer glibc than the build floor: they limit the systems " "they install on, but don't conflict with the pins): " + ", ".join(f"`{n}`" for n in sorted(notes)), ""] + if overrides: + if warnings := [line for line in overrides if line.startswith("- ⚠️")]: + lines += [*warnings, ""] + lines += [*_details(f"Pinning overrides (shared/pinning/overrides.yaml, distros/{distro}/distro.yaml)", + overrides), ""] if migrations: lines += [*_details("conda-forge migration status", ["```text", migrations, "```"]), ""] if conflicts: @@ -1223,7 +1369,7 @@ def dependency_report(distro: str) -> Result: run_url = "" if run_id := os.environ.get("GITHUB_RUN_ID"): run_url = f"{os.environ.get('GITHUB_SERVER_URL', 'https://github.com')}/{os.environ.get('GITHUB_REPOSITORY')}/actions/runs/{run_id}" - body = report_issue_body(distro, data, migration_status(proc.stdout), run_url) + body = report_issue_body(distro, data, migration_status(proc.stdout), run_url, override_report(distro)) title = f"{distro}: {count} dependency conflict{'s' if count != 1 else ''}" if count else f"{distro}: no dependency conflicts" if not os.environ.get("GITHUB_ACTIONS"): return Result(title, body) diff --git a/tools/tests/test_override_report.py b/tools/tests/test_override_report.py new file mode 100644 index 000000000..ffdc624ec --- /dev/null +++ b/tools/tests/test_override_report.py @@ -0,0 +1,92 @@ +"""dependency-report: the pinning overrides compared with conda-forge.""" + +import maintenance +import robostack as rs +from vinca import pinning + +SHARED = """pinning_overrides: + channel_sources: null + # why lua is held + lua: + - 5.4 + # why openexr is held + openexr: + - '3.4' + bar: + - 2.0 + qt6_main: + - 6.11 + libzenohc: + - 1.10.1 +""" +# conda-forge-pinning: "1" is the one the distribution is on, "2" the newest +CBC = {"1": "openexr:\n - '3.5'\nbar:\n - 2.0\nqt6_main:\n - '6'\n", + "2": "openexr:\n - '3.5'\nbar:\n - 2.1\nqt6_main:\n - '6.11'\n"} + + +def _file(subdir, version, depends): + return {"version": version, "attrs": {"subdir": subdir, "depends": depends}} + + +PACKAGES = { + "lua": {"latest_version": "5.5.0"}, + "openexr": {"latest_version": "3.5.5"}, + "bar": {"latest_version": "2.0.3"}, + "pyqt6": {"latest_version": "6.12.0", "files": [_file("linux-64", "6.12.0", ["qt6-main 6.12.0.*", "sip >=6.17.3"]), + _file("linux-64", "6.11.0", ["qt6-main 6.11.2.*"])]}, + "libzenohc": {"latest_version": "1.10.2"}, + "libgz-transport": {"files": [_file(p, "15.2.0", ["libzenohc >=1.10.2,<1.10.3.0a0"]) + for p in ("linux-64", "osx-64", "osx-arm64", "win-64")]}, +} + + +def _setup(monkeypatch, tmp_path, own="", packages=PACKAGES): + (tmp_path / "pinning").mkdir() + (tmp_path / "pinning" / "overrides.yaml").write_text(SHARED) + (tmp_path / "pinning" / "conda_forge.yaml").write_text("conda_forge_pinning_version: '1'\nmigrations: []\n") + (tmp_path / "x").mkdir() + (tmp_path / "x" / "distro.yaml").write_text(own) + monkeypatch.setattr(rs, "SHARED", tmp_path) + monkeypatch.setattr(rs, "DISTROS", tmp_path) + monkeypatch.setattr(pinning, "get_latest_pinning_distribution", lambda: ("2", "url")) + monkeypatch.setattr(pinning, "download_pinning_package", lambda version, artifact_url=None: (CBC[version], {})) + monkeypatch.setattr(maintenance, "conda_forge_package", lambda name, cache: packages.get(name)) + + +def _row(lines, key): + return next(line for line in lines if line.startswith(f"| `{key}` |")) + + +def test_override_report_rows(monkeypatch, tmp_path): + _setup(monkeypatch, tmp_path) + lines = maintenance.override_report("x") + assert lines[0].startswith("Compared with conda-forge-pinning 1 (the one x is on") + assert "conda-forge doesn't pin it; 5.5.0 is out | why lua is held |" in _row(lines, "lua") + assert "behind: conda-forge pins 3.5, 3.5.5 is out | why openexr is held |" in _row(lines, "openexr") + # equal to the distribution's pinning; the newest one moves on, which is noted + assert "same as conda-forge: can be dropped (conda-forge-pinning 2: 2.1)" in _row(lines, "bar") + assert "has to match another package, see below" in _row(lines, "qt6_main") + assert not any("channel_sources" in line for line in lines) # dropped (null) + assert "- ⚠️ `qt6_main` `6.11`: conda-forge's newest pyqt6 (6.12.0) is built for qt6-main 6.12.0" in "\n".join(lines) + assert "- ⚠️ `libzenohc` `1.10.1`: 1.10.2 is out, but libgz-transport has no build for it on linux-aarch64 yet: wait." \ + in lines + + +def test_override_report_distribution_overrides(monkeypatch, tmp_path): + packages = dict(PACKAGES) + packages["libgz-transport"] = {"files": [_file(p, "15.2.0", ["libzenohc >=1.10.2,<1.10.3.0a0"]) + for p in maintenance.GZ_TRANSPORT_PLATFORMS]} + _setup(monkeypatch, tmp_path, own="pinning_overrides:\n qt6_main: ['6.12.0']\n lua: null\n", packages=packages) + lines = maintenance.override_report("x") + assert "`6.12.0` (distro.yaml)" in _row(lines, "qt6_main") + assert not any(line.startswith("| `lua` |") for line in lines) # dropped by the distribution + assert "- ✅ `qt6_main` `6.12.0`: conda-forge's newest pyqt6 (6.12.0) is built for qt6-main 6.12.0" in lines + assert "- ⚠️ `libzenohc` `1.10.1`: 1.10.2 is out; libgz-transport is built for it on all 5 platforms, so it can move." \ + in lines + + +def test_report_issue_body_shows_override_warnings(): + overrides = ["table", "- ✅ fine", "- ⚠️ move it"] + body = maintenance.report_issue_body("x", {}, "", "", overrides) + assert "\n- ⚠️ move it\n\n
\nPinning overrides" in body + assert "- ✅ fine" in body.split("
", 1)[1]