entities.py

clew/wiki/entities.py

Entity quick views: a modal per function on a flow, with the view strip (round 5, P5.6).

_briefs

dict clew.wiki.entities._briefs(conn)

Each function's brief, from the index.

clew/wiki/entities.py:259

Source · 14 lines
def _briefs(conn) -> dict:  # noqa: ANN001
    """PLAIN TEXT: doxygen stores a brief as XML (`<para>…</para>`), which the quick view printed
    verbatim (found by looking); `strip_xml` is the one cleaner the step modal already uses.

    @brief Read briefs.
    @return Map.
    """
    from ..query._common import strip_xml

    rows = conn.execute(
        "SELECT m.name, p.name, COALESCE(m.briefdescription, '') FROM memberdef m JOIN path p "
        "ON p.rowid = COALESCE(NULLIF(m.bodyfile_id, 0), m.file_id) WHERE m.kind = 'function'"
    )
    return {(str(n), str(f)): " ".join(strip_xml(str(b)).split()) for n, f, b in rows if b}

1 more lines, not shown

Activity · 3 steps
lines 266–266from ..query._common import strip_xmllines 268–271rows = conn.execute( "SELECT m.name, p.name, COALESCE(m.briefdescription, '') FROM memberdef m JOIN path p " "ON p.rowid = COALESCE(NULLIF(m.bodyfile_id, 0), m.file_id) WHERE m.kind = 'function'" )lines 272–272return {(str(n), str(f)): " ".join(strip_xml(str(b)).split()) for n, f, b in rows if b}

Flows

_facts_of

EntityFacts clew.wiki.entities._facts_of(name, rel, flows_of, edges, file_block, test_href, req_of, briefs)

One function's facts from the site's pages and the index.

clew/wiki/entities.py:228

Source · 26 lines
def _facts_of(name, rel, flows_of, edges, file_block, test_href, req_of, briefs) -> EntityFacts:  # noqa: ANN001
    """THE TESTS ARE ITS DIRECT CALLERS that have a test page, from the index's call edges.

    @brief Gather facts.
    @return Facts.
    """
    on = flows_of.get((name, rel), [])
    callers = {
        edges.names[c][0]
        for r in edges.by_key.get((name, rel), ())
        for c in edges.callers.get(r, ())
    }
    return EntityFacts(
        name=name,
        file=rel,
        brief=briefs.get((name, rel), ""),
        block=file_block.get(rel, ""),
        flows=tuple((p.name, p.title) for p in on if p.role != "tests"),
        replays=tuple((p.name, p.title) for p in on if p.role == "tests"),
        tests=tuple((t, test_href[t]) for t in sorted(callers) if t in test_href),
        reqs=tuple(sorted(set(req_of.get((name, rel), ())))),
        page="",
        anchor="",
    )

Activity · 3 steps
lines 234–234on = flows_of.get((name, rel), [])lines 235–239callers = { edges.names[c][0] for r in edges.by_key.get((name, rel), ()) for c in edges.callers.get(r, ()) }lines 240–251return EntityFacts( name=name, file=rel, brief=briefs.get((name, rel), ""), block=file_block.get(rel, ""), flows=tuple((p.name, p.title) for p in on if p.role != "tests"), replays=tuple((p.name, p.title) for p in on if p.role == "tests"), tests=tuple((t, test_href[t]) for t in sorted(callers) if t in test_href), reqs=tuple(sorted(set(req_of.get((name, rel), ())))), page="", anchor="", )

Flows

_list

str clew.wiki.entities._list(tuple[tuple[str, str],...] items, str home, str empty, bool code=False)

A capped list of (label, page) links, or the sentence for none.

clew/wiki/entities.py:126

Show on the map →

Called by quick_view

Calls none

Source · 13 lines
def _list(items: tuple[tuple[str, str], ...], home: str, empty: str, code: bool = False) -> str:
    """@brief First `_SHOWN`, then the count of the rest. @return HTML."""
    if not items:
        return f'<p class="none">{escape(empty)}</p>'
    wrap = (lambda s: f"<code>{escape(s)}</code>") if code else escape
    lis = "".join(
        f'<li><a href="{escape(p)}.html">{wrap(label)}</a></li>' for label, p in items[:_SHOWN]
    )
    more = len(items) - _SHOWN
    tail = f'<p class="more"><a href="{home}">{more} more on its page</a></p>' if more > 0 else ""
    return f"<ul>{lis}</ul>{tail}"

Activity · 7 steps
lines 128–128◇ if not itemslines 129–129return f'<p class="none">{escape(empty)}</p>'lines 130–130wrap = (lambda s: f"<code>{escape(s)}</code>") if code else escapelines 131–133lis = "".join( f'<li><a href="{escape(p)}.html">{wrap(label)}</a></li>' for label, p in items[:_SHOWN] )lines 134–134more = len(items) - _SHOWNlines 135–135tail = f'<p class="more"><a href="{home}">{more} more on its page</a></p>' if more > 0 else ""lines 136–136return f"<ul>{lis}</ul>{tail}"

