productpage.py¶
clew/wiki/productpage.py
The product trace page: the composite requirement tree across pinned dependencies (GH #68).
product_html
str clew.wiki.productpage.product_html(Composite tree, Audience rules, frozenset[str] pages=frozenset())
The page body.
Source · 27 lines
def product_html(tree: Composite, rules: Audience, pages: frozenset[str] = frozenset()) -> str:
"""A REQUIREMENT WITH A PAGE HERE LINKS TO IT (2.0.0, P5.4); one without a page stays text,
so no link leads nowhere. Function and test names stay text: the tree carries bare names with
no file, and a link to a same-named symbol elsewhere would be a confident wrong answer.
@brief Tree, problems, unreached.
@return HTML.
"""
roots = frozenset(tree.nodes[r].catalog for r in tree.roots if r in tree.nodes)
links = _Links(pages, roots)
items = "".join(_item(tree, ref, rules, set(), links) for ref in tree.roots)
parts = [f'<ul class="ptree">{items}</ul>', _problems(tree)]
if tree.implemented_here:
rows = "".join(_line(tree.nodes[r], rules, links=links) for r in tree.implemented_here)
parts.append(
f'<details class="implemented-here" open><summary>{len(tree.implemented_here)} '
f"dependency requirement(s) this repository implements</summary><ul>{rows}</ul></details>"
)
if tree.unreached:
rows = "".join(_line(tree.nodes[r], rules, links=links) for r in tree.unreached)
parts.append(
f'<details class="unreached"><summary>{len(tree.unreached)} dependency requirement(s) '
f"nothing on this tree reaches</summary><ul>{rows}</ul></details>"
)
return "\n".join(p for p in parts if p)
Activity · 11 steps
Requirements
product_markdown
str clew.wiki.productpage.product_markdown(Composite tree, Audience rules)
The Product trace as plain Markdown, for wikis that take only Markdown.
Source · 24 lines
def product_markdown(tree: Composite, rules: Audience) -> str:
"""#73 item 1 (owner Q/A 2026-11-23, 2.1): an Azure DevOps code wiki takes Markdown only, and
the tree existed only in the HTML site. SAME TREE, SAME STATES, NO HTML: nested lists, the
evidence state in bold, why-not and the checkout on the line below.
@brief Product trace Markdown.
@return Markdown.
"""
lines = ["# Product trace", "", _LEAD, ""]
for ref in tree.roots:
lines += _md_item(tree, ref, rules, set(), 0)
problems = [f"- `{a}` satisfies `{b}`, which no catalogue holds" for a, b in tree.dangling]
problems += [f"- {c}" for c in tree.conflicts]
for heading, refs in (
("## Problems", None),
("## Dependency requirements this repository implements", tree.implemented_here),
("## Nothing on the tree reaches", tree.unreached),
):
rows = problems if refs is None else [_md_line(tree.nodes[r], rules) for r in refs]
if rows:
lines += ["", heading, "", *rows]
return "\n".join(lines) + "\n"
Activity · 10 steps
Requirements
product_page
str clew.wiki.productpage.product_page(Composite tree, Audience rules, Path source, frozenset[str] pages=frozenset())
Write the product trace page.
Source · 18 lines
def product_page(
tree: Composite, rules: Audience, source: Path, pages: frozenset[str] = frozenset()
) -> str:
"""@brief Write product.md. @return Page name."""
lines = [
"# Product trace",
"",
_LEAD,
"",
"```{raw} html",
product_html(tree, rules, pages),
"```",
"",
]
(Path(source) / "product.md").write_text("\n".join(lines), encoding="utf-8")
return "product"