diff --git a/.gitignore b/.gitignore index baa31a543..71958d693 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ mini-swe-agent/ # Nix .direnv/ result +.aider* diff --git a/scripts/syntax_guard.py b/scripts/syntax_guard.py index 7c41dc9b4..75d7a5e31 100755 --- a/scripts/syntax_guard.py +++ b/scripts/syntax_guard.py @@ -14,7 +14,30 @@ for p in Path(".").rglob("*.py"): 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 errors", file=sys.stderr) + print(f"\n{len(errors)} file(s) with syntax or cloud API errors", file=sys.stderr) sys.exit(1) -print("All Python files compile successfully") +print("All Python files compile and are cloud API-free")