Skip to content

pyflightstream.utils (stable)

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

Maintainer utilities that are not part of a run.

Pipeline role: none. Nothing in the run pipeline imports this subpackage, which is what keeps it outside the layer rule rather than at a position within it (CONTRIBUTING.md Layout, AD-01).

The modules occupy two dependency layers. :mod:~pyflightstream.utils.manual and :mod:~pyflightstream.utils.errors import nothing from this package and sit at the bottom beside :mod:pyflightstream._errors, so they can be used from any layer. :mod:~pyflightstream.utils.cli is an ENTRY POINT above :mod:pyflightstream.commands, which it reads to answer what the database already records, the same shape as :mod:pyflightstream.reference.

What belongs here is the work of KEEPING the package current rather than of using it: reading a new vendor manual, comparing it against the command database, reporting what a new release added. That work runs on the maintainer's machine against licensed material in _private/.

pyfs-manual register writes documented version rows for commands a manual supports. Other proposals remain drafts for review.

The layer statement above is unchanged by it, and the split is why. :func:~pyflightstream.utils.manual.insert_version_row takes the text of a chapter file and returns the edited text; it opens nothing.

The registration I/O lives in :mod:~pyflightstream.utils.database. It reads and writes chapter bytes and validates every edit against the command schema before writing any of them.

SO THIS SUBPACKAGE HAS THREE POSITIONS, not the two the statement above enumerates: manual and errors at the bottom, and cli and database above :mod:pyflightstream.commands. database is deliberately NOT re-exported from this module, and that is load bearing rather than an oversight: re-exporting it would make import pyflightstream.utils pull :mod:pyflightstream.commands in, and cost manual the property that it can be used from any layer. Import it by its own name.

What does NOT belong here is anything a user's run depends on. A helper that a script, a campaign or a parser needs is part of that layer and belongs in it; putting it here would make utils a bag that everything reaches into, which is the shape this subpackage is most at risk of becoming.

Advanced

pyflightstream.utils.CommandEntryLike

Bases: Protocol

The one field :func:stale_citations reads off a command entry.

versions property

versions: Mapping[str, VersionRowLike]

Evidence per canonical version identifier.

pyflightstream.utils.Coverage dataclass

Coverage(
    absent: tuple[str, ...] = (),
    recorded: tuple[str, ...] = (),
    undocumented: tuple[str, ...] = (),
    details: dict[str, ManualCommand] = dict(),
)

What one manual says that the database does not, and the reverse.

Attributes:

Name Type Description
absent tuple of str

Documented by the manual and not recorded in the database.

recorded tuple of str

In both.

undocumented tuple of str

Recorded in the database and not found in this manual. Not an error by itself: a command removed by a later build, or one documented only in another edition, lands here.

summary

summary() -> str

One sentence a maintainer can paste into a session note.

pyflightstream.utils.Edition dataclass

Edition(
    *,
    label: str,
    manual: Path,
    chapter: tuple[int, int],
    index: tuple[int, int] | None = None,
    source: str | None = None,
)

One manual to read, and where its two chapters sit in it.

A registered FlightStream build and the pdf that documents it. The page ranges are per edition because scripting-reference pagination differs between manuals.

KEYWORD-ONLY, and that is about chapter and index specifically. They are two page ranges of the same type, so positionally they are interchangeable and swapping them constructs cleanly: the sweep then reads the Script Index as the scripting reference, reports hundreds of false absences, and nothing anywhere can detect it. Named arguments are the only thing that separates them.

Attributes:

Name Type Description
label str

Canonical version identifier, for example "26.121". Used only to name the edition in the report; nothing resolves it against the version registry, so an unregistered build can be swept before it is added.

manual Path

Path of the manual pdf. Licensed vendor material, given explicitly and never guessed, and never committed.

chapter tuple of int

First and last page of the scripting reference, one-based inclusive.

index tuple of int or None

First and last page of the Script Index, if the edition has one. It supplies the section label only, so an edition without one is swept with its commands unlabelled rather than skipped.

source str or None

Citation id of this edition, for example "FSM-26.100", as a manual_ref would spell it.

pyflightstream.utils.EditionDelta dataclass

EditionDelta(
    *,
    name: str,
    verdict: EditionVerdict,
    page: int | None = None,
    previous_page: int | None = None,
    differs_in: tuple[str, ...] = (),
)

What a new edition says about one command, against its predecessor.

Produced by :func:documentation_delta, one per command the database records, so a caller can tell the five states apart without re-deriving them.

KEYWORD-ONLY, and that is about page and previous_page specifically, exactly as it is for :class:Edition's two page ranges. They are two fields of the same type sitting adjacent, so positionally they are interchangeable and swapping them constructs cleanly: :attr:repaginated still answers true, and the caller writes the PREDECESSOR's page into a row citing the new edition's source. That is a wrong citation in the shipped database with every guard green, and nothing but the keyword separates the two.

