sources.py¶
clew/wiki/sources.py
External node sources: model files whose entries are trace targets (1.4.0 W7, #67).
load_nodes
tuple[list[Node], list[str]] clew.wiki.sources.load_nodes(Path repo_root, tuple[SourceSpec,...] specs)
Every node of every declared source.
Source · 20 lines
def load_nodes(repo_root: Path, specs: tuple[SourceSpec, ...]) -> tuple[list[Node], list[str]]:
"""@brief Load all sources. @return Nodes and problems."""
nodes: list[Node] = []
problems: list[str] = []
seen: set[str] = set()
for spec in specs:
try:
items = _items(_parse(Path(repo_root) / spec.path), spec.items)
except (OSError, ValueError) as exc:
problems.append(f"source {spec.name!r} ({spec.path}): {exc}")
continue
for node in _nodes(spec, items, problems):
if node.ref in seen:
problems.append(f"source {spec.name!r}: id {node.id!r} is declared twice")
continue
seen.add(node.ref)
nodes.append(node)
return nodes, problems
Activity · 16 steps
Requirements
node_references
dict[str, tuple[str, ...]] clew.wiki.sources.node_references(Path|str db)
The functions whose doc comment names each node, from the index.
Source · 17 lines
def node_references(db: Path | str) -> dict[str, tuple[str, ...]]:
"""@brief Read `@node` tags. @return References."""
refs: dict[str, set[str]] = {}
with connect(db) as conn:
if not table_exists(conn, "memberdef"):
return {}
rows = conn.execute(
"SELECT name, briefdescription, detaileddescription FROM memberdef "
"WHERE kind = 'function' AND (briefdescription LIKE '%@node%' "
"OR detaileddescription LIKE '%@node%')"
)
for name, brief, detail in rows:
for ref in _NODE_TAG.findall(f"{brief or ''}\n{detail or ''}"):
refs.setdefault(ref, set()).add(str(name))
return {ref: tuple(sorted(names)) for ref, names in sorted(refs.items())}
Activity · 9 steps
Requirements
ref
str clew.wiki.sources.Node.ref(self)
The node's address, : .
Source · 5 lines
def ref(self) -> str:
"""@brief Address. @return `<source>:<id>`."""
return f"{self.source}:{self.id}"