markdown.py¶
clew/wiki/markdown.py
The wiki as Markdown pages for a GitHub or Azure DevOps wiki (round 3, P5b).
build_markdown
Path clew.wiki.markdown.build_markdown(Path repo_root, Path db, Path out, str flavor, str|None audience=None, Path|None config_path=None, Path|None summary=None)
Write the wiki as Markdown pages.
Called by _build, _markdown
Tested by
Calls _all_flows, _audience, _flow_page, _flows_index, _home, _impact, _requirements, _with_role, _write, _write_ci_summary, compose, list
Source · 58 lines
def build_markdown(
repo_root: Path,
db: Path,
out: Path,
flavor: str,
audience: str | None = None,
config_path: Path | None = None,
summary: Path | None = None,
) -> Path:
"""REFUSES an unknown flavour by name, as the site refuses an unknown audience.
@brief Build Markdown.
@return Directory.
"""
from .build import _all_flows, _audience, _commit, _with_role
from .config import load_wiki_config
from .tracepages import Trace
if flavor not in FLAVORS:
raise ValueError(f"unknown flavour {flavor!r} (known: {', '.join(FLAVORS)})")
dialect: _Flavor = _GitHub() if flavor == "github" else _Ado()
config, problems = load_wiki_config(Path(repo_root), config_path)
if problems:
raise ValueError("wiki configuration problems: " + "; ".join(problems))
rules = _audience(config, audience)
out = Path(out)
out.mkdir(parents=True, exist_ok=True)
trace = Trace.gather(Path(repo_root), Path(db), config, _commit(Path(repo_root)))
flows = [
_flow_page(Path(repo_root), Path(db), _with_role(s, config), dialect, out)
for s in _all_flows(Path(repo_root), Path(db), config)
]
pages = [("Home", "Home"), ("Requirements", "Requirements"), ("Flows", "Flows")]
_write(out, "Requirements", _requirements(trace, rules))
_write(out, "Flows", _flows_index(flows, dialect))
if trace.impact is not None:
_write(out, "Change-impact", _impact(trace, rules))
pages.append(("Change-impact", "Change impact"))
## #73 item 1 (owner Q/A 2026-11-23, 2.1): the cross-repository tree, as on the HTML site.
if config.catalogs:
from .composite import compose
from .productpage import product_markdown
tree = compose(
Path(repo_root), Path(repo_root).name, list(config.catalogs), root_db=Path(db)
)
_write(out, "Product-trace", product_markdown(tree, rules))
pages.insert(2, ("Product-trace", "Product trace"))
_write(out, "Home", _home(config.title, trace, len(flows), dialect, pages))
dialect.order(out, pages + [(page, label) for page, label, _role in flows])
## #72 item 12 (2.1): the CI evidence summary, where asked — never among the wiki's pages.
if summary is not None:
from .build import _write_ci_summary
_write_ci_summary(Path(summary), Path(repo_root), config, trace.evidence)
return out