2776813df3
The Sep 2026 decomposition (PR #102117) makes internal import paths a non-API: names now live in the focused modules that define them. This commit is the ONLY thing keeping the old paths alive, so external plugins have time to update. It is deliberately a single, unsquashed commit: git revert <this sha> removes every shim, stub and manifest at once on the announced date. Nothing in-tree may depend on these pointers: scripts/check_compat_pointers.py (wired into lint.yml) fails CI if it does. What it adds (see COMPAT_MANIFEST.md, compat_manifest.json): - 332 facade modules get one delimited `PLUGIN-COMPAT` block appended at the end of the file - 1,172 moved names resolved lazily via a module `__getattr__` (PEP 562) — never a top-level import, so no import cycles; facades that already had `__getattr__` get a chained one - 592 third-party/stdlib names the old modules used to expose, with their original import statements - 266 public definitions that had been deleted as unused, restored byte-for-byte from the pre-decomposition tree (+40 private helpers and 16 imports pulled in only because a restored definition needs them) - 3 deleted modules recreated as re-export stubs (gateway/startup_watchdog, hermes_cli/observability/ relay_runtime, tools/environments/modal_utils) - private names (`_x`) get no pointer: they were never API (3,792 skipped) Verified: all 335 touched modules import under a fresh HERMES_HOME and every manifest name resolves; the lint reports zero in-tree uses; ruff clean; targeted suites unchanged.
94 lines
4.1 KiB
Python
94 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Fail when in-tree code depends on a plugin-compat pointer.
|
|
|
|
``compat_manifest.json`` lists every name the Sep 2026 decomposition kept importable from its OLD
|
|
module purely for external plugins (the `PLUGIN-COMPAT` blocks). Those blocks are removed on a
|
|
schedule by reverting the commit that added them, so nothing inside this repository may depend on
|
|
them — otherwise the revert breaks the tree. This check walks every first-party Python file (source
|
|
AND tests) and flags:
|
|
|
|
from <facade> import <compat_name> # direct import through the old path
|
|
import <facade>; <facade>.<compat_name> # attribute access through the old path
|
|
patch("<facade>.<compat_name>") / monkeypatch.setattr(<facade>, "<compat_name>")
|
|
|
|
Exit 1 with a file:line list on any hit. Run: python scripts/check_compat_pointers.py
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
MANIFEST = ROOT / "compat_manifest.json"
|
|
SKIP_DIRS = {".git", "node_modules", "website", "skills", "optional-skills", "apps", "evals", "build", "MagicMock", ".worktrees", "__pycache__"}
|
|
|
|
|
|
def _py_files():
|
|
for p in ROOT.rglob("*.py"):
|
|
parts = p.relative_to(ROOT).parts
|
|
if parts[0] in SKIP_DIRS or p.name == "check_compat_pointers.py":
|
|
continue
|
|
yield p
|
|
|
|
|
|
def main() -> int:
|
|
if not MANIFEST.exists():
|
|
print("compat_manifest.json missing — nothing to check (compat layer already reverted?)")
|
|
return 0
|
|
entries = json.loads(MANIFEST.read_text(encoding="utf-8"))["entries"]
|
|
compat: dict[str, set[str]] = {}
|
|
for e in entries:
|
|
compat.setdefault(e["facade"], set()).add(e["name"])
|
|
facades = set(compat)
|
|
hits: list[str] = []
|
|
str_pat = re.compile(r"""["']((?:[A-Za-z_][\w]*\.)+[A-Za-z_]\w*)["']""")
|
|
for path in _py_files():
|
|
rel = path.relative_to(ROOT)
|
|
try:
|
|
src = path.read_text(encoding="utf-8", errors="ignore")
|
|
tree = ast.parse(src)
|
|
except SyntaxError:
|
|
continue
|
|
# module-level facade import aliases in this file: alias -> facade
|
|
aliases: dict[str, str] = {}
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.ImportFrom) and node.module in facades and node.level == 0:
|
|
bad = [a.name for a in node.names if a.name in compat[node.module]]
|
|
for b in bad:
|
|
hits.append(f"{rel}:{node.lineno}: from {node.module} import {b}")
|
|
elif isinstance(node, ast.Import):
|
|
for a in node.names:
|
|
if a.name in facades:
|
|
aliases[a.asname or a.name] = a.name
|
|
elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
|
|
for a in node.names:
|
|
full = f"{node.module}.{a.name}"
|
|
if full in facades:
|
|
aliases[a.asname or a.name] = full
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name):
|
|
fac = aliases.get(node.value.id)
|
|
if fac and node.attr in compat[fac]:
|
|
hits.append(f"{rel}:{node.lineno}: {node.value.id}.{node.attr} (via {fac})")
|
|
elif isinstance(node, ast.Constant) and isinstance(node.value, str):
|
|
m = str_pat.fullmatch(node.value.strip())
|
|
if m:
|
|
dotted = m.group(1); fac, _, name = dotted.rpartition(".")
|
|
if fac in facades and name in compat[fac]:
|
|
hits.append(f"{rel}:{node.lineno}: \"{dotted}\" (string patch target)")
|
|
if hits:
|
|
print("❌ in-tree code depends on plugin-compat pointers (scheduled for removal):")
|
|
for h in sorted(set(hits)):
|
|
print(" " + h)
|
|
print(f"\n{len(set(hits))} site(s). Import from the defining module instead (see COMPAT_MANIFEST.md).")
|
|
return 1
|
|
print(f"✅ no in-tree dependency on the {len(entries)} plugin-compat pointers")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|