Load graph.json as a directed graph for a node-lookup command, or exit 1. Directed so stored caller->callee direction survives the load.
(gp: Path)
| 1176 | |
| 1177 | |
| 1178 | def _load_cli_graph(gp: Path): |
| 1179 | """Load graph.json as a directed graph for a node-lookup command, or exit 1. |
| 1180 | |
| 1181 | Directed so stored caller->callee direction survives the load. |
| 1182 | """ |
| 1183 | from networkx.readwrite import json_graph |
| 1184 | from graphify.paths import consumed, read_graph_json |
| 1185 | |
| 1186 | if not gp.exists(): |
| 1187 | print(f"error: graph file not found: {gp}", file=sys.stderr) |
| 1188 | sys.exit(1) |
| 1189 | _enforce_graph_size_cap_or_exit(gp) |
| 1190 | raw = read_graph_json(gp) |
| 1191 | if "links" not in raw and "edges" in raw: |
| 1192 | raw = dict(raw, links=raw["edges"]) |
| 1193 | raw = {**raw, "directed": True} |
| 1194 | raw = dict(raw, nodes=consumed(raw["nodes"]), links=consumed(raw["links"])) |
| 1195 | return json_graph.node_link_graph(raw, edges="links") |
| 1196 | |
| 1197 | |
| 1198 | def _hook_strict_enabled(flag: bool) -> bool: |
no test coverage detected