Attributes:

Name Type Description
name str

Command name.

verdict EditionVerdict

Which of the five states this command is in.

page int or None

Page of the NEW edition, where it documents the command. None where this edition does not document it at all.

previous_page int or None

Page of the predecessor, where it did. None where the predecessor did not document it.

differs_in tuple of str

For changed only, which of args, sample, parameters and description moved. Empty for every other verdict, an arrival included: an arrival differs in nothing, it is new. It names the FIELDS and never their content: the parameter prose is licensed manual text and is read at run time, never carried into anything written (invariant 1).

repaginated property

repaginated: bool

True where the command moved page without changing.

pyflightstream.utils.EditionVerdict

Bases: StrEnum

Closed vocabulary for one command's relationship to a predecessor edition.

Five values distinguish unchanged, changed, arrived, dropped and absent commands. Callers can decide which rows to write without rechecking the predecessor mapping or reconstructing missing distinctions.

pyflightstream.utils.ManualCallError

Bases: PyflightstreamError, TypeError

A drafting function was called with the wrong argument shape.

The library raises nothing of this class today. propose_type takes its two strings as keywords only (PFS-2022.05), so a call with the strings positional, twice or missing raises Python's own TypeError, which is what the signature itself refuses with. The class stays in the catalogue for callers that name it.

TypeError as the second base, because that is what a wrong call shape raised before the catalogue held a class for it, and what a caller written against it would still catch (FR-39).

pyflightstream.utils.ManualCommand dataclass

ManualCommand(
    name: str,
    page: int,
    inline_args: tuple[str, ...] = (),
    sample: tuple[str, ...] = (),
    section: str | None = None,
    parameters: Mapping[str, str] = dict(),
    description: str = "",
)

One command as the manual describes it, before any judgement.

Attributes:

Name Type Description
name str

Command name as printed.

page int

Page of the manual that introduces it, one-based, as a reader would cite it in a manual_ref.

inline_args tuple of str

Placeholder names from the signature line, in order. These are the arguments written on the command's own line. Arguments that continue onto following lines do not appear here, which is the single largest reason a proposal needs review.

sample tuple of str

The lines of the sample block, comment lines removed. The first is the command with its inline arguments; any further line is a continuation, and the shape of those lines is what :func:propose_layout reads.

section str or None

Section the Script Index files it under, when an index was parsed and named it.

parameters mapping of str to str

The manual's own parameter table, placeholder name to the prose describing it, for the commands that carry one. This is the third source, after the signature and the sample, and it is the only one that says anything about an argument's TYPE. The prose is licensed manual text: it is read at run time from the pdf the caller passes and is never written into anything this module renders (invariant 1), which is why :func:propose_type returns a conclusion and a structural reason rather than a quotation.

description str

The complete command block, ending at the next signature, with whitespace normalized and page-number footers removed. Compared at runtime only; renderers never reproduce this licensed text.

continuation_lines property

continuation_lines: tuple[str, ...]

Sample lines after the first, which the signature never shows.

pyflightstream.utils.ManualDraftError

Bases: PyflightstreamError, ValueError

A draft was asked for something a manual cannot support.

Raised where the caller asks the drafting functions to record more than the source they are reading can justify, the sharp case being a verified or broken status: those are promoted from a committed probe report by pyfs-qa apply-compat, never from a page citation (CONTRIBUTING.md invariant 3).

ValueError as the second base, because that is what this refusal raised before the catalogue existed and what a caller written against it would still catch (FR-39).

pyflightstream.utils.Reachability dataclass

Reachability(
    *,
    findings: tuple[UnreachableCommand, ...],
    unmeasured: tuple[str, ...],
)

What a reachability sweep found, and what it could not look at.

Two fields rather than one tuple, because an edition whose label the registry cannot resolve is not a command and was being reported as one: it entered the findings with the string (every command) in the command field, so the CLI counted it in "N command(s) an edition documents that its build cannot emit" and --fail-if-absent failed on it. That is a build nobody has registered yet, which Edition.label explicitly promises can be swept.

Attributes:

Name Type Description
findings tuple of UnreachableCommand

One per command an edition documents that its build cannot emit. Empty when every edition read is complete.

unmeasured tuple of str

Labels the version registry could not turn into exactly one build, either unregistered or a vendor alias several builds share. Nothing is known about their commands, which is a different statement from knowing they cannot be emitted.

pyflightstream.utils.RegistryLike

Bases: Protocol

What the citation and reachability checks need of the database.

Both attributes, because the two checks need different halves: :func:stale_citations walks commands and :func:unreachable_commands also asks for_version what a build can emit. The protocol therefore requires both attributes.

commands property

commands: Mapping[str, CommandEntryLike]

