repomatic.tabular module¶
Render and persist the flat tables repomatic produces.
Two surfaces, one module, because both are the same shape of data: the CSV
files a repository commits (a scan verdict, a binary in a release, a metric
reading) and the Markdown tables its reports embed (a PR body’s diff table, a
step summary’s tally). render_markdown_table() is the one Markdown table
renderer, so every report agrees on the cell and separator spelling, and
ReportAction is the one vocabulary of its outcome cells. The CSV trio
below decides how the committed datasets are stored.
Note
CSV over JSON for these, on four counts a flat table makes decisive:
Diff churn. A record is one line, not seven. These files are sorted, so a scheduled append lands mid-file rather than at the end: ten new readings cost ten inserted lines instead of seventy.
Size. Roughly half, and the gap widens as a history accrues.
Rendering. MyST’s
csv-tabledirective reads one directly, and GitHub serves a committed CSV through its own searchable grid viewer where JSON is raw text.No formatter contention. Nothing in the autofix lane touches CSV, where a committed JSON file has to be serialized in Biome’s exact style or
format-jsonrewrites it right back.
JSON earns its place where a record nests. None of these do.
- repomatic.tabular.render_csv(headers, rows)[source]¶
Render a header row and its data rows as CSV text.
Newlines are
\non every platform, since the output is committed and a platform-dependent line ending would make the file churn between a Windows and a Unix runner.
- class repomatic.tabular.ReportAction(*values)[source]¶
Bases:
EnumWhat a job did to one item, as the markdown report spells it.
Each member’s value is the emoji-decorated label the report table shows, so a renderer reads the label off the action. No parallel mapping exists for a new member to miss.
The members are the union of the vocabularies every report needs, and each report uses the subset that applies to it: the release-notes sync never unsubscribes, and the notification sweep has nothing to call in sync. What they share is the outcome pair every dry-runnable sweep reports.
- DROPPED = '🗑️ Dropped'¶
- DRY_RUN = '👁️ Dry-run'¶
- FAILED = '⚠️ Failed'¶
- SKIPPED = '✅ In sync'¶
- UNSUBSCRIBED = '🔕 Unsubscribed'¶
- UPDATED = '🔄 Updated'¶
- UPLOADED = '⬆️ Uploaded'¶
- repomatic.tabular.render_markdown_table(headers, rows, align=())[source]¶
Render a GitHub-flavored Markdown table.
Cells are used as given: a caller wanting a code span, a link or an emoji renders it into the cell first. Nothing is escaped, matching what every report renderer did by hand before this existed: none of them ever feeds a cell carrying a
|.- Parameters:
rows (
Iterable[Sequence[object]]) – One sequence of cells per row, in the same order.align (
Sequence[str]) – Per-column alignment,left,rightorcenter; an empty entry (or a list shorter than headers) leaves that column on the parser default. Alignment only changes how a renderer justifies the column, so it is worth declaring where it carries meaning, like a numeric column read against its neighbours.
- Return type:
- Returns:
The table’s lines joined with newlines, no trailing newline.
- Raises:
KeyError – On an alignment name outside the vocabulary.
- repomatic.tabular.read_csv(path)[source]¶
Read a committed CSV into one mapping per row.
Every cell comes back as a string: CSV carries no types, so a caller wanting a number coerces it. A missing file reads as no rows, which is what a first run sees.
- Parameters:
path (
Path) – Path to the CSV file.- Return type:
- Returns:
One mapping per data row, keyed by column name.
- Raises:
ValueError – When the file exists but carries no header row. Loud on purpose: a truncated or half-written file must never be silently treated as empty and clobbered by the next
write_csv().
- repomatic.tabular.load_records(path, from_row, kind)[source]¶
Materialize a committed store through a row parser, loudly.
The committed-dataset counterpart of
read_csv(): one row-to-record pass with one failure contract, so every store fails the same way.- Parameters:
- Return type:
list[RecordT]- Returns:
The parsed records.
- Raises:
ValueError – When the store exists but cannot be parsed. Loud on purpose: a corrupt store must never be silently clobbered by the next write.