scaffold.scaffold_unit

scaffold.scaffold_unit(spec, module, pace, risk)

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: path, 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). What only a person can supply is left open: the intent items, the evaluations, the decisions and the external, operational and human consumers. The draft therefore fails check with UNIT06 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
risk str low, medium or high. 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 or risk is unknown.
FileNotFoundError If the module has no file below the source directory.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen 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", "high")
    print(target.relative_to(root))
    print([line for line in text.splitlines() if line.startswith(("unit", "path"))])
regen/units/core.calc.toml
['unit = "samplepkg.core.calc"', 'path = "src/samplepkg/core/calc.py"', 'unit_tests = []']