Skip to main content

checks.check_architecture

checks.check_architecture(spec)

Check every package import under the source directory against the allowed dependencies.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec. required

Returns

Name Type Description
list[Finding] list[Finding]: COMPILE01 errors for files that do not parse, COMPILE02 for forbidden imports, COMPILE03 for subpackages the architecture does not list, COMPILE04 for import cycles not in known_cycles and PACE03 for a pace that units declare and [pace] has no policy for; COMPACT01 warnings for listed subpackages that no longer exist, COMPACT02 for allowed edges nobody uses and COMPACT03 for known cycles that have disappeared.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import check_architecture, load_spec, make_sample_repo

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    spec = load_spec(root)
    print(check_architecture(spec))
    (root / "src/samplepkg/core/bad.py").write_text("from samplepkg.app import main\n")
    for finding in check_architecture(spec):
        print(finding.format())
[]
src/samplepkg/core/bad.py:1: error COMPILE02 'core' imports 'samplepkg.app', but architecture.toml allows only []
regen/architecture.toml:12: error COMPILE04 new import cycle between 'app' and 'core' (not in known_cycles)