Skip to main content

write.new_decision

write.new_decision(
    spec,
    decision_id,
    *,
    title,
    driver,
    decision,
    approved_by,
    decided_on=None,
    status='active',
    review_after=None,
    evidence=(),
    assumes=(),
    alternatives=(),
    dry_run=False,
)

Create regen/decisions/<id>.toml: the writer behind babregen new-decision.

The file is created and never overwritten. The text is the SPDX header of the architecture, the keys that were given in the order of the schema, and one [[alternatives]] block per rejected option. Nothing is made up: a key that has no value is left out, and the loader rejects a required value that is empty.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec. required
decision_id str The id, which is the file name without .toml: letters and digits, with ., - or _ between them. required
title str What was decided, in one line (prose). required
driver str What forced the decision (prose). required
decision str What was decided, and what it protects (prose). required
approved_by str Who stands behind the decision. required
decided_on date | None The date of the decision; today (UTC) by default. None
status str active (default), superseded or expired. 'active'
review_after date | None Date after which the check reports the record as due for review. None
evidence Sequence[str] References: file:<path> (which must exist), commit:<sha>, KB:<entry> or url:<url>. ()
assumes Sequence[str] Conditions the decision rests on (prose). ()
alternatives Sequence[tuple[str, str]] Pairs of a rejected option and why it lost (prose). ()
dry_run bool Check everything and return the text, but write nothing. False

Returns

Name Type Description
Written Written The new file, its text and the findings of the check about it.

Raises

Name Type Description
SpecError If the id is not valid, the file exists, the status or an evidence prefix is unknown, a file: evidence does not exist, a prose value holds a blank line, a name holds a line break or the result would not load.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import load_spec, make_sample_repo, new_decision

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    done = new_decision(
        load_spec(root),
        "why-sub",
        title="Subtraction is provided",
        driver="A user asked for it.",
        decision="Provide sub next to add.",
        approved_by="maintainer",
        dry_run=True,
    )
    print(done.text)
title = "Subtraction is provided"
date = 2026-11-29
status = "active"
driver = "A user asked for it."
decision = "Provide sub next to add."
approved_by = "maintainer"