44 lines
1.7 KiB
Python
Executable File
44 lines
1.7 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
|
|
|
|
errors = []
|
|
for p in Path(".").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)
|
|
|
|
# Check for cloud API usage
|
|
with open(p, "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
if any(import_pattern.search(content) for import_pattern in CLOUD_API_IMPORTS):
|
|
errors.append(f"{p}: Cloud API import detected")
|
|
print(f"CLOUD API IMPORT: {p}", file=sys.stderr)
|
|
if any(call_pattern.search(content) for call_pattern in CLOUD_API_CALLS):
|
|
errors.append(f"{p}: Cloud API call detected")
|
|
print(f"CLOUD API CALL: {p}", file=sys.stderr)
|
|
|
|
CLOUD_API_IMPORTS = [
|
|
re.compile(r'\bimport\s+(requests|httpx|aiohttp|urllib\.request)\b'),
|
|
re.compile(r'\bfrom\s+(requests|httpx|aiohttp|urllib\.request)\b'),
|
|
]
|
|
|
|
CLOUD_API_CALLS = [
|
|
re.compile(r'\b(requests\.(get|post|put|delete|patch|head|options))\b'),
|
|
re.compile(r'\b(httpx\.(get|post|put|delete|patch|head|options))\b'),
|
|
re.compile(r'\b(aiohttp\.(ClientSession\.)?\b(get|post|put|delete|patch|head|options))\b'),
|
|
re.compile(r'\b(urllib\.request\.(urlopen|urlretrieve))\b'),
|
|
re.compile(r'\brequests\.Session\(\)\.(get|post|put|delete|patch|head|options)\b'),
|
|
]
|
|
|
|
if errors:
|
|
print(f"\n{len(errors)} file(s) with syntax or cloud API errors", file=sys.stderr)
|
|
sys.exit(1)
|
|
print("All Python files compile and are cloud API-free")
|