Skip to main content

write.scaffold_unit

write.scaffold_unit(spec, module, pace)

Draft regen/units/<unit>.toml for a module that has no unit record yet.

Everything that can be read from the tree is filled in: the first paragraph of the module docstring as summary, the public names (__all__, else public defs, classes and upper-case constants), the package imports as depends_on, and every file that references the module as a consumer (test files named after the module as unit_tests, and tests/test_regen_eval_<module>.py, which the unit’s durable evaluations are written in, as evaluations). The record names neither the unit nor its path: both follow from the file name. What only a person can supply is left open: the intent items, the evaluations, the decisions and the external consumers. The draft therefore fails check with INTENT01 until at least one intent item is written, so a scaffold can never pass the check unreviewed.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec. required
module str Dotted module name, with or without the package prefix. required
pace str fast, medium or slow. required

Returns

Name Type Description
tuple[Path, str] tuple[Path, str]: Target path of the record and its TOML text.

Raises

Name Type Description
SpecError If the module already has a unit record or pace is unknown.
FileNotFoundError If the module has no file below the source directory.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import load_spec, make_sample_repo, scaffold_unit

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    (root / "regen/units/core.calc.toml").unlink()
    target, text = scaffold_unit(load_spec(root), "core.calc", "slow")
    print(target.relative_to(root))
    print([line for line in text.splitlines() if line.startswith(("pace", "public"))])
regen/units/core.calc.toml
['pace = "slow"', 'public = ["add"]']