Files
soleprint/soleprint/atlas2/docgen/extractors/python/__init__.py
2026-09-12 06:42:49 -03:00

30 lines
828 B
Python

"""
Python source -> IR, by `ast`.
from docgen.extractors.python import extract
ir = extract(Path("app/"))
Deterministic. A diagram built from this cannot be out of date with the code,
which is the whole reason the structural path has no model in it.
Two passes, because `ast` resolves nothing on its own — see `collect.py` and
`resolve.py`.
"""
from pathlib import Path
from .collect import collect
from .resolve import to_ir
def extract(root, exclude=(), source="python"):
"""Walk `root`, return an IR Graph. Never raises on a bad file."""
root = Path(root).resolve()
if not root.is_dir():
raise NotADirectoryError(f"not a directory: {root}")
modules = collect(root, exclude=exclude)
return to_ir(modules, root=root.name, source=source)
__all__ = ["extract", "collect", "to_ir"]