Files
GEWU/scripts/check_boundaries.py
T

30 lines
1.1 KiB
Python
Raw Normal View History

"""Enforce inward dependencies in the domain package."""
import ast
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
FORBIDDEN = ("fastapi", "mcp", "gewu.adapters", "gewu.bootstrap", "gewu.transports")
def main() -> None:
domain = ROOT / "src" / "gewu" / "domain"
violations: list[str] = []
for path in domain.rglob("*.py"):
tree = ast.parse(path.read_text(encoding="utf-8"), filename=str(path))
for node in ast.walk(tree):
if isinstance(node, ast.Import):
names = [alias.name for alias in node.names]
elif isinstance(node, ast.ImportFrom):
names = [node.module or ""]
else:
continue
for name in names:
if any(name == prefix or name.startswith(prefix + ".") for prefix in FORBIDDEN):
violations.append(f"{path.relative_to(ROOT)}:{node.lineno}: {name}")
if violations:
raise SystemExit("Forbidden domain dependencies:\n" + "\n".join(violations))
if __name__ == "__main__":
main()