Flows

_map

str clew.wiki.entities._map(EntityFacts facts)

The Map view: where the function sits, and a link that flies there.

clew/wiki/entities.py:102

Show on the map →

Called by quick_view

Calls none

Source · 6 lines
def _map(facts: EntityFacts) -> str:
    """@brief The map focuses `name@file` (`web.js`'s `#n=`). @return HTML."""
    target = quote(f"{facts.name}@{facts.file}", safe="")
    return f'<p><a href="map.html#n={target}">Show it on the map</a>, in its block\'s wedge.</p>'

Activity · 2 steps
lines 104–104target = quote(f"{facts.name}@{facts.file}", safe="")lines 105–105return f'<p><a href="map.html#n={target}">Show it on the map</a>, in its block\'s wedge.</p>'

Flows

_reqs

str clew.wiki.entities._reqs(tuple[str,...] reqs)

The requirement badges, or the sentence for none.

clew/wiki/entities.py:144

Source · 13 lines
def _reqs(reqs: tuple[str, ...]) -> str:
    """@brief Badges linking each requirement's page. @return HTML."""
    if not reqs:
        return '<p class="none">No requirement names this function as an implementer.</p>'
    from .reqmodal import page_of

    return (
        "<p>"
        + " ".join(f'<a class="req-badge" href="{page_of(r)}.html">{escape(r)}</a>' for r in reqs)
        + "</p>"
    )

Activity · 4 steps
lines 146–146◇ if not reqslines 147–147return '<p class="none">No requirement names this function as an implementer.</p>'lines 148–148from .reqmodal import page_oflines 150–154return ( "<p>" + " ".join(f'<a class="req-badge" href="{page_of(r)}.html">{escape(r)}</a>' for r in reqs) + "</p>" )

Flows

_titled

tuple[tuple[str, str], ...] clew.wiki.entities._titled(tuple[tuple[str, str],...] pages)

(page, title) pairs as the (label, page) pairs _list draws.

clew/wiki/entities.py:113

Show on the map →

Called by quick_view

Calls none

Source · 5 lines
def _titled(pages: tuple[tuple[str, str], ...]) -> tuple[tuple[str, str], ...]:
    """@brief Swap. @return Pairs."""
    return tuple((title, page) for page, title in pages)

Activity · 1 steps
lines 115–115return tuple((title, page) for page, title in pages)

Flows

quick_view

str clew.wiki.entities.quick_view(EntityFacts facts)

The quick view's HTML: the strip, then one panel per view.

clew/wiki/entities.py:64

Source · 33 lines
def quick_view(facts: EntityFacts) -> str:
    """@brief Strip and panels. @return HTML."""
    home = f"{facts.page}#{facts.anchor}"
    panels = {
        "map": _map(facts),
        "block": f"<p><strong>{escape(facts.block)}</strong> is the block holding "
        f"<code>{escape(facts.file)}</code>.</p>"
        if facts.block
        else f"<p>No block holds <code>{escape(facts.file)}</code>.</p>",
        "flow": _list(_titled(facts.flows), home, "No flow on this site calls this function."),
        "replay": _list(_titled(facts.replays), home, "No recorded run reaches this function."),
        "source": f'<p><a href="{home}">Its page</a>: signature, body, callers and callees. '
        f'<a href="{facts.page}#act-{facts.anchor}">Its activity diagram</a>.</p>',
        "tests": _list(
            tuple((n, h.removesuffix(".html")) for n, h in facts.tests),
            home,
            "No test calls this function directly.",
            code=True,
        ),
        "reqs": _reqs(facts.reqs),
    }
    strip = "".join(
        f'<button type="button" class="view-tab" data-view="{v}">{_LABELS[v]}</button>'
        for v in VIEWS
    )
    body = "".join(
        f'<section class="view" data-view-panel="{v}"><h4>{_LABELS[v]}</h4>{panels[v]}</section>'
        for v in VIEWS
    )
    brief = f'<p class="brief">{escape(facts.brief)}</p>' if facts.brief else ""
    return f'{brief}<nav class="views" aria-label="Views">{strip}</nav>{body}'

Activity · 6 steps
lines 66–66home = f"{facts.page}#{facts.anchor}"lines 67–84panels = { "map": _map(facts), "block": f"<p><strong>{escape(facts.block)}</strong> is the block holding " f"<code>{escape(facts.file)}</code>.</p>" if facts.block else f"<p>No block holds <code>{escape(facts.file)}</code>.</p>", "flow": _list(_titled(facts.flows), home, "No flow on this site calls this function."), "replay": _list(_titled(facts.replays), home, "No recorded run reaches this function."), "source": f'<p><a href="{home}">Its page</a>: signature, body, callers and callees. ' f'<a href="{facts.page}#act-{facts.anchor}">Its activity diagram</a>.</p>', "tests": _list( tuple((n, h.removesuffix(".html")) for n, h in facts.tests), home, "No test calls this function directly.", code=True, ), "reqs": _reqs(facts.reqs), }lines 85–88strip = "".join( f'<button type="button" class="view-tab" data-view="{v}">{_LABELS[v]}</button>' for v in VIEWS )lines 89–92body = "".join( f'<section class="view" data-view-panel="{v}"><h4>{_LABELS[v]}</h4>{panels[v]}</section>' for v in VIEWS )lines 93–93brief = f'<p class="brief">{escape(facts.brief)}</p>' if facts.brief else ""lines 94–94return f'{brief}<nav class="views" aria-label="Views">{strip}</nav>{body}'

