Download stackgo/stackbuild/graph.py from s0duku/the-stack-go: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/datasets/s0duku/the-stack-go/resolve/main/stackgo/stackbuild/graph.py
- Command line
-
hf download hf://datasets/s0duku/the-stack-go/stackgo/stackbuild/graph.py
-
curl -L -o graph.py https://huggingface.co/datasets/s0duku/the-stack-go/resolve/main/stackgo/stackbuild/graph.py
1.3 kB
| """Composition-oriented graph operations over RepoInfo.""" | |
| from __future__ import annotations | |
| from collections import defaultdict | |
| from .repo import RepoInfo | |
| def dependency_components(info: RepoInfo) -> tuple[tuple[str, ...], ...]: | |
| """Return weakly connected hard-dependency components in topo order.""" | |
| neighbors: dict[str, set[str]] = defaultdict(set) | |
| for edge in info.edges: | |
| if edge.status != "resolved" or edge.source == edge.target: | |
| continue | |
| neighbors[edge.source].add(edge.target) | |
| neighbors[edge.target].add(edge.source) | |
| position = {path: index for index, path in enumerate(info.topological_order)} | |
| unseen = set(position) | |
| result: list[tuple[str, ...]] = [] | |
| for start in info.topological_order: | |
| if start not in unseen: | |
| continue | |
| unseen.remove(start) | |
| members: set[str] = {start} | |
| stack = [start] | |
| while stack: | |
| current = stack.pop() | |
| for neighbor in neighbors.get(current, ()): | |
| if neighbor in unseen: | |
| unseen.remove(neighbor) | |
| members.add(neighbor) | |
| stack.append(neighbor) | |
| result.append(tuple(path for path in info.topological_order if path in members)) | |
| return tuple(result) | |