Every entry, keyed by command name.

for_version

for_version(version: Any) -> Any

Return the per-version view of the database.

pyflightstream.utils.StaleCitation dataclass

StaleCitation(
    *,
    command: str,
    edition: str,
    cited: int,
    found: int | None,
    reason: str,
)

A version row whose cited page does not hold the command.

Attributes:

Name Type Description
command str

Command name the row belongs to.

edition str

Label of the edition the row cites.

cited int

Page number written in the row's note.

found int or None

Page the edition actually prints the signature on, or None.

reason str

Which finding this is, because found is None alone carried two of them and the report printed one: "moved" when the edition prints the command elsewhere, "absent" when it does not print it at all, and "wrong source" when the note names another edition's source id. The three want different repairs. A moved page is a citation to correct, an absent command is a row that should not exist, and a wrong source is a row read against the wrong document.

pyflightstream.utils.SurfaceChange dataclass

SurfaceChange(
    *,
    older: str,
    newer: str,
    gained: tuple[str, ...],
    lost: tuple[str, ...],
)

What one build's scripting surface gained and lost against the one before it.

Attributes:

Name Type Description
older str

Label of the earlier edition.

newer str

Label of the later edition.

gained tuple of str

Commands the later edition documents and the earlier one does not, sorted.

lost tuple of str

Commands the earlier edition documents and the later one does not, sorted. Lost means the later manual stops printing the command, which is not the same as the solver refusing it: a command can disappear from a manual and keep working. Deciding which happened needs a probe, so this is evidence for a question rather than an answer to it.

pyflightstream.utils.SweptCommand dataclass

SweptCommand(
    name: str,
    editions: tuple[str, ...],
    pages: dict[str, int],
    section: str | None,
    detail: ManualCommand,
)

One command as the whole set of editions describes it.

Attributes:

Name Type Description
name str

Command name as printed.

editions tuple of str

Labels of the editions whose chapter body documents it, in the order the editions were given. A command absent from this tuple for a given edition is one that edition does not document, which is the fact a version row must reflect.

pages dict of str to int

Page carrying the signature, per edition label. The pages differ per edition and each version row cites its own.

section str or None

Section that documents it, from the first edition whose index names it.

detail ManualCommand

What the newest edition given states about it, for drafting.

pyflightstream.utils.TYPE_RULES module-attribute

TYPE_RULES: tuple[TypeRule, ...] = (
    TypeRule(
        "opening",
        "the description opens with what the value is",
        _read_opening,
    ),
    TypeRule(
        "integer-word",
        "the description says the value is whole",
        _read_integer_word,
    ),
    TypeRule(
        "dimension",
        "the parameter carries a physical dimension",
        _read_dimension,
    ),
    TypeRule(
        "enumeration",
        "the description enumerates the accepted tokens",
        _read_enumeration,
    ),
    TypeRule(
        "alternatives",
        "the description spells the alternatives with 'or'",
        _read_alternatives,
    ),
    TypeRule(
        "toggle",
        "the description offers the two toggle tokens",
        _read_toggle,
    ),
)

pyflightstream.utils.TypeRule dataclass

TypeRule(
    name: str,
    reason: str,
    read: Callable[
        [str, str], tuple[str, tuple[str, ...]] | None
    ],
)

One rule of :func:propose_type, and its position in the order.

Rules form an ordered list. Their precedence is part of the inference contract and is visible to both readers and tests.

Attributes:

Name Type Description
name str

Short identifier, used by the tests that pin the order.

reason str

What :func:propose_type reports when this rule answers.

read callable

Takes the upper-cased placeholder and the description, and returns (type, values) or None for "this rule has nothing to say".

pyflightstream.utils.UnreachableCommand dataclass

UnreachableCommand(
    *, command: str, edition: str, reason: str
)

A command an edition documents that its build cannot emit.

Attributes:

Name Type Description
command str

Command name as the edition prints it.

edition str

Label of the edition that documents it.

reason str

"no entry" when the database has no entry of that name at all, or "refused" when it has one and the version view refuses it, which means no row for this build and none reachable by hotfix inheritance. Those two and no others: an edition whose label cannot be resolved is not a command and is reported through :attr:Reachability.unmeasured instead, having been a third value of this field for one commit.

pyflightstream.utils.VersionRowLike

Bases: Protocol

The two fields :func:stale_citations reads off a version row.

Declared as a protocol rather than left implicit, because this module sits below commands in the dependency order and cannot import the real type. Every read of that type was a getattr with a swallowing default, so renaming VersionStatus.note would have made the check return no findings forever with a green suite; the tier-1 test asserting the real registry satisfies this is what turns that silence into a red.

note property

note: str | None

Paraphrased justification, where the row carries one.

status property

status: object

The row's evidence status, read through its value.

