28 lines
865 B
Python
Executable File
28 lines
865 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""Syntax guard — compile all Python files to catch syntax errors before merge."""
|
|
import py_compile
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
errors = []
|
|
script_dir = Path(__file__).resolve().parent
|
|
repo_root = script_dir
|
|
while not (repo_root / ".git").is_dir():
|
|
repo_root = repo_root.parent
|
|
if repo_root == repo_root.parent:
|
|
break # Prevent infinite loop if not in a git repo
|
|
|
|
for p in repo_root.rglob("*.py"):
|
|
if ".venv" in p.parts or "__pycache__" in p.parts:
|
|
continue
|
|
try:
|
|
py_compile.compile(str(p), doraise=True)
|
|
except py_compile.PyCompileError as e:
|
|
errors.append(f"{p}: {e}")
|
|
print(f"SYNTAX ERROR: {p}: {e}", file=sys.stderr)
|
|
|
|
if errors:
|
|
print(f"\n{len(errors)} file(s) with syntax errors", file=sys.stderr)
|
|
sys.exit(1)
|
|
print("All Python files compile successfully")
|