Skip to main content

spec.Unit

spec.Unit(
    name,
    path,
    summary,
    pace,
    public,
    depends_on,
    evaluations,
    unit_tests,
    intent,
    consumers,
    source,
)

A regenerable unit: one module plus the knowledge needed to rebuild it.

Attributes

Name Type Description
name str Dotted module name, <package>.<stem of the record> (the stem __init__ names the package itself; a dotted stem is a nested module), for example "samplepkg.core.calc".
path str Repository-relative POSIX path of the implementation, derived from name and normalised: <source_dir>/<package>/<a>/<b>/__init__.py if that file exists (a package directory wins over a module of the same name), else <source_dir>/<package>/<a>/<b>.py.
summary str One-paragraph purpose of the unit.
pace str fast, medium or slow, see [pace] in architecture.toml. The loader does not check it: it is empty when the record declares none and holds the value as written when that is not a pace, and check reports both (PACE01, PACE02).
public tuple[str, …] Public names the unit must define (its contract).
depends_on tuple[str, …] Modules of the package the unit may import.
evaluations tuple[str, …] Repository-relative paths of the durable evaluation files.
unit_tests tuple[str, …] Repository-relative paths of the implementation-coupled tests (the ephemeral layer, regenerated with the code).
intent tuple[IntentItem, …] The intent items.
consumers tuple[Consumer, …] Known dependents.
source Path Path of the TOML file the unit was read from.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import load_spec, make_sample_repo

with TemporaryDirectory() as tmp:
    spec = load_spec(make_sample_repo(Path(tmp) / "demo"))
    unit = spec.units["samplepkg.core.calc"]
    print(unit.name, unit.path, unit.pace, unit.public)
samplepkg.core.calc src/samplepkg/core/calc.py fast ('add',)