pyflightstream.utils.coverage_against

coverage_against(
    manual: Mapping[str, ManualCommand],
    *,
    recorded: Iterable[str],
) -> Coverage

Compare a parsed manual against the names the database records.

Parameters:

Name Type Description Default
manual mapping of str to ManualCommand

Output of :func:parse_signatures.

required
recorded iterable of str

Command names the database holds, typically CommandRegistry.load().commands.

required

Returns:

Type Description
Coverage

The three sets, each sorted, plus the parsed detail of every absent command so a maintainer can start writing entries without re-reading the manual.

pyflightstream.utils.documentation_delta

documentation_delta(
    previous: Mapping[str, ManualCommand],
    current: Mapping[str, ManualCommand],
    *,
    recorded: Iterable[str],
) -> tuple[EditionDelta, ...]

Classify every recorded command against two parsed editions.

THE COMPARISON IS OF WHAT THE EDITION SAYS, not of where it says it, and that is the whole reason this function exists. A rule keyed on the page number cannot see a command that moved: a local reflow repaginates a run of commands by one, and under a page rule every one of them falls out of a bulk pass although most are word for word what they were. Comparing the parsed records handles it and is sensitive to changes anywhere in the command block. Whitespace and page-number footers are normalized; an unchanged page number is not evidence of unchanged text.

Parameters:

Name Type Description Default
previous mapping of str to ManualCommand

Output of :func:read_edition for the predecessor and the new edition, in that order.

required
current mapping of str to ManualCommand

Output of :func:read_edition for the predecessor and the new edition, in that order.

required
recorded iterable of str

Command names the database holds. Commands the new edition documents that are not among these are not classified here; a caller reports them separately, because entering a new command is a different piece of work from carrying an existing one forward.

required

Returns:

Type Description
tuple of EditionDelta

One per recorded command, sorted by name.

pyflightstream.utils.edition_surfaces

edition_surfaces(
    editions: Iterable[Edition],
    *,
    reader: Callable[..., Mapping[int, str]] | None = None,
) -> dict[str, tuple[str, ...]]

Read each edition and return the command names it documents.

The whole surface, not the part the database lacks, which is what :func:manual_editions reports. Both read the chapter body the same way, and the difference is the question: a sweep asks what is missing from the database, this asks what each build documents so two builds can be compared.

Parameters:

Name Type Description Default
editions iterable of Edition

The manuals to read. Order is preserved in the result and is the caller's to choose; :func:surface_changes compares consecutive entries, so the intended order is release order.

required
reader callable

What turns a manual and a page range into text, defaulting to :func:read_pdf_pages. Same seam as :func:manual_editions, for the same reason.

None

Returns:

Type Description
dict of str to tuple of str

Command names per edition label, sorted within each edition, with the editions in the order given.

Raises:

Type Description
ManualDraftError

If no edition is given, or if two editions share a label. A duplicate label would silently overwrite the first reading and report a build compared against itself.

pyflightstream.utils.insert_version_row

insert_version_row(
    text: str,
    *,
    command: str,
    canonical: str,
    status: str,
    note: str,
) -> str

Insert one single-line version row into a chapter file's text.

The function renders its row through :func:pyflightstream._yamlflow.flow_mapping. It accepts no pre-rendered YAML, so escaping and validation remain within the library.

KEYWORD-ONLY after the text, for the reason the neighbouring :class:Edition is: command, canonical, status and note are four strings, so positionally they are interchangeable and a swap of the middle two constructs cleanly.

AT THE END OF THE BLOCK rather than in release order, and that is deliberate: the existing rows are NOT in release order in every entry, so inserting by order would reorder files this has no business reordering.

Preserve all bytes outside the inserted row, including each line's existing terminator. In particular, do not normalize CRLF chapters to LF while inserting a version row.

Parameters:

Name Type Description Default
text str

The chapter file, whole.

required
command str

Entry to edit. Its versions: block is found under it.

required
canonical str

Build the row is for. Refused if the entry already has one.

required
status str

Evidence status for that build, written as a bare token. This function does NOT judge it: which statuses exist and which may be written from a reading is the command database's rule and the caller's to obey (CONTRIBUTING.md invariant 3).

required
note str

Provenance of the row, quoted and escaped on the way in. A citation, for example "FSM-26.123 p.290, unchanged from FSM-26.122 p.289".

required

Returns:

Type Description
str

The edited text.

Raises:

Type Description
ManualDraftError

If the entry is not in this file, has no versions: block, or already records that build in either shape. Refusing rather than rewriting: a block-form row carries a note and possibly an argument override, and writing a second key beside it makes YAML keep the last and drop the first, silently.

pyflightstream.utils.manual_editions

manual_editions(
    editions: Iterable[Edition],
    *,
    recorded: Iterable[str],
    reader: Callable[..., Mapping[int, str]] | None = None,
) -> tuple[SweptCommand, ...]

