mode.utils.graphs

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

Format dependency graphs.

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

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[source]

Add an object to the graph.

add_edge(A: _T, B: _T) → None[source]

Add an edge from object A to object B.

I.e. A depends on B.

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

Add nodes from another graph.

topsort() → Sequence[source]

Sort the graph topologically.

Returns

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

Return type

List

valency_of(obj: _T) → int[source]

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

update(it: Iterable) → None[source]

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

edges() → Iterable[source]

Return generator that yields for all edges in the graph.

to_dot(fh: IO, *, formatter: mode.utils.types.graphs.GraphFormatterT[_T] = None) → None[source]

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[source]