build.py

clew/wiki/build.py

`clew wiki build`: a self-contained static site, rendered by Sphinx + MyST.

_actor_of

str clew.wiki.build._actor_of(Any spec, WikiConfig config)

Who starts a flow, for its actor lane (P5.6).

clew/wiki/build.py:1297

Show on the map →

Called by _build_site

Calls none

Source · 17 lines
def _actor_of(spec: Any, config: WikiConfig) -> str:
    """FROM WHERE THE SPEC CAME: a test flow is started by the test runner, a thread entry by its
    thread, a console script (title `script — `func``) by a command-line user, a discovered `main`
    by a program launcher; a flow the repository declares by its caller.

    @brief Actor of a flow.
    @return Name.
    """
    if spec.role == "tests":
        return "test runner"
    if spec.role == "threads":
        return "thread start"
    if spec in config.flows:
        return "caller"
    return "command-line user" if " — " in (spec.title or "") else "program launcher"

Activity · 7 steps
lines 1305–1305◇ if spec.role == "tests"lines 1306–1306return "test runner"lines 1307–1307◇ if spec.role == "threads"lines 1308–1308return "thread start"lines 1309–1309◇ if spec in config.flowslines 1310–1310return "caller"lines 1311–1311return "command-line user" if " — " in (spec.title or "") else "program launcher"

Requirements

REQ-DDB-WIKI-047

Flows

_all_flows

list clew.wiki.build._all_flows(Path repo_root, Path db, WikiConfig config)

The declared flows, then every entry point's flow not already declared.

clew/wiki/build.py:600

Source · 20 lines
def _all_flows(repo_root: Path, db: Path, config: WikiConfig) -> list:
    """A DECLARED FLOW WINS for its function: its title, depth and lanes are the repository's
    choice, so the derived one for the same entry is dropped.

    @brief Declared + entry-point flows.
    @return Specs.
    """
    from .entrypoints import entry_point_flows

    specs = list(config.flows)
    if config.entry_point_depth > 0:
        declared = {(s.entry, s.file) for s in specs} | {(s.entry, None) for s in specs}
        specs += [
            s
            for s in entry_point_flows(db, repo_root, config.entry_point_depth)
            if (s.entry, s.file) not in declared and (s.entry, None) not in declared
        ]
    return specs

Activity · 6 steps
lines 607–607from .entrypoints import entry_point_flowslines 609–609specs = list(config.flows)lines 610–610◇ if config.entry_point_depth > 0lines 611–611declared = {(s.entry, s.file) for s in specs} | {(s.entry, None) for s in specs}lines 612–616specs += [ s for s in entry_point_flows(db, repo_root, config.entry_point_depth) if (s.entry, s.file) not in declared and (s.entry, None) not in declared ]lines 617–617return specs

Flows

_architecture_entries

list clew.wiki.build._architecture_entries(Path db, Path repo_root, WikiConfig config, dict flow_of)

The entry points, as the Architecture page reads them.

clew/wiki/build.py:1267

Source · 24 lines
def _architecture_entries(db: Path, repo_root: Path, config: WikiConfig, flow_of: dict) -> list:
    """THE KIND FROM THE DISCOVERY that found it: a console script's title is `script — `func``,
    a thread entry carries the `threads` role, anything else is a `main`.

    @brief Classify entry points.
    @return Entries.
    """
    from .architecture import Entry
    from .entrypoints import entry_point_flows

    out = []
    for spec in entry_point_flows(db, repo_root, config.entry_point_depth):
        if spec.role == "threads":
            kind, label = "thread", ""
        elif " — " in spec.title:
            kind, label = "script", spec.title.split(" — ", 1)[0]
        else:
            kind, label = "main", ""
        ## THE SAME ROLE THE FLOWS GET (`_with_role`): a `tooling`-glob entry is not a container.
        role = _with_role(spec, config).role
        out.append(Entry(kind, spec.entry, spec.file or "", label, flow_of.get(spec.entry), role))
    return out