Read every manual edition and report what none of them has an entry for.

manual_editions is the public Python API; pyfs-manual sweep is the CLI subcommand that calls it.

The multi-edition form of :func:coverage_against, and it exists because the single-edition one answers a question no sweep asks. A command absent from one edition may be recorded from another, and a command the database lacks must be entered for EVERY edition that documents it at once (the chapter rule in docs/srs/data-model.md). Both need the union, so reading the editions one at a time and comparing four reports by eye is the step this removes.

Reading is body-driven: the signature headings of the chapter are the command set, and the Script Index is consulted only for section labels. That is not interchangeable with reading the index, which is incomplete: NEW_CCS_WING_FLAP_COVE has a heading on p.299 of one edition and no index row, so an index-driven sweep reports it covered forever.

Parameters:

Name Type Description Default
editions iterable of Edition

The manuals to read, oldest first by convention so that :attr:SweptCommand.detail carries the newest statement.

required
recorded iterable of str

Command names the database holds, typically CommandRegistry.load().commands. Keyword-only, so a call cannot pass the two collections the wrong way round.

required
reader callable

What turns a manual and a page range into text, defaulting to :func:read_pdf_pages. It is a parameter because this module keeps its parsing testable without a pdf and without the [manual] extra, which is the seam :func:read_pdf_pages documents about itself; this is the first function above that line to need a manual, so it takes the reader rather than reaching for it and leaving the seam to be maintained by monkeypatching.

None

Returns:

Type Description
tuple of SweptCommand

Every command documented by at least one edition and recorded by none, sorted by name.

Raises:

Type Description
ManualDraftError

If no edition is given. With no manual read, nothing can be documented and the answer is zero absent, which is indistinguishable from the complete database this is run to confirm. A configuration error that reads as the good outcome is the one shape worth refusing outright.

pyflightstream.utils.parse_script_index

parse_script_index(
    pages: Mapping[int, str],
) -> dict[str, str]

Read the manual's own Script Index into command and section.

The index is the authoritative command list: it is the vendor's enumeration rather than a heuristic over headings, which is why it is preferred over scanning the chapter.

Parameters:

Name Type Description Default
pages mapping of int to str

Extracted text of the index pages, keyed by one-based page number. Pass only the index pages; passing the whole manual would admit body text that happens to match the line shape.

required

Returns:

Type Description
dict of str to str

Command name to the section naming it, first occurrence winning.

pyflightstream.utils.parse_signatures

parse_signatures(
    pages: Mapping[int, str],
    *,
    sections: Mapping[str, str] | None = None,
) -> dict[str, ManualCommand]

Read every command's signature and sample from the scripting chapter.

Parameters:

Name Type Description Default
pages mapping of int to str

Extracted text of the scripting reference pages, keyed by one-based page number.

required
sections mapping of str to str

Output of :func:parse_script_index, used only to fill :attr:ManualCommand.section.

None

Returns:

Type Description
dict of str to ManualCommand

Command name to what the manual states about it. First definition wins, so a later cross-reference cannot overwrite the page a reader should cite.

Notes

The pages are read as one stream, preserving samples and parameter tables across page boundaries.

It was found by comparing two editions of one manual, where the consequence is sharp. The vendor repaginated one chapter by a page, which split DISABLE_WAKE_NODES_ON_TRAILING_EDGE across a break in the newer edition alone; the comparison then read a full record against a truncated one and reported a documentation change the vendor had not made. Worse in the other direction: with 22 commands of that edition truncated, three deliberately planted grammar edits below a break all compared EQUAL, so a real vendor change would have been carried forward as "same grammar".

The page a command is CITED at is still the page carrying its signature line, which is what a reader turns to.

A line that is nothing but its own page number is dropped while the stream is built. It is the extraction's footer, and joined into the stream it lands in the middle of a block and reads as content: 20 commands had one as the first line of their sample.

pyflightstream.utils.propose_layout

propose_layout(command: ManualCommand) -> tuple[str, str]

Suggest a database layout for a command, with the reason.

A PROPOSAL, and the second element says what it was read from so a reviewer can disagree cheaply. The five layouts are the database's own vocabulary: bare, inline, param_lines, payload_lines and keyword_block.

Parameters:

Name Type Description Default
command ManualCommand

The command as the manual reader parsed it.

required

Returns:

Type Description
tuple of str

(layout, why). why is a sentence naming the evidence, and is never empty, including when the answer is a guess.

pyflightstream.utils.propose_type

propose_type(
    *, placeholder: str, description: str
) -> tuple[str | None, tuple[str, ...], str]

Suggest an argument type from the manual's parameter table.

Both strings are keyword-only (PFS-2022.05). A positional Python call raises TypeError; naming placeholder and description prevents accidentally exchanging two otherwise valid strings.

