about summary refs log tree commit diff stats
path: root/scripts/check_meson_py_files.py
blob: 06cb8340812a6ea85978e42f1d05ff7d7157ddcf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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())