Skip to content

pyflightstream.utils.database (stable)

Generated from the docstrings at build time: every one of the 2 names in the __all__ of pyflightstream.utils.database has an entry below. The names a guide or an example uses come first; the others follow under Advanced.

Carry a build's documentation forward into the command database.

Maintainer tooling above commands: this module constructs the schema and owns the registration transaction used by the thin pyfs-manual CLI. Like qa.compat.apply_compat, it validates every rewritten chapter before writing any file (CONTRIBUTING.md invariant 3).

Registration requires a canonical build in the version registry and a manifest source citation. Edition labels can describe unregistered builds for comparisons, but may not write unregistered database rows. A comparison may omit source; a written documented row must cite its manual.

Build edits in memory, reparse them and reconstruct each touched entry through CommandEntry before writing. Already-recorded rows are counted and excluded, making a repeated --write a reported no-op.

Advanced

pyflightstream.utils.database.Registration dataclass

Registration(
    *,
    target: Edition,
    previous: Edition,
    deltas: tuple[EditionDelta, ...],
    writable: tuple[EditionDelta, ...],
    already_recorded: tuple[str, ...],
    undatabased: tuple[str, ...],
    directory: Path,
    withheld: tuple[EditionDelta, ...] = (),
    written: int = 0,
    chapters: tuple[Path, ...] = tuple(),
)

What one registration would write, and everything it would not.

Returned by :func:register_edition whether or not it wrote, so a dry run and a write report the same object and a caller cannot render a rehearsal that differs from what happens.

Attributes:

Name Type Description
target, previous Edition

The edition being registered and the one it is carried forward from, in that order.

deltas tuple of EditionDelta

Every recorded command, classified. Grouped for a caller by :meth:by_verdict.

writable tuple of EditionDelta

The unchanged commands that do NOT already carry a row for this build, which is exactly what a write touches.

already_recorded tuple of str

Unchanged commands whose entry already records this build. Not an error and not written again.

withheld tuple of EditionDelta

Unchanged commands whose predecessor row is broken or a MEASURED removed (the row cites a run). A reading of the new edition cannot carry that measurement forward, so no row is written for them; each needs a probe on the new build.

undatabased tuple of str

Commands the new edition documents that the database does not record at all. Entering one is a different piece of work from carrying an existing one forward, so they are reported and never written.

written int

Rows actually written; zero on a dry run.

chapters tuple of Path

Chapter files actually written; empty on a dry run.

directory Path

Where the rows would go or did go. A dry run reports it so the rehearsal names its own destination.

by_verdict

by_verdict(
    verdict: EditionVerdict,
) -> tuple[EditionDelta, ...]

Every delta carrying one verdict, in name order.

pyflightstream.utils.database.register_edition

register_edition(
    editions: Sequence[Edition],
    build: str,
    *,
    commands_dir: Path,
    registry: CommandRegistry | None = None,
    reader: Callable[..., Mapping[int, str]] | None = None,
    write: bool = False,
) -> Registration

Write documented rows for the commands a new edition did not change.

Parameters:

Name Type Description Default
editions sequence of Edition

The edition manifest, in release order.

required
build str

Which row of it to register. Must be a manifest label AND a registered build; see this module's docstring for why both.

required
commands_dir Path

Directory holding the chapter files. Point it at a copy to rehearse a write against real data.

required
registry CommandRegistry

The database to classify against, defaulting to the shipped one.

None
reader callable

Page reader, passed through to :func:read_edition, so this function is testable without a pdf and without the [manual] extra.

None
write bool

Write the rows. The default is a rehearsal that opens the manuals, classifies everything and touches nothing.

False

Returns:

Type Description
Registration

What was written, and everything that was not.

Raises:

Type Description
ManualDraftError

If the build is not a manifest label, is the first row of the manifest, is not a registered build, has no citation id, or if any chapter the write would produce is not valid afterwards. A chapter file that cannot be read raises it too. In every case nothing has been written.