check.py

clew/wiki/check.py

`clew wiki check`: everything the `wiki:` section points at exists — cheap, and Sphinx-free.

check_wiki

list[str] clew.wiki.check.check_wiki(Path repo_root, Path db, Path|None config_path=None, *bool before_tests=False)

Every problem with a repository's wiki configuration, against its index.

clew/wiki/check.py:46

Source · 15 lines
def check_wiki(
    repo_root: Path, db: Path, config_path: Path | None = None, *, before_tests: bool = False
) -> list[str]:
    """@brief Run every check. @return Problems."""
    repo_root = Path(repo_root)
    config, problems = load_wiki_config(repo_root, config_path)
    problems += _docs_problems(repo_root, config)
    problems += _flow_problems(db, config)
    problems += _evidence_problems(repo_root, config, before_tests)
    if config.link_template and "{file}" not in config.link_template:
        problems.append("`wiki.links.template` has no `{file}` placeholder")
    problems += trace_problems(repo_root, db, config)
    return problems + _site_problems(repo_root, config)

Activity · 9 steps
lines 50–50repo_root = Path(repo_root)lines 51–51config, problems = load_wiki_config(repo_root, config_path)lines 52–52problems += _docs_problems(repo_root, config)lines 53–53problems += _flow_problems(db, config)lines 54–54problems += _evidence_problems(repo_root, config, before_tests)lines 55–55◇ if config.link_template and "{file}" not in config.link_templatelines 56–56problems.append("`wiki.links.template` has no `{file}` placeholder")lines 57–57problems += trace_problems(repo_root, db, config)lines 58–58return problems + _site_problems(repo_root, config)

Requirements

REQ-DDB-WIKI-003

trace_problems

list[str] clew.wiki.check.trace_problems(Path repo_root, Path db, WikiConfig config)

Problems with the trace targets: nodes, catalogs, rules and mutation records.

clew/wiki/check.py:88

Show on the map →

Called by check_wiki

Calls _known_requirements, _mapping_problems, _mutation_problems, catalog_requirements, composite_problems, list, load_nodes, node_references, pin_problems

Source · 45 lines
def trace_problems(repo_root: Path, db: Path, config: WikiConfig) -> list[str]:
    """@brief Check W7–W9 targets. @return Problems."""
    from .catalogs import catalog_requirements, pin_problems
    from .sources import load_nodes, node_references

    nodes, problems = load_nodes(repo_root, config.sources)
    declared = {n.ref for n in nodes}
    for ref, names in node_references(db).items():
        if config.sources and ref not in declared:
            problems.append(f"`@node {ref}` on {', '.join(names)} names a node no source declares")
    known = _known_requirements(db)
    for spec in config.catalogs:
        pins = pin_problems(repo_root, spec)
        problems += pins
        if not pins:
            rows, more = catalog_requirements(repo_root, spec)
            problems += more
            known |= {r.req_id for r in rows}
    if config.catalogs:
        from .composite import composite_problems

        # GH #68: the composite's dangling links and pin conflicts; a catalogue that cannot be
        # read is already reported above, by the same reader, so it is not repeated.
        problems += [
            p for p in composite_problems(repo_root, list(config.catalogs)) if p not in problems
        ]
    for rule in config.rules:
        problems += [
            f"rule {rule.id!r} names requirement {r!r}, which nothing declares or tags"
            for r in rule.requirements
            if r not in known
        ]
    for node in nodes:
        problems += [
            f"node {node.ref!r} serves requirement {r!r}, which nothing declares or tags"
            for r in node.requirements
            if r not in known
        ]
    return (
        problems
        + _mutation_problems(repo_root, db, config)
        + _mapping_problems(repo_root, config, known)
    )

Activity · 23 steps
lines 90–90from .catalogs import catalog_requirements, pin_problemslines 91–91from .sources import load_nodes, node_referenceslines 93–93nodes, problems = load_nodes(repo_root, config.sources)lines 94–94declared = {n.ref for n in nodes}lines 95–95◇ for ref, names in node_references(db).items()lines 96–96◇ if config.sources and ref not in declaredlines 97–97problems.append(f"`@node {ref}` on {', '.join(names)} names a node no source declares")lines 98–98known = _known_requirements(db)lines 99–99◇ for spec in config.catalogslines 100–100pins = pin_problems(repo_root, spec)lines 101–101problems += pinslines 102–102◇ if not pinslines 103–103rows, more = catalog_requirements(repo_root, spec)lines 104–104problems += morelines 105–105known |= {r.req_id for r in rows}lines 106–106◇ if config.catalogslines 107–107from .composite import composite_problemslines 111–113problems += [ p for p in composite_problems(repo_root, list(config.catalogs)) if p not in problems ]lines 114–114◇ for rule in config.ruleslines 115–119problems += [ f"rule {rule.id!r} names requirement {r!r}, which nothing declares or tags" for r in rule.requirements if r not in known ]lines 120–120◇ for node in nodeslines 121–125problems += [ f"node {node.ref!r} serves requirement {r!r}, which nothing declares or tags" for r in node.requirements if r not in known ]lines 126–130return ( problems + _mutation_problems(repo_root, db, config) + _mapping_problems(repo_root, config, known) )

Requirements

REQ-DDB-WIKI-005