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.
Called by _site
Tested by 11 tests
test_a_catalog_that_moved_since_its_pin_fails_check, test_a_declared_docs_glob_that_matches_nothing_is_still_reported, test_a_default_docs_glob_that_matches_nothing_is_not_a_problem, test_a_rule_must_name_known_requirements, test_before_tests_a_report_a_run_produces_is_not_yet_required, test_check_names_every_missing_import, test_check_names_every_problem, test_check_passes_a_valid_section_and_imports_no_sphinx, test_check_refuses_a_reference_to_an_undeclared_node, test_check_refuses_an_unknown_palette_token, test_wiki_check_prints_ears_notes_without_failing_on_them
Calls _docs_problems, _evidence_problems, _flow_problems, _site_problems, load_wiki_config, trace_problems
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
Requirements
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.
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)
)