MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / load_graph

Function load_graph

graphify/callflow_html.py:265–306  ·  view source on GitHub ↗

Load graph.json. Returns normalized (nodes, edges, hyperedges, metadata).

(path: str | Path)

Source from the content-addressed store, hash-verified

263
264
265def load_graph(path: str | Path) -> tuple:
266 """Load graph.json. Returns normalized (nodes, edges, hyperedges, metadata)."""
267 if path:
268 from graphify.security import check_graph_file_size_cap
269 try:
270 check_graph_file_size_cap(Path(path))
271 except ValueError as exc:
272 raise SystemExit(f"ERROR: {exc}") from exc
273 data = read_json(path)
274 if not isinstance(data, dict):
275 raise SystemExit(f"ERROR: graph file must contain a JSON object: {path}")
276
277 graph_block = data.get("graph") if isinstance(data.get("graph"), dict) else {}
278 meta_block = data.get("metadata") if isinstance(data.get("metadata"), dict) else {}
279
280 node_link = _node_link_payload(data)
281 if node_link:
282 raw_nodes, raw_edges = node_link
283 else:
284 raw_nodes = first_list(data.get("nodes"), data.get("vertices"), graph_block.get("nodes"), graph_block.get("vertices"))
285 raw_edges = first_list(data.get("links"), data.get("edges"), graph_block.get("links"), graph_block.get("edges"))
286 raw_hyperedges = first_list(data.get("hyperedges"), graph_block.get("hyperedges"), data.get("groups"), graph_block.get("groups"))
287 hyperedges = [h for h in raw_hyperedges if isinstance(h, dict)]
288
289 nodes = [normalize_node(n, i) for i, n in enumerate(raw_nodes) if isinstance(n, dict)]
290 edges = []
291 for i, raw_edge in enumerate(raw_edges):
292 if not isinstance(raw_edge, dict):
293 continue
294 edge = normalize_edge(raw_edge, i)
295 if edge:
296 edges.append(edge)
297
298 meta = dict(graph_block)
299 meta.update(meta_block)
300 for key in ("built_at_commit", "commit", "project_name", "repo", "repository", "language_breakdown"):
301 if data.get(key) and not meta.get(key):
302 meta[key] = data.get(key)
303 if meta.get("commit") and not meta.get("built_at_commit"):
304 meta["built_at_commit"] = meta["commit"]
305
306 return nodes, edges, hyperedges, meta
307
308
309def load_labels(path: str | Path | None) -> dict:

Calls 8

read_jsonFunction · 0.85
_node_link_payloadFunction · 0.85
first_listFunction · 0.85
normalize_nodeFunction · 0.85
normalize_edgeFunction · 0.85
updateMethod · 0.80
getMethod · 0.45