Answer architecture round 1: 0 🔴, 8 🟡; read old routes' rungs, write R in rank_todo, route reviews through review_rungs, file item 168

This commit is contained in:
2026-10-16 12:11:25 +02:00
parent 149108e8d8
commit 12909f233d
20 changed files with 141 additions and 94 deletions
+15 -16
View File
@@ -76,7 +76,7 @@ import re
import sys
import typing
from todo_table import BLOCKED_BY, cells, HEADER_START, Item, items_table, MOVES, OLD_SHAPE, parse_row, Shape, SHAPE, shape_of, Table, table_rows
from todo_table import BLOCKED_BY, cells, HEADER_START, Item, items_table, MOVES, OLD_SHAPE, parse_row, risk, Shape, SHAPE, shape_of, Table, table_rows
from failure import Failure
from markdown_text import FENCE, sections
from file_writes import replace_file
@@ -290,31 +290,29 @@ def read_table(lines: list[str]) -> Table | Failure:
return Failure(f"## Items holds no table whose header opens {HEADER_START}; rank_todo.py --help shows a valid one")
if isinstance(table, Failure):
return table
# A table without its shape's risk scores fails, so no chunk starts on an unscored item.
if shape_of(table.columns) is OLD_SHAPE and "C" not in table.columns:
return Failure("todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help")
if shape_of(table.columns) is SHAPE and not {"L", "E", "I"} <= set(table.columns):
old = older_columns(table)
shape = shape_of(table.columns)
if missing := [column for column in shape.risk_columns if column not in table.columns]:
old = older_columns(table, shape)
dropped = f", and drop {joined(old)}" if old else ""
return Failure(f"todo.md's items table has no L, E and I columns; add them before R, score each item's L, E and I as rank_todo.py --help shows{dropped}")
return unknown_columns(table) or outside_items(lines, table) or table
columns = f"{joined(missing)} column; add it" if len(missing) == 1 else f"{joined(missing)} columns; add them"
return Failure(f"todo.md's items table has no {columns}, scoring each item's {joined(list(shape.risk_columns))} as rank_todo.py --help shows{dropped}")
return unknown_columns(table, shape) or outside_items(lines, table) or table
def unknown_columns(table: Table) -> Failure | None:
def unknown_columns(table: Table, shape: Shape) -> Failure | None:
"""Why ranking, which writes only the columns of the table's shape, would drop one of the table's columns; None when it would drop none."""
known = shape_of(table.columns).columns
unknown = [column for column in table.columns if column not in known]
if old := older_columns(table):
unknown = [column for column in table.columns if column not in shape.columns]
if old := older_columns(table, shape):
kind = "a column of an older shape; drop it" if len(old) == 1 else "columns of an older shape; drop them"
return Failure(f"todo.md's items table has {joined(old)}, {kind}, as rank_todo.py --help shows")
if unknown:
return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; the columns it knows are {', '.join(known)}. Rename it, or move this machine to the release that added it")
return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; the columns it knows are {', '.join(shape.columns)}. Rename it, or move this machine to the release that added it")
return None
def older_columns(table: Table) -> list[str]:
def older_columns(table: Table, shape: Shape) -> list[str]:
"""The table's columns that only OLD_SHAPE knows, where the table is in SHAPE."""
return [column for column in table.columns if column not in SHAPE.columns and column in OLD_SHAPE.columns] if shape_of(table.columns) is SHAPE else []
return [column for column in table.columns if column not in SHAPE.columns and column in OLD_SHAPE.columns] if shape is SHAPE else []
def joined(names: list[str]) -> str:
@@ -569,7 +567,8 @@ def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure:
return Failure(f"item {item.id} cites goal {goal}, which README.md's ## Goals does not number")
if scoring.goals[goal] == "Maintain" and item.exempt != "defect":
return Failure(f"item {item.id} cites goal {goal}, a maintain goal, which only a defect that restores it may name; name the achieve goals the item moves")
return item
# R is written here, as the Score is, so --check finds a stale one, and a reader keeps the R the table stored.
return dataclasses.replace(item, scores=item.scores | {"R": risk(item.scores["L"], item.scores["E"], item.scores["I"])})
def render_item(item: Item, value: float, shape: Shape) -> str: