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.

clew/wiki/composite.py:192

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
lines 208–208trace = trace or _tracelines 209–209root = _root_source(Path(repo_root), root_name, root_db)lines 210–210sources, conflicts = _walk(Path(repo_root), root_name, specs, probe or _probe_default)lines 211–211dep_ids = {rid for s in sources for rid in s.rows}lines 212–212root.rows = {k: v for k, v in root.rows.items() if k in root.declared or k not in dep_ids}lines 213–213sources.insert(0, root)lines 214–214nodes, dangling = _nodes(sources, trace)lines 215–215roots = tuple(f"{root_name}:{rid}" for rid in sorted(root.rows))lines 216–216tagged = _tagged(root_db)lines 217–219here = tuple( sorted(r for r, n in nodes.items() if n.catalog != root_name and n.req_id in tagged) )lines 220–220◇ for ref in herelines 221–221nodes[ref] = _served_here(nodes[ref], root.state, trace)lines 222–222reached = _reach(roots, nodes) | set(here)lines 223–223unreached = tuple(sorted(r for r in nodes if r not in reached))lines 224–224return Composite(roots, nodes, unreached, tuple(dangling), tuple(conflicts), here)

Requirements

REQ-DDB-WIKI-040

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 .

clew/wiki/composite.py:542

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
lines 550–550tree = compose(Path(repo_root), Path(repo_root).name, specs, probe=probe or _no_probe)lines 551–554return [ f"{ref} satisfies {target}, which no catalogue on the composite holds" for ref, target in tree.dangling ] + list(tree.conflicts)

Requirements

REQ-DDB-WIKI-040

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.

clew/wiki/composite.py:105

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)

Activity · 7 steps
lines 118–118db = (locate or _locate)(dep)lines 119–119◇ if db is Nonelines 120–120return ("absent", f"{dep.name} is not indexed on this machine", None)lines 121–121head = (git_text(dep, "rev-parse", "HEAD") or "").strip()lines 122–132checks = ( (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"), )lines 133–133note = next((msg for failed, msg in checks if failed()), "")lines 134–134return ("unknown" if note else "indexed", note, db)

Requirements

REQ-DDB-WIKI-040