reqmodal.py¶
clew/wiki/reqmodal.py
One requirement's whole trace, on its own page (round 3, P1d; round 4, R4).
_ears_line
list[str] clew.wiki.reqmodal._ears_line(Any row, dict entry, dict[str, Any] ctx)
The EARS badge line for a requirement page, when wiki.check.ears is on.
Source · 11 lines
def _ears_line(row: Any, entry: dict, ctx: dict[str, Any]) -> list[str]:
"""@brief Badge on the statement the catalogue gives, else the title. @return Lines."""
if not ctx.get("ears"):
return []
from ..requirements import catalog_value
from .ears import ears_badge, statement_of
statement = statement_of(catalog_value(entry, "acceptance"), row.title)
return [f'<p class="ears-line">{ears_badge(statement)}</p>']
Activity · 6 steps
Requirements
Flows
_evidence_line
list[str] clew.wiki.reqmodal._evidence_line(Any row)
The evidence diagram for a requirement page, and its map overlay link.
Source · 17 lines
def _evidence_line(row: Any) -> list[str]:
"""@brief The diagram in a scrolling figure. @return Lines."""
from urllib.parse import quote
from .reqdiagram import evidence_svg
svg = evidence_svg(row)
lines = [f'<figure class="req-evidence-fig">{svg}</figure>'] if svg else []
## THE OVERLAY (P5.4): only with implementers, so the link never opens an empty map.
if row.implementers:
lines.append(
f'<p class="req-map"><a href="map.html#req={quote(row.req_id, safe="")}">'
"Show on the map</a></p>"
)
return lines
Activity · 7 steps
Requirements
_key
str clew.wiki.reqmodal._key(str req_id)
A requirement id as a modal key.
Source · 7 lines
def _key(req_id: str) -> str:
"""@brief Keep the characters a URL fragment carries. @return Key."""
import re
return re.sub(r"[^\w.:-]", "_", req_id)
Activity · 2 steps
Flows
_what
str clew.wiki.reqmodal._what(Any row, dict entry, dict[str, Any] ctx)
WHAT a requirement asks for, before how it is met (W-9, owner review 2026-11-22).
Called by requirement_pages
Tested by
Source · 41 lines
def _what(row: Any, entry: dict, ctx: dict[str, Any]) -> str:
"""THE REQUIREMENT FIRST: its criteria one per line, the declared facts (tier, status, priority,
verification, rationale, parent), the catalog's own scenario when it declares one (Gherkin,
declared only), and where in the system it lives — the map blocks its implementers sit in, by
count, linked to the map's overlay. Withheld text stays withheld.
@brief The WHAT section.
@return HTML.
"""
rules: Audience = ctx["rules"]
parts = ["<h2>What it requires</h2>"]
if not rules.exclude_requirement_text:
criteria = str(first(entry, "acceptance_criteria", "acceptance", "description") or "")
items = [c for c in _SENTENCE.split(" ".join(criteria.split())) if c]
if items:
parts.append(
'<ol class="criteria">'
+ "".join(f"<li>{md_title(c)}</li>" for c in items)
+ "</ol>"
)
scenario = first(entry, "scenario")
lines = scenario.splitlines() if isinstance(scenario, str) else list(scenario or ())
parts.append(gherkin([" ".join(str(x).split()) for x in lines]))
facts = [("tier", tag(row.tier))]
for label, keys in (
("declared", ("x-status", "status")),
("priority", ("x-priority", "priority")),
("verification", ("verification",)),
("rationale", ("rationale",)),
("parent", ("parent",)),
):
value = first(entry, *keys)
if value:
facts.append((label, text(str(value))))
parts.append(
'<dl class="req-facts">' + "".join(f"<dt>{k}</dt><dd>{v}</dd>" for k, v in facts) + "</dl>"
)
parts.append(_where(row, ctx.get("blocks") or {}))
return '<section class="req-what">' + "".join(parts) + "</section>"
Activity · 18 steps
Requirements
Flows
first
Any clew.wiki.reqmodal.first(dict entry, *str keys)
The first of several keys a catalog entry carries.
Called by _body, _requirement_table, _requirements, _what, _words, requirement_cell, requirement_pages
Calls none
Source · 6 lines
def first(entry: dict, *keys: str) -> Any:
"""@brief Look up. @return Value."""
for key in keys:
if entry.get(key):
return entry[key]
return ""1 more lines, not shown
Activity · 4 steps
Requirements
Flows
issue_links
str clew.wiki.reqmodal.issue_links(list issues, bool titled=False)
Open issues as links: inline ( #12, #13 ) or as a list with titles.
Source · 12 lines
def issue_links(issues: list, titled: bool = False) -> str:
"""@brief Issue links. @return HTML."""
if not issues:
return ""
if not titled:
return ", ".join(f'<a href="{text(i.url)}">#{text(i.id)}</a>' for i in issues)
items = "".join(
f'<li><a href="{text(i.url)}">#{text(i.id)}</a> {text(i.title)}</li>' for i in issues
)
return f'<ul class="modal-list">{items}</ul>'
Activity · 6 steps
Requirements
page_of
str clew.wiki.reqmodal.page_of(str req_id)
The page name of a requirement.
Called by _badges, _body, _by_requirement, _line, _reqs, requirement_cell, requirement_pages
Calls _key
Source · 5 lines
def page_of(req_id: str) -> str:
"""@brief Page name. @return Name."""
return "req-" + _key(req_id)
Activity · 1 steps
Requirements
Flows
requirement_cell
str clew.wiki.reqmodal.requirement_cell(Any row, dict entry, dict[str, Any] ctx)
The requirement's cell: its id linking to its page, and its title under it.
Source · 15 lines
def requirement_cell(row: Any, entry: dict, ctx: dict[str, Any]) -> str:
"""@brief Id, title and modal. @return HTML."""
rules: Audience = ctx["rules"]
title = (
"" if rules.exclude_requirement_text else (row.title or str(first(entry, "name", "title")))
)
cell = (
f'<span class="rid" id="{text(row.req_id)}">'
f'<a href="{text(page_of(row.req_id))}.html">{text(row.req_id)}</a></span>'
)
if title:
cell += f'<div class="rtitle">{text(title)}</div>'
return cell
Activity · 6 steps
Requirements
requirement_pages
list[str] clew.wiki.reqmodal.requirement_pages(Any trace, dict[str, Any] ctx, Any source)
Write one page per requirement.
Called by requirements_page
Calls _ears_line, _evidence_line, _what, first, md_title, page_of
Source · 43 lines
def requirement_pages(trace: Any, ctx: dict[str, Any], source: Any) -> list[str]:
"""ORPHAN PAGES (linked from the index, not from the toctree), one per requirement, so a
requirement is a URL a reader can share and the index stays a table.
@brief Write req-*.md.
@return Names.
"""
from pathlib import Path
rules: Audience = ctx["rules"]
names = []
for row in trace.evidence:
entry = trace.declared.get(row.req_id, {})
title = (
""
if rules.exclude_requirement_text
else (row.title or str(first(entry, "name", "title")))
)
name = page_of(row.req_id)
heading = f"{row.req_id}: {title}" if title else row.req_id
lines = [
"---",
"orphan: true",
"---",
"",
f"# {md_title(heading)}",
"",
"```{raw} html",
'<p class="crumbs"><a href="requirements.html">← Requirements</a></p>',
*_ears_line(row, entry, ctx),
## W-9 (owner review 2026-11-22): WHAT it requires, then HOW it is met.
_what(row, entry, ctx),
"<h2>How it is met</h2>",
*_evidence_line(row),
f'<div class="req-page">{_body(row, entry, title, ctx)}</div>',
"```",
"",
]
(Path(source) / f"{name}.md").write_text("\n".join(lines), encoding="utf-8")
names.append(name)
return names
Activity · 12 steps
Requirements
Flows
test_link
str clew.wiki.reqmodal.test_link(str name, dict[str, str] hrefs)
A test's name, linked to its section when it has one.
Source · 6 lines
def test_link(name: str, hrefs: dict[str, str]) -> str:
"""@brief Link a test. @return HTML."""
href = hrefs.get(name)
return f'<a href="{text(href)}">{code(name)}</a>' if href else code(name)
Activity · 2 steps
Requirements
via
str clew.wiki.reqmodal.via(Any row, str test)
How a test was linked, when weaker than a tag.
Source · 12 lines
def via(row: Any, test: str) -> str:
"""@brief Link kind. @return HTML."""
for kind, tests in (
("measured", row.measured_tests),
("catalog", row.declared_tests),
("inferred", row.inferred_tests),
):
if test in tests:
return f' <span class="via via-{kind}" title="linked by {kind}">{kind}</span>'
return ""