Skip to main content

spec.load_unit

spec.load_unit(path, architecture)

Read one regen/units/<stem>.toml file.

The unit is named <package>.<stem> after the architecture’s package (the stem __init__ names the package itself), and its module path is derived from that name; the record holds neither. A dotted stem is a nested module (core.sub.mod.toml is <package>.core.sub.mod), so a module outside <source_dir>/<package>/ cannot be a unit.

Parameters

Name Type Description Default
path Path Path of the file. required
architecture Architecture The architecture the unit belongs to. required

Returns

Name Type Description
Unit Unit The parsed unit.

Raises

Name Type Description
SpecError If a required field is missing, a value has the wrong type, a key of the schema is unknown, a consumer kind is unknown, an intent id repeats or the stem is not a dotted module name (a part that is not an identifier, or __init__ as a part: the record of a package is <package dir>.toml). A missing or unknown pace is no error here: check reports it.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import make_sample_repo
from babregen.spec import load_architecture, load_unit

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    arch = load_architecture(root / "regen" / "architecture.toml")
    unit = load_unit(root / "regen" / "units" / "core.calc.toml", arch)
    print(unit.name, unit.path, [item.id for item in unit.intent])
samplepkg.core.calc src/samplepkg/core/calc.py ['C-1']