composite.py¶
clew/wiki/composite.py
The composite requirement tree: a product's requirements and every pinned dependency's (GH #68).
compose
Composite clew.wiki.composite.compose(Path repo_root, str root_name, list[CatalogSpec] specs, *Probe|None probe=None, Trace|None trace=None, Path|None root_db=None)
Compose the requirement tree rooted at this repository's catalogue.
Called by _product_section, _tree, build_markdown, composite_problems
Tested by 10 tests
test_a_dependency_catalogue_is_read_at_its_pin, test_a_dependency_requirement_implemented_here_is_served_not_unreached, test_a_repository_cycle_terminates, test_a_tagged_requirement_without_a_catalogue_entry_is_a_root, test_an_indexed_dependency_carries_its_trace, test_an_unknown_dependency_carries_no_evidence_and_links_its_checkout, test_one_repository_pinned_twice_is_a_conflict, test_the_tree_is_composed_transitively_and_namespaced, test_the_wiki_tree_follows_a_serves_link, test_unreached_and_dangling_are_reported
Calls _nodes, _reach, _root_source, _served_here, _tagged, _walk
Source · 35 lines
def compose(
repo_root: Path,
root_name: str,
specs: list[CatalogSpec],
*,
probe: Probe | None = None,
trace: Trace | None = None,
root_db: Path | None = None,
) -> Composite:
"""AN ID A DEPENDENCY'S CATALOGUE HOLDS IS THAT CATALOGUE'S: tagged here without a local
catalogue entry, it is not also a root — it is listed as implemented here, with THIS
repository's functions and tests rather than the dependency's index state.
@brief Read every catalogue, link, mark reach.
@return Composite.
"""
trace = trace or _trace
root = _root_source(Path(repo_root), root_name, root_db)
sources, conflicts = _walk(Path(repo_root), root_name, specs, probe or _probe_default)
dep_ids = {rid for s in sources for rid in s.rows}
root.rows = {k: v for k, v in root.rows.items() if k in root.declared or k not in dep_ids}
sources.insert(0, root)
nodes, dangling = _nodes(sources, trace)
roots = tuple(f"{root_name}:{rid}" for rid in sorted(root.rows))
tagged = _tagged(root_db)
here = tuple(
sorted(r for r, n in nodes.items() if n.catalog != root_name and n.req_id in tagged)
)
for ref in here:
nodes[ref] = _served_here(nodes[ref], root.state, trace)
reached = _reach(roots, nodes) | set(here)
unreached = tuple(sorted(r for r in nodes if r not in reached))
return Composite(roots, nodes, unreached, tuple(dangling), tuple(conflicts), here)
Activity · 15 steps
Requirements
composite_problems
list[str] clew.wiki.composite.composite_problems(Path repo_root, list[CatalogSpec] specs, *Probe|None probe=None)
The composite's problems, for clew wiki check .
Source · 15 lines
def composite_problems(
repo_root: Path, specs: list[CatalogSpec], *, probe: Probe | None = None
) -> list[str]:
"""CHEAP: the default probe reads no index — check is about the catalogues, not evidence.
@brief Check the composite.
@return Problems.
"""
tree = compose(Path(repo_root), Path(repo_root).name, specs, probe=probe or _no_probe)
return [
f"{ref} satisfies {target}, which no catalogue on the composite holds"
for ref, target in tree.dangling
] + list(tree.conflicts)
Activity · 2 steps
Requirements
probe_index
tuple[str, str, Path | None] clew.wiki.composite.probe_index(Path dep, str pin, str|None pin_sha, *Callable[[Path], Path|None]|None locate=None, Callable[[Path, Path], bool]|None is_stale=None)
Whether a dependency's index describes its pinned code.
Source · 32 lines
def probe_index(
dep: Path,
pin: str,
pin_sha: str | None,
*,
locate: Callable[[Path], Path | None] | None = None,
is_stale: Callable[[Path, Path], bool] | None = None,
) -> tuple[str, str, Path | None]:
"""FIRST FAILING CHECK WINS, each named, so the page says exactly why evidence is withheld.
@brief Probe a dependency's index against its pin.
@return State, note, index.
"""
db = (locate or _locate)(dep)
if db is None:
return ("absent", f"{dep.name} is not indexed on this machine", None)
head = (git_text(dep, "rev-parse", "HEAD") or "").strip()
checks = (
(lambda: pin_sha is None, f"pin {pin} does not resolve in {dep.name}"),
(lambda: head != pin_sha, f"not indexed at pin {pin[:12]}; checkout is at {head[:12]}"),
(
lambda: bool(
(git_text(dep, "status", "--porcelain", "--untracked-files=no") or "").strip()
),
f"{dep.name} has uncommitted changes, so its index is not the pinned code",
),
(lambda: (is_stale or _stale)(db, dep), f"{dep.name}'s index is older than its checkout"),
)
note = next((msg for failed, msg in checks if failed()), "")
return ("unknown" if note else "indexed", note, db)