mode.utils.graphs¶
- class mode.utils.graphs.DependencyGraph(it: Optional[Iterable] = None, formatter: Optional[GraphFormatterT[_T]] = None)¶
A directed acyclic graph of objects and their dependencies.
Supports a robust topological sort to detect the order in which they must be handled.
Takes an optional iterator of
(obj, dependencies)tuples to build the graph from.Warning
Does not support cycle detection.
- add_arc(obj: _T) None¶
Add an object to the graph.
- add_edge(A: _T, B: _T) None¶
Add an edge from object
Ato objectB.I.e.
Adepends onB.
- adjacent: MutableMapping¶
- connect(graph: DependencyGraphT[_T]) None¶
Add nodes from another graph.
- edges() Iterable¶
Return generator that yields for all edges in the graph.
- items() a set-like object providing a view on D's items¶
- to_dot(fh: IO, *, formatter: Optional[GraphFormatterT[_T]] = None) None¶
Convert the graph to DOT format.
- Parameters:
fh (IO) – A file, or a file-like object to write the graph to.
formatter (celery.utils.graph.GraphFormatter) – Custom graph formatter to use.
- topsort() Sequence¶
Sort the graph topologically.
- Returns:
of objects in the order in which they must be handled.
- Return type:
list
- update(it: Iterable) None¶
Update graph with data from a list of
(obj, deps)tuples.
- valency_of(obj: _T) int¶
Return the valency (degree) of a vertex in the graph.
- class mode.utils.graphs.GraphFormatter(root: Optional[Any] = None, type: Optional[str] = None, id: Optional[str] = None, indent: int = 0, inw: str = ' ', **scheme: Any)¶
Format dependency graphs.
- FMT(fmt: str, *args: Any, **kwargs: Any) str¶
- attr(name: str, value: Any) str¶
- attrs(d: Optional[Mapping] = None, scheme: Optional[Mapping] = None) str¶
- draw_edge(a: _T, b: _T, scheme: Optional[Mapping] = None, attrs: Optional[Mapping] = None) str¶
- draw_node(obj: _T, scheme: Optional[Mapping] = None, attrs: Optional[Mapping] = None) str¶
- edge(a: _T, b: _T, **attrs: Any) str¶
- edge_scheme: Mapping[str, Any] = {'arrowcolor': 'black', 'arrowsize': 0.7, 'color': 'darkseagreen4'}¶
- graph_scheme: Mapping[str, Any] = {'bgcolor': 'mintcream'}¶
- head(**attrs: Any) str¶
- label(obj: _T) str¶
- node(obj: _T, **attrs: Any) str¶
- node_scheme: Mapping[str, Any] = {'color': 'palegreen4', 'fillcolor': 'palegreen3'}¶
- scheme: Mapping[str, Any] = {'arrowhead': 'vee', 'fontname': 'HelveticaNeue', 'shape': 'box', 'style': 'filled'}¶
- tail() str¶
- term_scheme: Mapping[str, Any] = {'color': 'palegreen2', 'fillcolor': 'palegreen1'}¶
- terminal_node(obj: _T, **attrs: Any) str¶