The parameter table supplies type information absent from signatures and samples. An unknown type remains unresolved so the caller can write ??? rather than invent a type.

The rules are tried in a stated order and the order is load-bearing. A counting or indexing opening decides before either enum rule, because both enum rules read tokens out of a sentence and a count whose description mentions two alternatives is still a count. Both enum rules then read only the sentence carrying the phrase that introduces the set.

Nothing of the description reaches the return value. The reason is a sentence about the SHAPE the rule matched, not a paraphrase of the manual, so a draft carries no licensed text (invariant 1).

Parameters:

Name Type Description Default
placeholder str

Parameter name as the manual prints it, for example "NUM_BOUNDARIES".

required
description str

The manual's prose for that parameter, as :attr:ManualCommand.parameters holds it.

required

Returns:

Type Description
tuple

(type, values, reason). type is a database ArgType value, or None when no rule matched. values is the token tuple of an enum and empty otherwise. reason says which rule answered, or why none did.

Raises:

Type Description
TypeError

A positional call, which Python itself refuses on this signature.

pyflightstream.utils.read_edition

read_edition(
    edition: Edition,
    *,
    reader: Callable[..., Mapping[int, str]] | None = None,
) -> dict[str, ManualCommand]

Parse one edition's scripting reference, sections included.

Parameters:

Name Type Description Default
edition Edition

A row of the edition manifest.

required
reader callable

Page reader, defaulting to :func:read_pdf_pages. It is a parameter for the same reason it is one on :func:manual_editions and :func:edition_surfaces: this module keeps its parsing testable without a pdf and without the [manual] extra. It was omitted when this function was written, which left the one code path in this repository that writes hundreds of database rows with no end-to-end test.

None

Returns:

Type Description
dict of str to ManualCommand

What that edition states about each command it documents.

pyflightstream.utils.read_edition_manifest

read_edition_manifest(
    path: str | Path,
) -> tuple[Edition, ...]

Read an edition manifest, the file that makes a sweep repeatable.

The manifest is a list of mappings with the keys of :class:Edition, chapter and index written as FIRST-LAST. It is a file rather than repeated command-line flags because it is the thing a new build EDITS: registering one is adding a row, and the row is then under the maintainer's own version control rather than retyped from a session note.

It is never committed here. It names paths of licensed manuals, and those live in _private/ (CONTRIBUTING.md invariant 1).

Named for the manifest and not for the editions, unlike the neighbouring :func:read_pdf_pages: this opens a small text file and returns descriptors, and opens no manual at all.

Parameters:

Name Type Description Default
path str or Path

Manifest file, YAML.

required

Returns:

Type Description
tuple of Edition

In the order written.

Raises:

Type Description
ManualDraftError

If the file is not a list of mappings, if a row lacks label, manual or chapter, carries a key outside the five, has a label or source that YAML did not read as non-blank text (an unquoted 26.120 is the number 26.12, a blank source: is null), names a manual that does not exist, or writes a page range that is not FIRST-LAST with FIRST no greater than LAST. Every check names the offending row, because a manifest is edited rarely and by hand. Check every row before opening any manual.

Examples:

A manifest with one edition, as it would be written by hand::

- label: "26.121"
  source: FSM-26.121
  manual: _private/manual/user-manual-26121.pdf
  chapter: 284-379
  index: 380-386

pyflightstream.utils.read_pdf_pages

read_pdf_pages(
    path: str | Path, *, first: int, last: int
) -> dict[int, str]

Extract the text of a page range from a manual pdf.

Separated from every function above so the parsing is testable without a pdf and without the optional dependency: everything else in this module takes text.

Require a valid, keyword-only range of one-based page numbers. Reversed bounds must not produce an empty mapping that coverage would interpret as a manual documenting no commands; zero must not index the last PDF page or produce a p.0 citation.

Parameters:

Name Type Description Default
path str or Path

The manual. It is licensed vendor material, lives in _private/ and never enters Git (CONTRIBUTING.md invariant 1); only paraphrases and page citations derived from it are committed.

required
first int

One-based, inclusive page range. Keyword-only.

required
last int

One-based, inclusive page range. Keyword-only.

required

Returns:

Type Description
dict of int to str

Extracted text keyed by one-based page number, one entry per page of the requested range.

Raises:

Type Description
ManualDraftError

If the range is not one-based and ascending, or if it reaches past the end of the document. A short read is never returned.

MissingExtraError

When the manual extra is not installed.

pyflightstream.utils.render_chapter

render_chapter(
    commands: Iterable[ManualCommand],
    *,
    source: str,
    versions: Mapping[str, str],
) -> str

Render several entries as one chapter file body, sorted by name.

Parameters:

Name Type Description Default
commands iterable of ManualCommand

