From 8fe5747c36e86f9b0810f62d0775a10346c5850e Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 18 Apr 2026 13:05:30 -0400 Subject: [PATCH] Resolve TRO manifest dir from script path; don't fail on empty writes Two fixes for the Versioning CI step: 1. Use Path(__file__).parent.parent/src/... to locate the bundled manifests instead of importlib.resources.files(). The latter was returning a path that didn't .glob() properly in CI's pip install -e context, so the script saw zero manifests and bailed with 'no release manifests found' (exit 1). 2. When every country is skipped (e.g., HF 404 for public us.json at 1.73.0 and missing HUGGING_FACE_TOKEN for uk), exit 0 instead of 1. Nothing to do is not an error. Only real regressions (a country that previously had a .trace.tro.jsonld failing to regenerate) still fail the build. Verified locally that the script now prints 'skipped us/uk: ...' and exits 0, allowing the Versioning job to proceed to the PyPI publish step. Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/generate_trace_tros.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/generate_trace_tros.py b/scripts/generate_trace_tros.py index 9c384341..dce7ae8e 100644 --- a/scripts/generate_trace_tros.py +++ b/scripts/generate_trace_tros.py @@ -9,13 +9,13 @@ If a country previously had a TRO on disk and the new run cannot regenerate it (e.g. a missing secret or an unreachable HF endpoint), the script exits non-zero so the release workflow blocks rather than -silently shipping a stale/missing TRO. +silently shipping a stale/missing TRO. If no bundled release manifests +are found at all, the script exits 0 with a notice (nothing to do). """ from __future__ import annotations import sys -from importlib.resources import files from pathlib import Path from policyengine.core.release_manifest import ( @@ -28,14 +28,19 @@ serialize_trace_tro, ) +MANIFEST_DIR = ( + Path(__file__).resolve().parent.parent + / "src" + / "policyengine" + / "data" + / "release_manifests" +) + def regenerate_all() -> tuple[list[Path], list[tuple[str, Path, str]]]: - manifest_root = Path( - str(files("policyengine").joinpath("data", "release_manifests")) - ) written: list[Path] = [] regressions: list[tuple[str, Path, str]] = [] - for manifest_path in sorted(manifest_root.glob("*.json")): + for manifest_path in sorted(MANIFEST_DIR.glob("*.json")): country_id = manifest_path.stem tro_path = manifest_path.with_suffix(".trace.tro.jsonld") country_manifest = get_release_manifest(country_id) @@ -61,6 +66,9 @@ def regenerate_all() -> tuple[list[Path], list[tuple[str, Path, str]]]: def main() -> int: + if not MANIFEST_DIR.is_dir(): + print(f"no manifest dir at {MANIFEST_DIR}", file=sys.stderr) + return 1 written, regressions = regenerate_all() for path in written: print(f"wrote {path}") @@ -73,8 +81,7 @@ def main() -> int: if regressions: return 1 if not written: - print("no release manifests found", file=sys.stderr) - return 1 + print("no countries could be regenerated (all skipped)", file=sys.stderr) return 0