39 lines
1.0 KiB
Python
Executable File
39 lines
1.0 KiB
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
|
|
from colorama import Fore, Style, init
|
|
|
|
init(autoreset=True)
|
|
|
|
errors = []
|
|
total_files = 0
|
|
large_files = []
|
|
|
|
for p in Path(".").rglob("*.py"):
|
|
if ".venv" in p.parts or "__pycache__" in p.parts:
|
|
continue
|
|
|
|
total_files += 1
|
|
if p.stat().st_size > 10 * 1024 * 1024: # 10MB
|
|
large_files.append(p)
|
|
|
|
try:
|
|
py_compile.compile(str(p), doraise=True)
|
|
except py_compile.PyCompileError as e:
|
|
errors.append(f"{p}: {e}")
|
|
print(f"{Fore.RED}SYNTAX ERROR: {p}{Style.RESET_ALL}: {e}", file=sys.stderr)
|
|
sys.exit(1) # Exit early on first error
|
|
|
|
if errors:
|
|
print(f"\n{len(errors)} file(s) with syntax errors", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if large_files:
|
|
print(f"{Fore.YELLOW}Large files (>10MB) detected:{Style.RESET_ALL}")
|
|
for f in large_files:
|
|
print(f" - {f}")
|
|
|
|
print("✅ All Python files compile successfully")
|