29 lines
1.5 KiB
Python
29 lines
1.5 KiB
Python
"""How todo-item prints items: as rows of the table `rank_todo.py --help` shows, whatever backend holds the plan, without the Score a markdown plan alone has."""
|
|
from release_plan.todo_table import BLOCKED_BY, Item, OLD_SHAPE, SHAPE, Shape
|
|
from release_plan.release import version
|
|
|
|
|
|
def table(items: list[Item]) -> str:
|
|
"""A markdown table of items, in their order."""
|
|
shape = shape_of(items)
|
|
columns = [column for column in shape.columns if column != "Score"]
|
|
return "\n".join(["| " + " | ".join(columns) + " |", "|" + "---|" * len(columns), *(row(item, shape) for item in items)])
|
|
|
|
|
|
def shape_of(items: list[Item]) -> Shape:
|
|
"""OLD_SHAPE where an item holds a score only that shape has, as a plan not yet reshaped does."""
|
|
return OLD_SHAPE if any(set(item.scores) - set(SHAPE.score_columns) for item in items) else SHAPE
|
|
|
|
|
|
def row(item: Item, shape: Shape) -> str:
|
|
named = {"ID": item.id, "Release": version(item.release), BLOCKED_BY: ", ".join(str(id_) for id_ in item.blocked_by), "Exempt": item.exempt, "Item": item.tagline, shape.goals_column: shape.write_goals(item.moves), **item.scores}
|
|
return "| " + " | ".join(str(named.get(column, "")) for column in shape.columns if column != "Score") + " |"
|
|
|
|
|
|
def shown(item: Item) -> str:
|
|
"""item's row under the table's header, then its detail under the heading a markdown plan gives it; the row alone where it has no detail."""
|
|
if not item.detail:
|
|
return table([item])
|
|
tagline = item.tagline.removeprefix("**").removesuffix("**").replace("\\|", "|")
|
|
return f"{table([item])}\n\n### {item.id}. {tagline}\n\n{item.detail}"
|