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]: ARCH01 errors for forbidden imports, ARCH02 errors for subpackages the architecture does not list, ARCH04 errors for import cycles not in known_cycles, ARCH03 warnings for listed subpackages that no longer exist or allowed edges nobody uses, ARCH05 warnings for known cycles that have disappeared.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen 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())
[]
ERROR   ARCH01  src/samplepkg/core/bad.py: 'core' imports 'samplepkg.app', but architecture.toml allows only []
ERROR   ARCH04  architecture.toml: new import cycle between 'app' and 'core' (not in known_cycles)