The entries to render.

required
source str

Manual source id for the citation, for example FSM-26.100.

required
versions mapping of str to str

Canonical version to status, as :func:render_entry takes it.

required

Returns:

Type Description
str

The chapter header, then one entry per command, sorted by name.

pyflightstream.utils.render_entry

render_entry(
    command: ManualCommand,
    *,
    source: str,
    versions: Mapping[str, str],
    phase: str | None = None,
) -> str

Render one command as a database entry, for a person to review.

Parameters:

Name Type Description Default
command ManualCommand

Parsed entry, from :func:parse_signatures.

required
source str

Manual source id for the citation, for example "FSM-26.100".

required
versions mapping of str to str

Canonical version to status. Only documented is meaningful from a manual: verified and broken need a committed probe report and this function will not write them (invariant 3).

required
phase str

Overrides the phase proposed from the section.

None

Returns:

Type Description
str

YAML for one entry, with ??? wherever the manual does not answer, so an unreviewed draft cannot load: the database schema refuses those values and the suite goes red rather than green over a guess.

Raises:

Type Description
ManualDraftError

If a status other than documented is requested, since a manual is not probe evidence. A ValueError as well, so a caller written before the catalogue still catches it.

pyflightstream.utils.sample_contradiction

sample_contradiction(
    command: ManualCommand,
    *,
    index: int,
    proposed: str | None,
    values: tuple[str, ...] = (),
) -> str | None

Report the sample token a proposed type would refuse.

The parameter table is not the only thing the manual says about an argument: the page also PRINTS a call. A proposal read from the table alone is therefore a reading of one source that another source on the same page can already falsify, and this is that second reading.

What it does NOT claim is that the manual contradicts itself. Four causes produce the same signal and only a person can tell them apart: the table offered "label or number" and only the labels were read; the table is genuinely incomplete; the sample is a typo; or the argument list is out of step with the signature so the compared token belongs to a different argument. All four mean the proposal must not be written, which is the only decision this function makes.

A parameter table can disagree with its sample. CAD_BODY_ROTATE has a parameter table naming the three axis letters and a sample calling it with the index 2, on the same page, in every edition; three SWEEPER_SET_*_SWEEP commands omit a mode their own samples use.

Why this belongs here rather than in a review checklist: both facts are already in :class:ManualCommand, so the tool had everything it needed and compared nothing. The earlier measurement that certified :func:propose_type as never disagreeing with a hand-authored type could not have caught this, because those entries were authored from the same parameter table; the tool and the reviewer read one source and agreed with each other about it.

Parameters:

Name Type Description Default
command ManualCommand

Parsed entry. Its sample supplies the evidence and its inline_args the positions.

required
index int

ZERO-based position in command.inline_args. Keyword-only, along with everything after it, because a call reading sample_contradiction(cmd, 1, "enum", ("X", "Y")) says nothing about which of those is which.

required
proposed str or None

Type :func:propose_type returned, or None when no rule answered. None is never contradicted: an unanswered argument refuses nothing.

required
values tuple of str

Token set of an enumeration proposal.

()

Returns:

Type Description
str or None

The token the sample passes at that position, when the proposed type would refuse it. None when the proposal accepts the token, and also when the sample cannot answer: a command with no sample, a sample whose first line is not the call, or a call with fewer tokens than the signature has placeholders. Those three are silent rather than reported because the absence of a sample is not evidence of agreement, and a caller that treated None as confirmation would be reading it as one.

Raises:

Type Description
ManualDraftError

If index is outside the command's own argument list. It used to index the sample tokens directly, so a caller passing the 1-based position a person reads off the manual page got a confident report about the NEXT argument's token, phrased exactly like a real finding. A caller bug must not be able to produce a plausible sentence.

pyflightstream.utils.stale_citations

stale_citations(
    editions: Iterable[Edition],
    *,
    recorded: RegistryLike,
    reader: Callable[..., Mapping[int, str]] | None = None,
) -> tuple[StaleCitation, ...]

Check every version row's page citation against the manual it names.

Check that cited pages still match the manual's command locations. A regenerated conversion can shift pagination while leaving a cited page number valid but pointing to the wrong command.

Parameters:

Name Type Description Default
editions iterable of Edition

The manuals to check against. The manual side comes first and the database is keyword-only, matching :func:manual_editions and :func:coverage_against; two adjacent positional parameters of unrelated kinds is a call nobody can read.

required
recorded RegistryLike

The loaded database, used through .commands. Typed loosely because this module sits below commands in the dependency order (CONTRIBUTING.md Layout) and must not import it, which is also why the check cannot default to loading it.

required
reader callable

What turns a manual and a page range into text, defaulting to :func:read_pdf_pages. Same seam as :func:edition_surfaces.

None

Returns:

Type Description
tuple of StaleCitation

