Files
hermes-agent/scripts/syntax_guard.py

57 lines
2.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
import importlib.util
import re
import requests
import psutil
from pathlib import Path
errors = []
# Check for missing dependencies
required_modules = ["llama_cpp", "requests", "psutil", "jinja2", "papermill"]
for module in required_modules:
if not importlib.util.find_spec(module):
errors.append(f"Missing required module: {module}")
print(f"MISSING DEPENDENCY: {module}", file=sys.stderr)
# Check for external API calls in test files
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 HTTP API calls
if "test_" in p.name or "smoke_test" in p.name:
with open(p, "r") as f:
content = f.read()
if re.search(r'requests\.(get|post|put|delete)', content):
errors.append(f"External API call detected in {p}")
print(f"API CALL DETECTED: {p}", file=sys.stderr)
# Check local model server health
try:
response = requests.get("http://localhost:8080/v1", timeout=5)
if response.status_code != 200:
errors.append("Local model server not responding")
print("MODEL SERVER ERROR: Not responding", file=sys.stderr)
except requests.exceptions.RequestException:
errors.append("Local model server not reachable")
print("MODEL SERVER ERROR: Not reachable", file=sys.stderr)
# Check RAM usage
if psutil.virtual_memory().available < 500 * 1024 * 1024: # 500MB free
errors.append("Insufficient RAM for model and system")
print("RAM ERROR: Less than 500MB available", file=sys.stderr)
if errors:
print(f"\n{len(errors)} issue(s) detected", file=sys.stderr)
sys.exit(1)
print("All Python files compile successfully and dependencies are satisfied")