finesse.utilities.graph module
Functions to aid manipulation of networkx graphs as well as some graph related utilities.
- finesse.utilities.graph.class_graph(cls, G=None)[source]
Creates a directed graph from a class and all of its base classes.
objectis ignored because every class derives from object and so it just clutters up the graph.
- finesse.utilities.graph.class_graph_from_module_graph(module_graph, G=None)[source]
Creates a directed graph for all the classes and base classes in the module graph.
- finesse.utilities.graph.copy_graph(G)[source]
A trick I often see in networkx’s codebase to copy a graph.
type(G) returns the class of G (e.g. nx.DiGraph) which can accept a graph to make a copy of. Useful for writing ‘pure’ functions on graphs.
- finesse.utilities.graph.get_source_nodes(G)[source]
A source node is a node with no incoming edges.
- finesse.utilities.graph.module_graph(module, G=None, external_modules=False, include_root_module=False)[source]
Creates a directed graph from a module and all of its submodules. External submodules can be included in graph but they will not be traversed since that could cause the graph to walk an absurd number of packages.
The root module is typically not included since it tends to clutter the graph.
- finesse.utilities.graph.remove_orphans(G, inplace=False)[source]
Removes nodes with in and out degree 0 from graph G.
This should not need to be recursive.