Requirements

REQ-DDB-WIKI-048

Flows

write_quick_views

int clew.wiki.entities.write_quick_views(db, source, list pages, dict file_block, dict test_href, dict req_of)

Append each flow page's quick views: a trigger and a template per function on it.

clew/wiki/entities.py:168

Source · 48 lines
def write_quick_views(
    db, source, pages: list, file_block: dict, test_href: dict, req_of: dict
) -> int:  # noqa: ANN001
    """A SECOND PASS, after every flow and test page exists: a quick view lists the OTHER flows a
    function is on and the tests that call it, which no single flow page knows while it is drawn.
    The page's own text is untouched; the section is appended to its source before rendering.

    @brief Write quick views.
    @return Count.
    """
    from pathlib import Path

    from ..query._common import connect
    from .htmltable import plural
    from .modal import modal
    from .symbols import _Edges, anchor, symbol_href

    with connect(db) as conn:
        edges = _Edges(conn)
        briefs = _briefs(conn)
    flows_of: dict = {}
    for p in pages:
        for key in p.functions:
            flows_of.setdefault(key, []).append(p)
    written = 0
    for page in pages:
        items = []
        for i, (name, rel) in enumerate(sorted(page.functions, key=lambda k: (k[1], k[0]))):
            facts = _facts_of(name, rel, flows_of, edges, file_block, test_href, req_of, briefs)
            href, _a = symbol_href(name, rel).split("#", 1)
            facts = EntityFacts(**{**facts.__dict__, "page": href, "anchor": anchor(name)})
            items.append(f"<li>{modal(f'q-{i}', name, f'{name} ({rel})', quick_view(facts))}</li>")
            written += 1
        if items:
            block = (
                "\n## Quick views\n\n```{raw} html\n"
                ## A-1 (UX review, owner Q/A 2026-11-22): folded under its count (3,527 px on
                ## clew's dossier flow); a quick view still opens from inside the fold.
                f'<details class="fold quick-fold"><summary>{plural(len(items), "function")}, each '
                f'with its quick view</summary><ul class="modal-list quick-views">{"".join(items)}'
                "</ul></details>\n"
                '<script src="_static/clew-views.js"></script>\n```\n'
            )
            path = Path(source) / f"{page.name}.md"
            path.write_text(path.read_text(encoding="utf-8") + block, encoding="utf-8")
    return written

Activity · 26 steps
lines 178–178from pathlib import Pathlines 180–180from ..query._common import connectlines 181–181from .htmltable import plurallines 182–182from .modal import modallines 183–183from .symbols import _Edges, anchor, symbol_hreflines 185–185with connect(db) as connlines 186–186edges = _Edges(conn)lines 187–187briefs = _briefs(conn)lines 188–188flows_of: dict = {}lines 189–189◇ for p in pageslines 190–190◇ for key in p.functionslines 191–191flows_of.setdefault(key, []).append(p)lines 192–192written = 0lines 193–193◇ for page in pageslines 194–194items = []lines 195–195◇ for i, (name, rel) in enumerate(sorted(page.functions, key=lambda k: (k[1], k[0])))lines 196–196facts = _facts_of(name, rel, flows_of, edges, file_block, test_href, req_of, briefs)lines 197–197href, _a = symbol_href(name, rel).split("#", 1)lines 198–198facts = EntityFacts(**{**facts.__dict__, "page": href, "anchor": anchor(name)})lines 199–199items.append(f"<li>{modal(f'q-{i}', name, f'{name} ({rel})', quick_view(facts))}</li>")lines 200–200written += 1lines 201–201◇ if itemslines 202–210block = ( "\n## Quick views\n\n```{raw} html\n" ## A-1 (UX review, owner Q/A 2026-11-22): folded under its count (3,527 px on ## clew's dossier flow); a quick view still opens from inside the fold. f'<details class="fold quick-fold"><summary>{plural(len(items), "function")}, each ' f'with its quick view</summary><ul class="modal-list quick-views">{"".join(items)}' "</ul></details>\n" '<script src="_static/clew-views.js"></script>\n```\n' )lines 211–211path = Path(source) / f"{page.name}.md"lines 212–212path.write_text(path.read_text(encoding="utf-8") + block, encoding="utf-8")lines 213–213return written

Requirements

REQ-DDB-WIKI-048

Flows