Activity · 13 steps
lines 1274–1274from .architecture import Entrylines 1275–1275from .entrypoints import entry_point_flowslines 1277–1277out = []lines 1278–1278◇ for spec in entry_point_flows(db, repo_root, config.entry_point_depth)lines 1279–1279◇ if spec.role == "threads"lines 1280–1280kind, label = "thread", ""lines 1281–1281◇ elif " — " in spec.titlelines 1282–1282kind, label = "script", spec.title.split(" — ", 1)[0]lines 1283–1283elselines 1284–1284kind, label = "main", ""lines 1286–1286role = _with_role(spec, config).rolelines 1287–1287out.append(Entry(kind, spec.entry, spec.file or "", label, flow_of.get(spec.entry), role))lines 1288–1288return out

Requirements

REQ-DDB-WIKI-046

_audience

Audience clew.wiki.build._audience(WikiConfig config, str|None audience)

The rules for the requested audience.

clew/wiki/build.py:655

Source · 10 lines
def _audience(config: WikiConfig, audience: str | None) -> Audience:
    """@brief Resolve an audience. @return Rules."""
    if audience is None:
        return Audience()
    if audience not in config.audiences:
        known = ", ".join(sorted(config.audiences)) or "none declared"
        raise ValueError(f"unknown audience {audience!r} (known: {known})")
    return config.audiences[audience]

Activity · 6 steps
lines 657–657◇ if audience is Nonelines 658–658return Audience()lines 659–659◇ if audience not in config.audienceslines 660–660known = ", ".join(sorted(config.audiences)) or "none declared"lines 661–661raise ValueError(f"unknown audience {audience!r} (known: {known})")lines 662–662return config.audiences[audience]

Flows

_build_site

Path clew.wiki.build._build_site(Path repo_root, Path db, Path out_dir, str|None audience=None, str|None version=None, Path|None config_path=None, Path|None summary=None)

Write and render the site.

clew/wiki/build.py:138

Source · 120 lines
def _build_site(
    repo_root: Path,
    db: Path,
    out_dir: Path,
    audience: str | None = None,
    version: str | None = None,
    config_path: Path | None = None,
    summary: Path | None = None,
) -> Path:
    """REFUSES rather than degrades: an invalid section, an unknown audience or a missing extra is
    an error naming itself, never a partial site that looks complete.

    @brief Write and render the site.
    @return The HTML directory.
    @version 1
    """
    from .architecture import architecture_page
    from .flowpage import flow_page, flows_index
    from .impactpage import impact_page
    from .graph import build_graph
    from .issues import resolve_target
    from .web import minimap_html, web_page
    from . import testfacts
    from .imports import parse_features
    from .adr import find_decisions
    from .exports import write_exports
    from .tracerun import load_traces, root_name, trace_for
    from .symbols import symbol_pages
    from .testpages import test_pages
    from .evidence import parse_junit
    from .tracepages import Trace, nodes_page, requirements_page
    from .versions import record_version, valid_key

    repo_root, out_dir = Path(repo_root), Path(out_dir)
    config, problems = load_wiki_config(repo_root, config_path)
    if problems:
        raise ValueError("wiki configuration problems: " + "; ".join(problems))
    rules = _audience(config, audience)
    site_dir = out_dir / valid_key(version) if version else out_dir
    source = site_dir / "_source"
    if source.exists():
        shutil.rmtree(source)
    source.mkdir(parents=True)
    commit = _commit(repo_root)
    if commit_published(repo_root, commit) is False:
        config = dataclasses.replace(config, link_template="")
    trace = Trace.gather(repo_root, db, config, commit)
    snapshot = trace.snapshot(version or "")
    milestones = _milestones(repo_root, config)
    burndown = _burndown(out_dir, version, snapshot, milestones) if version else ""
    req_of = _requirements_of(trace.evidence)
    facts = testfacts.gather(trace.evidence)
    traces = {
        root_name(otlp): (rel, otlp) for rel, otlp in load_traces(repo_root, config.inputs.traces)
    }
    test_specs = _test_flows(db, facts, frozenset(traces), config.trace_depth)
    specs = [*_all_flows(repo_root, db, config), *test_specs]
    coverage = _coverage(repo_root, config)
    ## P5.6: THE GRAPH BEFORE THE FLOWS, so a flow's block lanes are the map's blocks.
    graph = build_graph(
        db,
        trace.evidence,
        trace.impact,
        config.components,
        exclude_tests=True,
        component_depth=config.component_depth,
    )
    blocks = graph.get("file_block") or {}
    pages, not_drawn, flow_of = [], [], {}
    for s in specs:
        try:
            pages.append(
                flow_page(
                    repo_root,
                    db,
                    _with_role(s, config),
                    source,
                    rules,
                    config,
                    commit,
                    req_of,
                    ## X-2: a master flow takes the subtree a traced test reached under it.
                    trace_for(s.entry, traces),
                    coverage,
                    blocks,
                    _actor_of(s, config),
                )
            )
            flow_of.setdefault(s.entry, pages[-1].name)
        except ValueError as refused:
            ## Round 4: a DISCOVERED flow that cannot be drawn is listed with its reason; a
            ## DECLARED one is the repository's own statement and still fails the build.
            if s in config.flows:
                raise
            not_drawn.append((s.entry, s.file or "", str(refused)))
    unmatched = tuple(
        (rel, root)
        for root, (rel, _o) in sorted(traces.items())
        if root not in {s.entry for s in specs}
    )
    keys = {(n, f) for r in trace.evidence for n, f, _l in r.implementer_sites}
    keys |= {fn for p in pages for fn in p.functions}
    symbol_ctx = {
        ## V6 (owner Q/A 2026-11-20): how many body lines a symbol page bundles.
        "body_lines": config.body_lines,
        "req_of": req_of,
        "flows": pages,
        "rules": rules,
        "template": config.link_template,
        ## R5-CFG C3 (2.0.0): ONE test → implementer path depth for the symbol and test pages.
        "path_depth": config.path_depth,
        "commit": commit,
        "tests": facts,
        "implementers": {
            r.req_id: {(n, f) for n, f, _l in r.implementer_sites} for r in trace.evidence
        },
    }
    written = symbol_pages(db, repo_root, keys, symbol_ctx, source)
    scenarios = parse_features(repo_root, config.inputs.features)
    written |= testfacts.feature_pages(repo_root, scenarios, facts, source)

