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.

clew/wiki/reqmodal.py:366

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
lines 368–368◇ if not ctx.get("ears")lines 369–369return []lines 370–370from ..requirements import catalog_valuelines 371–371from .ears import ears_badge, statement_oflines 373–373statement = statement_of(catalog_value(entry, "acceptance"), row.title)lines 374–374return [f'<p class="ears-line">{ears_badge(statement)}</p>']

Requirements

REQ-DDB-WIKI-042

Flows

_evidence_line

list[str] clew.wiki.reqmodal._evidence_line(Any row)

The evidence diagram for a requirement page, and its map overlay link.

clew/wiki/reqmodal.py:342

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
lines 344–344from urllib.parse import quotelines 346–346from .reqdiagram import evidence_svglines 348–348svg = evidence_svg(row)lines 349–349lines = [f'<figure class="req-evidence-fig">{svg}</figure>'] if svg else []lines 351–351◇ if row.implementerslines 352–355lines.append( f'<p class="req-map"><a href="map.html#req={quote(row.req_id, safe="")}">' "Show on the map</a></p>" )lines 356–356return lines

Requirements

REQ-DDB-WIKI-022

_key

str clew.wiki.reqmodal._key(str req_id)

A requirement id as a modal key.

clew/wiki/reqmodal.py:531

Show on the map →

Called by page_of

Calls none

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
lines 533–533import relines 535–535return re.sub(r"[^\w.:-]", "_", req_id)

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).

clew/wiki/reqmodal.py:124

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
lines 133–133rules: Audience = ctx["rules"]lines 134–134parts = ["<h2>What it requires</h2>"]lines 135–135◇ if not rules.exclude_requirement_textlines 136–136criteria = str(first(entry, "acceptance_criteria", "acceptance", "description") or "")lines 137–137items = [c for c in _SENTENCE.split(" ".join(criteria.split())) if c]lines 138–138◇ if itemslines 139–143parts.append( '<ol class="criteria">' + "".join(f"<li>{md_title(c)}</li>" for c in items) + "</ol>" )lines 144–144scenario = first(entry, "scenario")lines 145–145lines = scenario.splitlines() if isinstance(scenario, str) else list(scenario or ())lines 146–146parts.append(gherkin([" ".join(str(x).split()) for x in lines]))lines 147–147facts = [("tier", tag(row.tier))]lines 148–148◇ for label, keys in (lines 155–155value = first(entry, *keys)lines 156–156◇ if valuelines 157–157facts.append((label, text(str(value))))lines 158–160parts.append( '<dl class="req-facts">' + "".join(f"<dt>{k}</dt><dd>{v}</dd>" for k, v in facts) + "</dl>" )lines 161–161parts.append(_where(row, ctx.get("blocks") or {}))lines 162–162return '<section class="req-what">' + "".join(parts) + "</section>"

Requirements

REQ-DDB-WIKI-022

Flows

first

Any clew.wiki.reqmodal.first(dict entry, *str keys)

The first of several keys a catalog entry carries.

clew/wiki/reqmodal.py:544

Show on the map →

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
lines 546–546◇ for key in keyslines 547–547◇ if entry.get(key)lines 548–548return entry[key]lines 549–549return ""

Requirements

REQ-DDB-WIKI-022

Flows

page_of

str clew.wiki.reqmodal.page_of(str req_id)

The page name of a requirement.

clew/wiki/reqmodal.py:331

Show on the map →

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
lines 333–333return "req-" + _key(req_id)

Requirements

REQ-DDB-WIKI-022

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.

clew/wiki/reqmodal.py:43

Show on the map →

Called by _requirement_table

Calls first, page_of, text

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
lines 45–45rules: Audience = ctx["rules"]lines 46–48title = ( "" if rules.exclude_requirement_text else (row.title or str(first(entry, "name", "title"))) )lines 49–52cell = ( 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>' )lines 53–53◇ if titlelines 54–54cell += f'<div class="rtitle">{text(title)}</div>'lines 55–55return cell

Requirements

REQ-DDB-WIKI-022

requirement_pages

list[str] clew.wiki.reqmodal.requirement_pages(Any trace, dict[str, Any] ctx, Any source)

Write one page per requirement.

clew/wiki/reqmodal.py:387

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
lines 394–394from pathlib import Pathlines 396–396rules: Audience = ctx["rules"]lines 397–397names = []lines 398–398◇ for row in trace.evidencelines 399–399entry = trace.declared.get(row.req_id, {})lines 400–404title = ( "" if rules.exclude_requirement_text else (row.title or str(first(entry, "name", "title"))) )lines 405–405name = page_of(row.req_id)lines 406–406heading = f"{row.req_id}: {title}" if title else row.req_idlines 407–424lines = [ "---", "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>', "```", "", ]lines 425–425(Path(source) / f"{name}.md").write_text("\n".join(lines), encoding="utf-8")lines 426–426names.append(name)lines 427–427return names

Requirements

REQ-DDB-WIKI-022

Flows

via

str clew.wiki.reqmodal.via(Any row, str test)

How a test was linked, when weaker than a tag.

clew/wiki/reqmodal.py:466

Show on the map →

Called by none

Calls none

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 ""

Activity · 4 steps
lines 468–468◇ for kind, tests in (lines 473–473◇ if test in testslines 474–474return f' <span class="via via-{kind}" title="linked by {kind}">{kind}</span>'lines 475–475return ""

Requirements

REQ-DDB-WIKI-022