flow.py

clew/wiki/flow.py

A sequence diagram FORMED from the index: lanes, ordered steps, frames.

_entry_rowids

list[int] clew.wiki.flow._entry_rowids(sqlite3.Connection conn, _Walker walker, str entry, str|None qualified, str|None file)

The rowids of the entry: its identity, chosen by file when one is given.

clew/wiki/flow.py:189

Source · 22 lines
def _entry_rowids(
    conn: sqlite3.Connection, walker: _Walker, entry: str, qualified: str | None, file: str | None
) -> list[int]:
    """THE FILE CHOOSES THE IDENTITY. Filtering the default identity by file found nothing when
    two same-named functions were distinct identities and the guess picked the other one — which
    depended on the doxygen version. With a file and no selector, the identity is the one whose
    row sits in that file; only that file's rows are walked.

    @brief Entry rowids.
    @return Rowids.
    """
    if not file:
        return identity_rowids(conn, entry, qualified)
    if qualified is None:
        rows = [(r, sig) for r, sig, *_rest in function_candidates(conn, entry)]
        hit = next((sig for r, sig in rows if walker.file_of(r) == file), None)
        if hit is None:
            return []
        qualified = qualified_name_of(entry, hit)
    return [r for r in identity_rowids(conn, entry, qualified) if walker.file_of(r) == file]

Activity · 9 steps
lines 200–200◇ if not filelines 201–201return identity_rowids(conn, entry, qualified)lines 202–202◇ if qualified is Nonelines 203–203rows = [(r, sig) for r, sig, *_rest in function_candidates(conn, entry)]lines 204–204hit = next((sig for r, sig in rows if walker.file_of(r) == file), None)lines 205–205◇ if hit is Nonelines 206–206return []lines 207–207qualified = qualified_name_of(entry, hit)lines 208–208return [r for r in identity_rowids(conn, entry, qualified) if walker.file_of(r) == file]

Flows

derive_flow

Flow clew.wiki.flow.derive_flow(Path|str db, Path|str repo_root, str entry, *str|None qualified=None, int depth=3, str lanes="files", tuple[str,...] stop_at=(), str|None file=None, dict[str, set[int]]|None executed=None, int|None max_steps=None, int|None measured_depth=None, dict[str, str]|None blocks=None, str actor="")

Derive the flow from an entry function.

clew/wiki/flow.py:127

Source · 53 lines
def derive_flow(
    db: Path | str,
    repo_root: Path | str,
    entry: str,
    *,
    qualified: str | None = None,
    depth: int = 3,
    lanes: str = "files",
    stop_at: tuple[str, ...] = (),
    file: str | None = None,
    executed: dict[str, set[int]] | None = None,
    max_steps: int | None = None,
    measured_depth: int | None = None,
    blocks: dict[str, str] | None = None,
    actor: str = "",
) -> Flow:
    """REFUSES BY NAME an entry the index does not hold and a lane strategy it does not know, so a
    typo never yields an empty diagram that looks like a function with no calls.

    @brief Build a Flow.
    @return The flow.
    @version 2
    """
    if lanes not in LANES:
        raise ValueError(f"unknown lane strategy {lanes!r}; known: {', '.join(LANES)}")
    with connect(db) as conn:
        walker = _Walker(conn, Path(repo_root), lanes, frozenset(stop_at))
        walker.executed = executed
        walker.blocks = blocks or {}
        walker.max_steps = max_steps or (MEASURED_STEP_CAP if executed is not None else 0)
        ## R5-CFG C1 (2.0.0): how deep a call measured as run expands (`wiki.measured_depth`).
        walker.measured_levels = measured_depth or MEASURED_LEVELS
        rowids = _entry_rowids(conn, walker, entry, qualified, file)
        if not rowids:
            raise ValueError(
                f"no function {entry!r} in this index (qualified={qualified!r}, file={file!r})"
            )
        full = qualified_name_of(entry, _definition(conn, rowids[0]))
        walker.walk(entry, full, min(rowids), depth, 1, frozenset({full}), rowids if file else None)
        ordered = tuple(walker.lane_order)
        return Flow(
            entry=entry,
            entry_qualified=full,
            depth=depth,
            lane_strategy=lanes,
            lanes=tuple(Lane(id=lane, label=lane) for lane in ordered),
            steps=tuple(walker.steps),
            measured=executed is not None,
            capped=walker.capped,
            actor=actor,
        )

Activity · 15 steps
lines 150–150◇ if lanes not in LANESlines 151–151raise ValueError(f"unknown lane strategy {lanes!r}; known: {', '.join(LANES)}")lines 152–152with connect(db) as connlines 153–153walker = _Walker(conn, Path(repo_root), lanes, frozenset(stop_at))lines 154–154walker.executed = executedlines 155–155walker.blocks = blocks or {}lines 156–156walker.max_steps = max_steps or (MEASURED_STEP_CAP if executed is not None else 0)lines 158–158walker.measured_levels = measured_depth or MEASURED_LEVELSlines 159–159rowids = _entry_rowids(conn, walker, entry, qualified, file)lines 160–160◇ if not rowidslines 161–163raise ValueError( f"no function {entry!r} in this index (qualified={qualified!r}, file={file!r})" )lines 164–164full = qualified_name_of(entry, _definition(conn, rowids[0]))lines 165–165walker.walk(entry, full, min(rowids), depth, 1, frozenset({full}), rowids if file else None)lines 166–166ordered = tuple(walker.lane_order)lines 167–177return Flow( entry=entry, entry_qualified=full, depth=depth, lane_strategy=lanes, lanes=tuple(Lane(id=lane, label=lane) for lane in ordered), steps=tuple(walker.steps), measured=executed is not None, capped=walker.capped, actor=actor, )

Requirements

REQ-DDB-WIKI-001 REQ-DDB-WIKI-041

Flows