Dump the graph as a JSON string to stdout. This copies some of the work by process_graph() (sorted_components() and order_ascc()).
(graph: Graph, stdout: TextIO | None = None)
| 4213 | |
| 4214 | |
| 4215 | def dump_graph(graph: Graph, stdout: TextIO | None = None) -> None: |
| 4216 | """Dump the graph as a JSON string to stdout. |
| 4217 | |
| 4218 | This copies some of the work by process_graph() |
| 4219 | (sorted_components() and order_ascc()). |
| 4220 | """ |
| 4221 | stdout = stdout or sys.stdout |
| 4222 | nodes = [] |
| 4223 | sccs = sorted_components(graph) |
| 4224 | for i, ascc in enumerate(sccs): |
| 4225 | scc = order_ascc(graph, ascc.mod_ids) |
| 4226 | node = NodeInfo(i, scc) |
| 4227 | nodes.append(node) |
| 4228 | inv_nodes = {} # module -> node_id |
| 4229 | for node in nodes: |
| 4230 | for mod in node.scc: |
| 4231 | inv_nodes[mod] = node.node_id |
| 4232 | for node in nodes: |
| 4233 | for mod in node.scc: |
| 4234 | state = graph[mod] |
| 4235 | size = 0 |
| 4236 | if state.path: |
| 4237 | try: |
| 4238 | size = os.path.getsize(state.path) |
| 4239 | except OSError: |
| 4240 | pass |
| 4241 | node.sizes[mod] = size |
| 4242 | for dep in state.dependencies: |
| 4243 | if dep in state.priorities: |
| 4244 | pri = state.priorities[dep] |
| 4245 | if dep in inv_nodes: |
| 4246 | dep_id = inv_nodes[dep] |
| 4247 | if dep_id != node.node_id and ( |
| 4248 | dep_id not in node.deps or pri < node.deps[dep_id] |
| 4249 | ): |
| 4250 | node.deps[dep_id] = pri |
| 4251 | print("[" + ",\n ".join(node.dumps() for node in nodes) + "\n]", file=stdout) |
| 4252 | |
| 4253 | |
| 4254 | def load_graph( |
no test coverage detected
searching dependent graphs…