-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscover_floors.py
More file actions
109 lines (85 loc) · 3.41 KB
/
Copy pathdiscover_floors.py
File metadata and controls
109 lines (85 loc) · 3.41 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
"""discover_floors.py - auto-discover and run the repo's red floors.
A floor is a Python file carrying the marker line ``# FLOOR`` within its first
few lines. Discovery replaces the hardcoded floor list that used to live in
``tests.yml``: adding a skill means dropping a marked floor, never editing the
workflow (ROADMAP G5).
Tools (``check_steering_doc.py``, ``check_action_drift.py``) and this discoverer
itself do not carry the marker, so they are never run as floors. pytest-style
floors live under ``tests/`` and are found by ``pytest tests/``, not here.
Usage::
python scripts/discover_floors.py --run # run every discovered floor
python scripts/discover_floors.py --list # print discovered paths
Exit 0 = every discovered floor passed (or, with --list, discovery succeeded);
exit 1 = at least one floor failed, or no floor was found.
"""
from __future__ import annotations
import argparse
import itertools
import subprocess
import sys
from pathlib import Path
MARKER = "# FLOOR"
MARKER_SCAN_LINES = 5
EXCLUDED_DIRS = {".git", ".venv", "__pycache__", "node_modules"}
def is_floor(path: Path) -> bool:
"""True iff one of the file's first MARKER_SCAN_LINES lines is the marker."""
try:
with path.open(encoding="utf-8") as handle:
for line in itertools.islice(handle, MARKER_SCAN_LINES):
if line.strip() == MARKER:
return True
except (OSError, UnicodeDecodeError):
return False
return False
def discover(root: Path) -> list[Path]:
"""Every marked floor under root, excluding EXCLUDED_DIRS, sorted."""
floors = [
path
for path in root.rglob("*.py")
if not EXCLUDED_DIRS.intersection(path.parts) and is_floor(path)
]
return sorted(floors)
def run_floors(floors: list[Path], root: Path) -> int:
"""Run each floor with the current interpreter; 0 iff all passed."""
failed: list[Path] = []
for floor in floors:
rel = floor.relative_to(root)
print(f"[floor] {rel}")
result = subprocess.run([sys.executable, str(floor)], check=False)
if result.returncode != 0:
failed.append(rel)
print()
if failed:
names = ", ".join(str(rel) for rel in failed)
print(f"FAIL: {len(failed)} floor(s) failed: {names}")
return 1
print(f"OK: {len(floors)} floor(s) passed")
return 0
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(
description="Discover and run the repo's red floors by marker."
)
parser.add_argument("root", nargs="?", default=".", help="Root to scan (default: current dir).")
group = parser.add_mutually_exclusive_group()
group.add_argument("--run", action="store_true", help="Run every discovered floor (default).")
group.add_argument("--list", action="store_true", help="Print discovered floor paths and exit.")
args = parser.parse_args(argv)
root = Path(args.root).resolve()
floors = discover(root)
if not floors:
print(
f"No floors found under {root} (marker line '{MARKER}').",
file=sys.stderr,
)
return 1
if args.list:
for floor in floors:
print(floor.relative_to(root))
return 0
return run_floors(floors, root)
if __name__ == "__main__":
sys.exit(main())
# --- floor-coverage registry ---
CODES = frozenset()
FLOOR = "test_discover_floors.py"