One entry per disagreeing row, sorted by command then edition.

Raises:

Type Description
ManualDraftError

If no edition is given, or if two editions share a label, or if the mapping exposes no version rows at all. All three are configuration errors that would otherwise return an empty tuple, and an empty tuple from this function reads as a clean bill.

Notes

Three classes of row are NOT checked, and silence about a row is therefore never a claim that the row is right.

A removed row is skipped: its citation addresses an ABSENCE and names the pages the command is not on, so checking it the same way would report every honest removal record as a defect.

A row whose note carries no page cannot be checked, and most rows do not carry one. Neither can a row whose edition the manifest does not list, and that one differs in kind from the other three: the run has no reading to check it against, so it is not an outcome of this check at all.

Each run records how the rows it saw ended, in :data:citation_reach, one count per outcome of :data:CITATION_REACH_OUTCOMES per edition. Those four partition the rows seen for that edition, so a caller can say WHY a row went unchecked rather than inferring one reason for all of them (OPS-2003.10.02). Rows of an unlisted edition appear in none of the four, for the reason in the paragraph above.

A note citing a page RANGE is satisfied by any page in it. Twenty-six shipped rows cite one, and reading only the first page of a span reports a correct citation as wrong whenever the signature heading sits on the second.

The SOURCE is checked too, where the manifest records one: a note citing FSM-26.120 on a row keyed to the edition FSM-26.121 was reading a different document, and page numbers between those two differ by a uniform three, so a coincidence is cheap.

pyflightstream.utils.surface_changes

surface_changes(
    surfaces: Mapping[str, Iterable[str]],
) -> tuple[SurfaceChange, ...]

Compare each edition's command surface with the one before it.

Parameters:

Name Type Description Default
surfaces mapping of str to iterable of str

Command names per edition label, in release order. Python mappings preserve insertion order and this relies on it, so a caller that sorts the labels as strings gets the wrong neighbours: "26.100" sorts before "26.101" by luck, and "26.12" sorts after both as a string.

required

Returns:

Type Description
tuple of SurfaceChange

One entry per consecutive pair, empty when fewer than two editions are given.

pyflightstream.utils.unreachable_commands

unreachable_commands(
    editions: Iterable[Edition],
    *,
    recorded: RegistryLike,
    reader: Callable[..., Mapping[int, str]] | None = None,
) -> Reachability

Report, per edition, the documented commands its build cannot emit.

This is the row-level half of the coverage question, and it exists because the entry-level half cannot answer it. :func:manual_editions compares the manuals against the set of entry NAMES, so an entry that exists but carries no row for one edition is invisible to it: the sweep reports zero absent while that build's emitter refuses a command the caller's own manual documents.

Reachability, not row presence, is the measure, because a genuine hotfix inherits its base release's records: 26.122 carries twenty direct rows and reaches 375, and counting rows would report it as missing hundreds.

Parameters:

Name Type Description Default
editions iterable of Edition

The manuals to read.

required
recorded RegistryLike

The loaded database. Typed loosely because this module sits below commands in the dependency order (CONTRIBUTING.md Layout) and must not import it; it is used through .commands and .for_version.

required
reader callable

What turns a manual and a page range into text, defaulting to :func:read_pdf_pages.

None

Returns:

Type Description
Reachability

Its findings are sorted by edition then command and empty means every command every readable edition documents can be emitted for that build. Its unmeasured names the editions whose label the registry could not resolve, about which nothing was learned either way.

Raises:

Type Description
ManualDraftError

If no edition is given, or if two editions share a label. Same two refusals as :func:edition_surfaces and for the same reason: with no edition every command is vacuously reachable, which is a configuration error reading as the good outcome.

pyflightstream.utils.write_chapter

write_chapter(
    body: str,
    *,
    path: str | Path,
    write: bool = False,
    overwrite: bool = False,
) -> str

Write a drafted chapter, but only when asked.

The default is a dry run, and the reason is the measurement in this module's own docstring: the drafts reproduce 77 percent of hand-authored argument lists, so writing them unreviewed into the database the emitter validates against would put invented grammar in front of other people's scripts.

Parameters:

Name Type Description Default
body str

Output of :func:render_chapter.

required
path (str or Path, keyword - only)

Destination. Point it at a scratch file to review before moving anything into src/pyflightstream/commands/. Keyword-only to prevent exchanging the destination with the chapter body.

required
write (bool, keyword - only)

False, the default, writes nothing. True writes body to path.

False
overwrite (bool, keyword - only)

False, the default, refuses a path that already exists, so a reviewed draft or a shipped chapter is never replaced by accident. True replaces it.

False

Returns:

Type Description
str

A sentence saying what happened, for a caller to print.

Raises:

Type Description
ManualDraftError

If write is True, path exists and overwrite is False.