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.

clew/wiki/sources.py:68

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
lines 70–70nodes: list[Node] = []lines 71–71problems: list[str] = []lines 72–72seen: set[str] = set()lines 73–73◇ for spec in specslines 74–74trylines 75–75items = _items(_parse(Path(repo_root) / spec.path), spec.items)lines 76–76except (OSError, ValueError) as exclines 77–77problems.append(f"source {spec.name!r} ({spec.path}): {exc}")lines 78–78continuelines 79–79◇ for node in _nodes(spec, items, problems)lines 80–80◇ if node.ref in seenlines 81–81problems.append(f"source {spec.name!r}: id {node.id!r} is declared twice")lines 82–82continuelines 83–83seen.add(node.ref)lines 84–84nodes.append(node)lines 85–85return nodes, problems

Requirements

REQ-DDB-WIKI-004

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.

clew/wiki/sources.py:94

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
lines 96–96refs: dict[str, set[str]] = {}lines 97–97with connect(db) as connlines 98–98◇ if not table_exists(conn, "memberdef")lines 99–99return {}lines 100–104rows = conn.execute( "SELECT name, briefdescription, detaileddescription FROM memberdef " "WHERE kind = 'function' AND (briefdescription LIKE '%@node%' " "OR detaileddescription LIKE '%@node%')" )lines 105–105◇ for name, brief, detail in rowslines 106–106◇ for ref in _NODE_TAG.findall(f"{brief or ''}\n{detail or ''}")lines 107–107refs.setdefault(ref, set()).add(str(name))lines 108–108return {ref: tuple(sorted(names)) for ref, names in sorted(refs.items())}

Requirements

REQ-DDB-WIKI-004

ref

str clew.wiki.sources.Node.ref(self)

The node's address, : .

clew/wiki/sources.py:57

Show on the map →

Called by none

Calls none

Source · 5 lines
    def ref(self) -> str:
        """@brief Address. @return `<source>:<id>`."""
        return f"{self.source}:{self.id}"

Activity · 1 steps
lines 59–59return f"{self.source}:{self.id}"

Requirements

REQ-DDB-WIKI-004