#!/usr/bin/env python3 """Verify that all .py files in fungus/ are listed in fungus/meson.build.""" import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent FUNGUS_DIR = ROOT / "fungus" MESON_BUILD = FUNGUS_DIR / "meson.build" def discover_py_files() -> set[str]: """Return all .py files directly inside fungus/ (excluding __pycache__).""" return { f.name for f in FUNGUS_DIR.iterdir() if f.is_file() and f.suffix == ".py" and f.name != "__main__.py" } def extract_listed_py_files() -> set[str]: """Parse fungus/meson.build and extract quoted .py filenames.""" text = MESON_BUILD.read_text(encoding="utf-8") # Match single-quoted strings ending with .py return { m.group(1) for m in re.finditer(r"'([^']+\.py)'", text) } def main() -> int: discovered = discover_py_files() listed = extract_listed_py_files() missing_in_meson = discovered - listed extra_in_meson = listed - discovered status = 0 if missing_in_meson: print("❌ .py files in fungus/ NOT listed in meson.build:") for name in sorted(missing_in_meson): print(f" {name}") status = 1 if extra_in_meson: print("⚠️ .py files listed in meson.build but missing from fungus/:") for name in sorted(extra_in_meson): print(f" {name}") if not status: status = 1 # warn is non-zero too if not missing_in_meson and not extra_in_meson: print("✅ All .py files in fungus/ are accounted for in meson.build.") return status if __name__ == "__main__": sys.exit(main())