p1-6's acceptance names bench/filesize_check, and the file did not exist: the 500-line rule was enforced by memory. It now runs, and it fails on training.py 1639, benchmarks.py 619, bench/run.py 609 and db.py 503. That is the honest state of the tree, not a passing gate invented after the work. The console work passed independent review on round three: the reviewer re-ran the smoke, then broke the pager three ways and watched each break go red - a pager that does nothing, a pager that appends, and a Previous button that stops restoring.
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""Fail when a tracked source file outgrows the line budget the repo agreed to."""
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
LINE_LIMIT = 500
|
|
CODE_SUFFIXES = (".py", ".go", ".ts", ".tsx", ".mjs", ".css", ".sh", ".ps1")
|
|
|
|
|
|
def tracked_files() -> list[Path]:
|
|
"""Every file git tracks under the repository root."""
|
|
listing = subprocess.run(
|
|
["git", "ls-files"],
|
|
cwd=Path(__file__).resolve().parents[1],
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
if listing.returncode != 0:
|
|
raise SystemExit(f"git ls-files failed: {listing.stderr.strip()}")
|
|
return [Path(name) for name in listing.stdout.split() if name.endswith(CODE_SUFFIXES)]
|
|
|
|
|
|
def line_count(path: Path) -> int:
|
|
return len(path.read_text(encoding="utf-8", errors="replace").splitlines())
|
|
|
|
|
|
def offenders(root: Path, files: list[Path] | None = None) -> list[tuple[int, str]]:
|
|
"""Files over the budget, biggest first."""
|
|
rows: list[tuple[int, str]] = []
|
|
for name in files if files is not None else tracked_files():
|
|
path = root / name
|
|
if not path.is_file():
|
|
continue
|
|
lines = line_count(path)
|
|
if lines > LINE_LIMIT:
|
|
rows.append((lines, str(name)))
|
|
return sorted(rows, reverse=True)
|
|
|
|
|
|
def main() -> None:
|
|
root = Path(__file__).resolve().parents[1]
|
|
over = offenders(root)
|
|
if not over:
|
|
print(f"OK: no tracked source file exceeds {LINE_LIMIT} lines")
|
|
return
|
|
for lines, name in over:
|
|
print(f"{lines:5d} {name}")
|
|
raise SystemExit(f"{len(over)} files exceed the {LINE_LIMIT}-line budget")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|