From dae6b3a14626a919550dfb105ebf4f8437e114d4 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:22:27 +0100 Subject: [PATCH] fix: fail --manifest-targets without targets dir --- scripts/packs/packmodes.py | 13 ++++++++++--- scripts/packs/targets.py | 18 ++++++++---------- tests/test_audit_regressions.py | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/scripts/packs/packmodes.py b/scripts/packs/packmodes.py index 95ddd2e6a..e8772471f 100644 --- a/scripts/packs/packmodes.py +++ b/scripts/packs/packmodes.py @@ -59,9 +59,16 @@ def _run_quick_mode( if holds_other_kind(args.output_dir, "targets"): sys.exit(1) with pack_output_lock(args.output_dir): - generate_target_manifests( - os.path.join(args.platforms_dir, "targets"), args.output_dir - ) + try: + written = generate_target_manifests( + os.path.join(args.platforms_dir, "targets"), args.output_dir + ) + except FileNotFoundError as exc: + print(exc, file=sys.stderr) + sys.exit(1) + for name, count in written: + print(f" {name}: {count} targets") + print(f"Generated {len(written)} target manifest(s) in {args.output_dir}") return True return run_listing(args, parser, args.list) diff --git a/scripts/packs/targets.py b/scripts/packs/targets.py index 46ec358eb..123f746c1 100644 --- a/scripts/packs/targets.py +++ b/scripts/packs/targets.py @@ -4,7 +4,6 @@ from __future__ import annotations import json import os -import sys from pathlib import Path from core.artifacts import write_text_atomic @@ -12,23 +11,22 @@ from model.sources import source_yaml_file from model.targets import load_target_config, target_aliases, target_overrides -def generate_target_manifests(targets_dir: str, output_dir: str) -> None: - """Convert target YAMLs to installer JSON manifests.""" - os.makedirs(output_dir, exist_ok=True) +def generate_target_manifests(targets_dir: str, output_dir: str) -> list[tuple[str, int]]: + """Convert target YAMLs to installer JSON manifests: each platform + written, with its number of targets. A missing directory raises.""" targets_path = Path(targets_dir) if not targets_path.is_dir(): - print(f"No targets directory at {targets_dir}", file=sys.stderr) - return - count = 0 + raise FileNotFoundError(f"No targets directory at {targets_dir}") + os.makedirs(output_dir, exist_ok=True) + written: list[tuple[str, int]] = [] for yml_file in sorted(targets_path.glob("*.yml")): if yml_file.name.startswith("_"): continue result = target_list(yml_file) out_path = Path(output_dir) / f"{yml_file.stem}.json" write_text_atomic(out_path, json.dumps(result, indent=2, sort_keys=True) + "\n") - count += 1 - print(f" {yml_file.stem}: {len(result)} targets") - print(f"Generated {count} target manifest(s) in {output_dir}") + written.append((yml_file.stem, len(result))) + return written def target_list(yml_file: Path) -> dict[str, list[str] | dict | None]: diff --git a/tests/test_audit_regressions.py b/tests/test_audit_regressions.py index 75053e7a8..e7c77afeb 100644 --- a/tests/test_audit_regressions.py +++ b/tests/test_audit_regressions.py @@ -2254,6 +2254,23 @@ class TargetManifestRegressions(unittest.TestCase): with self.assertRaisesRegex(ValueError, "non-empty strings"): generate_target_manifests(str(source), str(output)) + def test_a_missing_targets_directory_fails_the_command(self): + """--manifest-targets printed the missing directory and exited 0 + with nothing written: the pipeline step read that as done.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + with self.assertRaisesRegex(FileNotFoundError, "No targets directory"): + generate_target_manifests(str(root / "absent"), str(root / "out")) + (root / "plat").mkdir() + run = subprocess.run( + [sys.executable, str(ROOT / "scripts" / "generate_pack.py"), + "--manifest-targets", "--platforms-dir", str(root / "plat"), + "--output-dir", str(root / "out")], + capture_output=True, text=True, cwd=ROOT, check=False, + ) + self.assertEqual(run.returncode, 1, run.stderr) + self.assertIn("No targets directory at", run.stderr) + class CheckoutCompletenessRegressions(unittest.TestCase): """Coverage is resolved against the disk, so the checkout must be whole.