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.
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
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.
Called by _flow_object, _flow_page, expected_steps, flow_page
Tested by 16 tests
test_a_flow_entry_by_file_survives_distinct_identities, test_a_flow_entry_is_selected_by_file, test_a_flow_follows_the_calls_in_order_with_frames, test_a_flow_names_its_actor, test_a_measured_depth_bounds_measured_expansion, test_a_measured_flow_expands_what_ran_and_folds_what_did_not, test_a_not_run_stub_is_drawn_as_a_dim_note_not_a_call, test_a_step_cap_stops_the_walk_and_says_so, test_a_step_links_to_its_call_site_not_the_callee_file, test_an_entry_no_test_ran_is_walked_statically, test_an_unknown_entry_is_refused_by_name, test_an_unmeasured_file_is_walked_statically_never_folded_as_not_run
Calls _entry_rowids, connect, qualified_name_of
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
Requirements
REQ-DDB-WIKI-001 REQ-DDB-WIKI-041