mode.utils.graphs

class mode.utils.graphs.GraphFormatter(root: Any = None, type: str = None, id: str = None, indent: int = 0, inw: str = ' ', **scheme: Any)

Format dependency graphs.

edge_scheme: Mapping[str, Any] = {'arrowcolor': 'black', 'arrowsize': 0.7, 'color': 'darkseagreen4'}
node_scheme: Mapping[str, Any] = {'color': 'palegreen4', 'fillcolor': 'palegreen3'}
term_scheme: Mapping[str, Any] = {'color': 'palegreen2', 'fillcolor': 'palegreen1'}
scheme: Mapping[str, Any] = {'arrowhead': 'vee', 'fontname': 'HelveticaNeue', 'shape': 'box', 'style': 'filled'}
graph_scheme: Mapping[str, Any] = {'bgcolor': 'mintcream'}
attr(name: str, value: Any) → str
attrs(d: Mapping = None, scheme: Mapping = None) → str
head(**attrs: Any) → str
tail() → str
label(obj: _T) → str
node(obj: _T, **attrs: Any) → str
terminal_node(obj: _T, **attrs: Any) → str
edge(a: _T, b: _T, **attrs: Any) → str
FMT(fmt: str, *args: Any, **kwargs: Any) → str
draw_edge(a: _T, b: _T, scheme: Mapping = None, attrs: Mapping = None) → str
draw_node(obj: _T, scheme: Mapping = None, attrs: Mapping = None) → str
class mode.utils.graphs.DependencyGraph(it: Iterable = None, formatter: mode.utils.types.graphs.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.

adjacent: MutableMapping = None
add_arc(obj: _T) → None

Add an object to the graph.

add_edge(A: _T, B: _T) → None

Add an edge from object A to object B.

I.e. A depends on B.

connect(graph: mode.utils.types.graphs.DependencyGraphT[_T]) → None

Add nodes from another graph.

topsort() → Sequence

Sort the graph topologically.

Returns

of objects in the order in which they must be handled.

Return type

List

valency_of(obj: _T) → int

Return the valency (degree) of a vertex in the graph.

update(it: Iterable) → None

Update graph with data from a list of (obj, deps) tuples.

edges() → Iterable

Return generator that yields for all edges in the graph.

to_dot(fh: IO, *, formatter: mode.utils.types.graphs.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.

items() → a set-like object providing a view on D's items