120 more lines, not shown

Activity · 90 steps
lines 154–154from .architecture import architecture_pagelines 155–155from .flowpage import flow_page, flows_indexlines 156–156from .impactpage import impact_pagelines 157–157from .graph import build_graphlines 158–158from .issues import resolve_targetlines 159–159from .web import minimap_html, web_pagelines 160–160from . import testfactslines 161–161from .imports import parse_featureslines 162–162from .adr import find_decisionslines 163–163from .exports import write_exportslines 164–164from .tracerun import load_traces, root_name, trace_forlines 165–165from .symbols import symbol_pageslines 166–166from .testpages import test_pageslines 167–167from .evidence import parse_junitlines 168–168from .tracepages import Trace, nodes_page, requirements_pagelines 169–169from .versions import record_version, valid_keylines 171–171repo_root, out_dir = Path(repo_root), Path(out_dir)lines 172–172config, problems = load_wiki_config(repo_root, config_path)lines 173–173◇ if problemslines 174–174raise ValueError("wiki configuration problems: " + "; ".join(problems))lines 175–175rules = _audience(config, audience)lines 176–176site_dir = out_dir / valid_key(version) if version else out_dirlines 177–177source = site_dir / "_source"lines 178–178◇ if source.exists()lines 179–179shutil.rmtree(source)lines 180–180source.mkdir(parents=True)lines 181–181commit = _commit(repo_root)lines 182–182◇ if commit_published(repo_root, commit) is Falselines 183–183config = dataclasses.replace(config, link_template="")lines 184–184trace = Trace.gather(repo_root, db, config, commit)lines 185–185snapshot = trace.snapshot(version or "")lines 186–186milestones = _milestones(repo_root, config)lines 187–187burndown = _burndown(out_dir, version, snapshot, milestones) if version else ""lines 188–188req_of = _requirements_of(trace.evidence)lines 189–189facts = testfacts.gather(trace.evidence)lines 190–192traces = { root_name(otlp): (rel, otlp) for rel, otlp in load_traces(repo_root, config.inputs.traces) }lines 193–193test_specs = _test_flows(db, facts, frozenset(traces), config.trace_depth)lines 194–194specs = [*_all_flows(repo_root, db, config), *test_specs]lines 195–195coverage = _coverage(repo_root, config)lines 197–204graph = build_graph( db, trace.evidence, trace.impact, config.components, exclude_tests=True, component_depth=config.component_depth, )lines 205–205blocks = graph.get("file_block") or {}lines 206–206pages, not_drawn, flow_of = [], [], {}lines 207–207◇ for s in specslines 208–208trylines 209–225pages.append( flow_page( repo_root, db, _with_role(s, config), source, rules, config, commit, req_of, ## X-2: a master flow takes the subtree a traced test reached under it. trace_for(s.entry, traces), coverage, blocks, _actor_of(s, config), ) )lines 226–226flow_of.setdefault(s.entry, pages[-1].name)lines 227–227except ValueError as refusedlines 230–230◇ if s in config.flowslines 231–231raiselines 232–232not_drawn.append((s.entry, s.file or "", str(refused)))lines 233–237unmatched = tuple( (rel, root) for root, (rel, _o) in sorted(traces.items()) if root not in {s.entry for s in specs} )lines 238–238keys = {(n, f) for r in trace.evidence for n, f, _l in r.implementer_sites}lines 239–239keys |= {fn for p in pages for fn in p.functions}lines 240–254symbol_ctx = { ## V6 (owner Q/A 2026-11-20): how many body lines a symbol page bundles. "body_lines": config.body_lines, "req_of": req_of, "flows": pages, "rules": rules, "template": config.link_template, ## R5-CFG C3 (2.0.0): ONE test → implementer path depth for the symbol and test pages. "path_depth": config.path_depth, "commit": commit, "tests": facts, "implementers": { r.req_id: {(n, f) for n, f, _l in r.implementer_sites} for r in trace.evidence }, }lines 255–255written = symbol_pages(db, repo_root, keys, symbol_ctx, source)lines 256–256scenarios = parse_features(repo_root, config.inputs.features)lines 257–257written |= testfacts.feature_pages(repo_root, scenarios, facts, source)lines 258–258trace.symbols = set(written)lines 260–284trace.test_href = test_pages( db, repo_root, { **symbol_ctx, "results": parse_junit( [repo_root / j for j in config.junit if (repo_root / j).is_file()] ), "extent": {r.req_id: dict(r.extent) for r in trace.evidence if r.extent is not None}, "flow_of": flow_of, "traced": set(traces), ## P5.5: the runs themselves, for each pinned check's traced value. "traces": traces, ## P5.5: context paths — the product flows a test's calls are reached by. "product_flows": [p for p in pages if p.role == "product"], ## P5.5: the call-flow boxes — what each test ran, and which functions have a page. "lines_by_test": _lines_by_test(coverage), "written": set(written), "test_pages": config.test_pages, "slices": _slices_by_test(pages), ## OWNER Q/A 2026-11-20 (after P6): how many of a test's slices are drawn. "test_slices": config.test_slices, }, source, )lines 285–285◇ for (name, _rel), href in sorted(written.items())lines 286–286◇ if name in factslines 287–287trace.test_href.setdefault(name, href)lines 289–289from .entities import write_quick_viewslines 291–291write_quick_views(db, source, pages, blocks, trace.test_href, req_of)lines 292–292decisions = find_decisions(repo_root, config.adrs, tuple(r.req_id for r in trace.evidence))lines 293–295trace.decisions = { r.req_id: [d for d in decisions if r.req_id in d.requirements] for r in trace.evidence }lines 296–296issues = resolve_target(config.issues, config.issues_enabled, repo_root)lines 297–297trace.issues, trace.unlinked, trace.issues_note = _fetch_issues(config, issues, trace.evidence)lines 298–298_issues_into(graph, trace.issues)lines 299–323sections = [ requirements_page( trace, config, source, rules, burndown, tuple(pages), issues, graph.get("file_block") or {}, ), flows_index(source, pages, unmatched, tuple(not_drawn)), impact_page(trace, pages, rules, source), web_page( db, graph, [n for n, _g in config.components], pages, written, source, config.web_max_ring, owners=not rules.exclude_owners, ), _docs_page(source, _prose(repo_root, config, source), config, decisions), ]lines 325–325from .testpages import tests_indexlines 327–335sections.insert( sections.index("flows") + 1 if "flows" in sections else len(sections), tests_index( db, {"tests": facts, "results": _test_results(repo_root, config)}, trace.test_href, source, ), )lines 337–337from .apiref import api_pageslines 339–339sections.append(api_pages(db, config.api, source, config.doc_tags))lines 341–341from .sbom import sbom_pagelines 343–343sections.append(sbom_page(repo_root, db, config, source))lines 345–350sections.insert( sections.index("map") + 1 if "map" in sections else len(sections), architecture_page( config.title, graph, _architecture_entries(db, repo_root, config, flow_of), source ), )lines 351–351◇ if config.catalogslines 352–352linked = frozenset(r.req_id for r in trace.evidence)lines 353–353sections.insert(1, _product_section(repo_root, db, config, rules, source, linked))lines 354–354◇ if config.sourceslines 355–355sections.append(nodes_page(trace, config, source))lines 356–356_write_index(source, config, trace, [s for s in sections if s], len(pages))lines 357–363write_exports( source / "_extra", trace, pages, graph, {"title": config.title, "rules": rules, "summary": ""}, )lines 364–369context = { "clew_minimap": minimap_html(graph, [n for n, _g in config.components]) if "map" in sections else "", "clew_minimap_lit": _lit(pages, graph, config), }lines 370–370html = _render(source, site_dir / "html", config, repo_root, context)lines 372–372_write_ci_summary(summary or site_dir / "summary.md", repo_root, config, trace.evidence)lines 373–373◇ if versionlines 374–374record_version(out_dir, version, snapshot, config.title, milestones)lines 375–375return html

Flows

_burndown

str clew.wiki.build._burndown(Path out_dir, str version, dict snapshot, list milestones)

The burndown for a versioned build: earlier recorded versions, then this one.

clew/wiki/build.py:641

Source · 8 lines
def _burndown(out_dir: Path, version: str, snapshot: dict, milestones: list) -> str:
    """@brief Draw the burndown. @return SVG."""
    from .charts import burndown
    from .versions import series

    return burndown(series(out_dir, version, snapshot), milestones)

Activity · 3 steps
lines 643–643from .charts import burndownlines 644–644from .versions import serieslines 646–646return burndown(series(out_dir, version, snapshot), milestones)

Flows

_commit

str clew.wiki.build._commit(Path repo_root)

The repository's HEAD commit, or "HEAD" when it cannot be read.

clew/wiki/build.py:1114

Source · 22 lines
def _commit(repo_root: Path) -> str:
    """FULL IDS, through the hardened git environment (#67: commit-correct links).

    @brief Read HEAD.
    @return Sha.
    """
    from ..gitenv import git_argv

    try:
        out = subprocess.run(
            git_argv("rev-parse", "HEAD"),
            cwd=repo_root,
            capture_output=True,
            text=True,
            check=False,
            timeout=30,
        )
    except (OSError, subprocess.TimeoutExpired):
        return "HEAD"
    return out.stdout.strip() or "HEAD"

Activity · 6 steps
lines 1120–1120from ..gitenv import git_argvlines 1122–1122trylines 1123–1130out = subprocess.run( git_argv("rev-parse", "HEAD"), cwd=repo_root, capture_output=True, text=True, check=False, timeout=30, )lines 1131–1131except (OSError, subprocess.TimeoutExpired)lines 1132–1132return "HEAD"lines 1133–1133return out.stdout.strip() or "HEAD"

Flows

_coverage

dict | None clew.wiki.build._coverage(Path repo_root, Any config)

Per-test coverage, when the section names it and it is there.

clew/wiki/build.py:501

Source · 10 lines
def _coverage(repo_root: Path, config: Any) -> dict | None:
    """@brief Read contexts. @return Contexts or None."""
    from .imports import parse_contexts

    rel = config.inputs.contexts
    return (
        parse_contexts(repo_root / rel, repo_root) if rel and (repo_root / rel).is_file() else None
    )

Activity · 3 steps
lines 503–503from .imports import parse_contextslines 505–505rel = config.inputs.contextslines 506–508return ( parse_contexts(repo_root / rel, repo_root) if rel and (repo_root / rel).is_file() else None )

Flows

_fetch_issues

tuple[Any, list, str] clew.wiki.build._fetch_issues(WikiConfig config, Any target, list evidence)

Open issues linked to requirements, when the section asks for them.

clew/wiki/build.py:451

Source · 29 lines
def _fetch_issues(config: WikiConfig, target: Any, evidence: list) -> tuple[Any, list, str]:
    """THE BUILD'S ONLY NETWORK USE, and only when `wiki.issues.fetch` is true. A failure is SAID
    on the page — never a crash, and never an empty list that would read "no open issues".

    @brief Fetch and link issues.
    @return Linked, unlinked, note.
    """
    from . import issues as tracker

    if not config.issues_fetch:
        return None, [], ""
    if target is None:
        return None, [], "Issues were not fetched: no tracker is declared or found on `origin`."
    provider = tracker.provider_for(target)
    try:
        found = provider.list_open()
    except (OSError, ValueError, KeyError) as exc:
        return None, [], f"Issues were not fetched from {target[0]} `{target[1]}`: {exc}"
    linked, unlinked = tracker.link_issues(found, [r.req_id for r in evidence])
    ## D14 (2.0.0): a listing cut at its page cap is SAID — the counts below are a floor.
    note = (
        f"Only the first {len(found)} open issues were read from {target[0]} `{target[1]}` (the "
        f"listing stops at its page cap); counts on this page are a lower bound."
        if getattr(provider, "truncated", False)
        else ""
    )
    return linked, unlinked, note

Activity · 13 steps
lines 458–458from . import issues as trackerlines 460–460◇ if not config.issues_fetchlines 461–461return None, [], ""lines 462–462◇ if target is Nonelines 463–463return None, [], "Issues were not fetched: no tracker is declared or found on `origin`."lines 464–464provider = tracker.provider_for(target)lines 465–465trylines 466–466found = provider.list_open()lines 467–467except (OSError, ValueError, KeyError) as exclines 468–468return None, [], f"Issues were not fetched from {target[0]} `{target[1]}`: {exc}"lines 469–469linked, unlinked = tracker.link_issues(found, [r.req_id for r in evidence])lines 471–476note = ( f"Only the first {len(found)} open issues were read from {target[0]} `{target[1]}` (the " f"listing stops at its page cap); counts on this page are a lower bound." if getattr(provider, "truncated", False) else "" )lines 477–477return linked, unlinked, note

Flows

_issues_into

None clew.wiki.build._issues_into(dict graph, Any linked)

Each component's count of open issues linked to the requirements it implements.

clew/wiki/build.py:486

Show on the map →

Called by _build_site

Calls none

Source · 9 lines
def _issues_into(graph: dict, linked: Any) -> None:
    """@brief Count per component. @return None."""
    if linked is None:
        return
    for comp in graph["components"]:
        ids = {i.id for r, _tier in comp.get("req_ids") or [] for i in linked.get(r, [])}
        comp["issues"] = len(ids)

Activity · 5 steps
lines 488–488◇ if linked is Nonelines 489–489returnlines 490–490◇ for comp in graph["components"]lines 491–491ids = {i.id for r, _tier in comp.get("req_ids") or [] for i in linked.get(r, [])}lines 492–492comp["issues"] = len(ids)

Flows

_lines_by_test

dict clew.wiki.build._lines_by_test(dict|None coverage)

Each test's executed lines, from per-test coverage.

clew/wiki/build.py:1252

Source · 7 lines
def _lines_by_test(coverage: dict | None) -> dict:
    """@brief Group by test. @return Lines."""
    from .slices import lines_per_test

    return lines_per_test(coverage) if coverage else {}

Activity · 2 steps
lines 1254–1254from .slices import lines_per_testlines 1256–1256return lines_per_test(coverage) if coverage else {}

Flows

_milestones

list[tuple[str, str]] clew.wiki.build._milestones(Path repo_root, WikiConfig config)

The roadmap's milestones, or none when no roadmap is declared.

clew/wiki/build.py:626

Source · 7 lines
def _milestones(repo_root: Path, config: WikiConfig) -> list[tuple[str, str]]:
    """@brief Read milestones. @return Pairs."""
    from .charts import roadmap_milestones

    return roadmap_milestones(repo_root / config.roadmap) if config.roadmap else []

Activity · 2 steps
lines 628–628from .charts import roadmap_milestoneslines 630–630return roadmap_milestones(repo_root / config.roadmap) if config.roadmap else []

Flows

_requirements_of

dict[tuple[str, str], list[str]] clew.wiki.build._requirements_of(list evidence)

Which requirements each implementing function carries.

clew/wiki/build.py:583

Show on the map →

Called by _build_site

Calls none

Source · 9 lines
def _requirements_of(evidence: list) -> dict[tuple[str, str], list[str]]:
    """@brief Invert implementer sites. @return Map."""
    out: dict[tuple[str, str], list[str]] = {}
    for row in evidence:
        for name, rel, _line in row.implementer_sites:
            out.setdefault((name, rel), []).append(row.req_id)
    return out

Activity · 5 steps
lines 585–585out: dict[tuple[str, str], list[str]] = {}lines 586–586◇ for row in evidencelines 587–587◇ for name, rel, _line in row.implementer_siteslines 588–588out.setdefault((name, rel), []).append(row.req_id)lines 589–589return out

Flows

_slices_by_test

dict[str, list] clew.wiki.build._slices_by_test(list pages)

Each test's slices of the master flows, most exercised first.

clew/wiki/build.py:516

Show on the map →

Called by _build_site

Calls none

Source · 11 lines
def _slices_by_test(pages: list) -> dict[str, list]:
    """@brief Group slices by test. @return Slices."""
    out: dict[str, list] = {}
    for page in pages:
        for test, cut in (page.slices or {}).items():
            out.setdefault(test, []).append((page, cut))
    for cuts in out.values():
        cuts.sort(key=lambda pc: (-len(pc[1].exercised), pc[0].name))
    return out

Activity · 7 steps
lines 518–518out: dict[str, list] = {}lines 519–519◇ for page in pageslines 520–520◇ for test, cut in (page.slices or {}).items()lines 521–521out.setdefault(test, []).append((page, cut))lines 522–522◇ for cuts in out.values()lines 523–523cuts.sort(key=lambda pc: (-len(pc[1].exercised), pc[0].name))lines 524–524return out

Requirements

REQ-DDB-WIKI-041

Flows

_test_flows

list clew.wiki.build._test_flows(Path db, dict facts, frozenset traced=frozenset(), int depth=2)

Directly linked tests (by tag or measured coverage) with a packaged run, as flows.

clew/wiki/build.py:539

Source · 22 lines
def _test_flows(db: Path, facts: dict, traced: frozenset = frozenset(), depth: int = 2) -> list:
    """CATALOG AND INFERRED LINKS ARE NOT DIRECT: a catalog names a whole test file and inference
    reaches through the call graph; only a tagged or measured test is drawn by default.

    @brief Test flows.
    @return Specs.
    """
    from ..query._common import connect
    from .config import FlowSpec
    from .symbols import test_functions

    direct = {n for n, f in facts.items() if any(k in ("tag", "measured") for _r, k in f.verifies)}
    with connect(db) as conn:
        keys = sorted(test_functions(conn, direct))
    chosen = [k for k in keys if k[0] in traced]
    specs = [
        FlowSpec(entry=n, file=f, depth=depth, title=f"test `{n}` ({f})", role="tests")
        for n, f in chosen
    ]
    return specs

Activity · 9 steps
lines 546–546from ..query._common import connectlines 547–547from .config import FlowSpeclines 548–548from .symbols import test_functionslines 550–550direct = {n for n, f in facts.items() if any(k in ("tag", "measured") for _r, k in f.verifies)}lines 551–551with connect(db) as connlines 552–552keys = sorted(test_functions(conn, direct))lines 553–553chosen = [k for k in keys if k[0] in traced]lines 554–557specs = [ FlowSpec(entry=n, file=f, depth=depth, title=f"test `{n}` ({f})", role="tests") for n, f in chosen ]lines 558–558return specs

Requirements

REQ-DDB-WIKI-027

Flows

_with_role

Any clew.wiki.build._with_role(Any spec, WikiConfig config)

A flow with its role settled: declared, else tooling by path, else product.

clew/wiki/build.py:567

Source · 11 lines
def _with_role(spec: Any, config: WikiConfig) -> Any:
    """@brief Classify. @return Spec."""
    import dataclasses
    import fnmatch

    if spec.role:
        return spec
    tooling = bool(spec.file) and any(fnmatch.fnmatch(spec.file, g) for g in config.tooling)
    return dataclasses.replace(spec, role="tooling" if tooling else "product")

Activity · 6 steps
lines 569–569import dataclasseslines 570–570import fnmatchlines 572–572◇ if spec.rolelines 573–573return speclines 574–574tooling = bool(spec.file) and any(fnmatch.fnmatch(spec.file, g) for g in config.tooling)lines 575–575return dataclasses.replace(spec, role="tooling" if tooling else "product")

Flows

build_wiki

Path clew.wiki.build.build_wiki(Path repo_root, Path db, Path out_dir, str|None audience=None, str|None version=None, Path|None config_path=None, Path|None summary=None)

Build the site for a repository.

clew/wiki/build.py:87

Source · 23 lines
def build_wiki(
    repo_root: Path,
    db: Path,
    out_dir: Path,
    audience: str | None = None,
    version: str | None = None,
    config_path: Path | None = None,
    summary: Path | None = None,
) -> Path:
    """THE REPORT SIZE LIMIT (`tests.max_report_mb`) IS THIS BUILD'S: every report reader below
    consults it, so it is set around the whole build rather than threaded through each parser.

    @brief Write and render the site, within this build's report limit.
    @return The HTML directory.
    @version 24
    """
    from .evidence import report_limit

    config, problems = load_wiki_config(Path(repo_root), config_path)
    with report_limit(config.max_report_mb if not problems else DEFAULT_MAX_REPORT_MB):
        return _build_site(repo_root, db, out_dir, audience, version, config_path, summary)

Activity · 4 steps
lines 103–103from .evidence import report_limitlines 105–105config, problems = load_wiki_config(Path(repo_root), config_path)lines 106–106with report_limit(config.max_report_mb if not problems else DEFAULT_MAX_REPORT_MB)lines 107–107return _build_site(repo_root, db, out_dir, audience, version, config_path, summary)

Requirements

REQ-DDB-WIKI-003

Flows

commit_published

bool | None clew.wiki.build.commit_published(Path repo_root, str commit)

Whether a commit is on one of the repository's remotes.

clew/wiki/build.py:1143

Source · 29 lines
def commit_published(repo_root: Path, commit: str) -> bool | None:
    """OWNER 2026-11-15: "GH link broken (local unpushed commits)" — a permalink to a commit no
    remote has is a 404. Only a KNOWN negative drops links: with nothing to go on they stay.

    @brief Published?
    @return Tri-state.
    """
    from ..gitenv import git_argv

    if not commit or commit == "HEAD":
        return None
    try:
        remotes = subprocess.run(
            git_argv("remote"), cwd=repo_root, capture_output=True, text=True, timeout=30
        )
        if remotes.returncode != 0 or not remotes.stdout.strip():
            return None
        found = subprocess.run(
            git_argv("branch", "-r", "--contains", commit),
            cwd=repo_root,
            capture_output=True,
            text=True,
            timeout=30,
        )
    except (OSError, subprocess.TimeoutExpired):
        return None
    return bool(found.stdout.strip()) if found.returncode == 0 else None

Activity · 11 steps
lines 1150–1150from ..gitenv import git_argvlines 1152–1152◇ if not commit or commit == "HEAD"lines 1153–1153return Nonelines 1154–1154trylines 1155–1157remotes = subprocess.run( git_argv("remote"), cwd=repo_root, capture_output=True, text=True, timeout=30 )lines 1158–1158◇ if remotes.returncode != 0 or not remotes.stdout.strip()lines 1159–1159return Nonelines 1160–1166found = subprocess.run( git_argv("branch", "-r", "--contains", commit), cwd=repo_root, capture_output=True, text=True, timeout=30, )lines 1167–1167except (OSError, subprocess.TimeoutExpired)lines 1168–1168return Nonelines 1169–1169return bool(found.stdout.strip()) if found.returncode == 0 else None

Requirements

REQ-DDB-WIKI-025

Flows