Skip to main content

write.Written

write.Written(path, text, created, written, findings, next)

What a writer did: the record, the text and, after a write, what is still open.

Attributes

Name Type Description
path Path The record that was created or appended to.
text str Exactly the text that was created (a new file) or appended (a blank line and one block), or, in a dry run, the text that would be.
created bool Whether the record is a new file.
written bool Whether the file was written; False in a dry run.
findings tuple[Finding, …] The findings of the check for the record after the write: check_unit for a unit, the findings about the file for a decision. Empty in a dry run.
next str One sentence that says what remains to be done.

Examples

from pathlib import Path
from tempfile import TemporaryDirectory

from babregen import add_consumer, load_spec, make_sample_repo

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    (root / "scripts").mkdir()
    (root / "scripts/use_it.py").write_text("from samplepkg.core import calc\n")
    done = add_consumer(
        load_spec(root), "core.calc", "scripts/use_it.py", note="runs add"
    )
    print(done.report(root))
wrote regen/units/core.calc.toml
next: run babregen check

Methods

Name Description
report The lines a command prints after a write: wrote PATH, next:, the findings.

report

write.Written.report(root)

The lines a command prints after a write: wrote PATH, next:, the findings.

The findings come last, under still open (babregen check will report):, and only when there are any, so that the two lines that say what happened and what to do are the first two.

Parameters

Name Type Description Default
root Path The repository root, which the path is shown relative to. required

Returns

Name Type Description
str str The lines, without a trailing line feed.