Skip to main content

DependencyGraph

A directed acyclic graph of objects and their dependencies.

Attributes

AttributeTypeDescription
formatter[GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter) = GraphFormatter()A GraphFormatter instance used to customize the visual representation and labeling of nodes and edges when exporting to DOT format.
adjacentdict = {}A dictionary mapping each object to a list of its direct dependencies, representing the adjacency list of the directed graph.

Constructor

Signature

def DependencyGraph(
it: iterator = null,
formatter: [GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter) = null
) - > null

Parameters

NameTypeDescription
ititerator = nullAn optional iterator of (obj, dependencies) tuples to build the graph from.
formatter[GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter) = nullAn optional custom graph formatter; defaults to a new GraphFormatter instance if not provided.

Methods


add_arc()

@classmethod
def add_arc(
obj: Any
)

Add an object to the graph.

Parameters

NameTypeDescription
objAnyThe object to be added as a node in the graph.

add_edge()

@classmethod
def add_edge(
A: Any,
B: Any
)

Add an edge from object A to object B.

Parameters

NameTypeDescription
AAnyThe source object that depends on another object.
BAnyThe target object that is a dependency of the source.

connect()

@classmethod
def connect(
graph: [DependencyGraph](dependencygraph.md?sid=celery_utils_graph_dependencygraph)
)

Add nodes from another graph.

Parameters

NameTypeDescription
graph[DependencyGraph](dependencygraph.md?sid=celery_utils_graph_dependencygraph)Another DependencyGraph instance whose adjacency data will be merged into this graph.

topsort()

@classmethod
def topsort() - > List

Sort the graph topologically.

Returns

TypeDescription
ListList: of objects in the order in which they must be handled.

valency_of()

@classmethod
def valency_of(
obj: Any
) - > int

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

Parameters

NameTypeDescription
objAnyThe vertex object whose valency is to be calculated.

Returns

TypeDescription
intThe total count of recursive dependencies for the specified object.

update()

@classmethod
def update(
it: Iterable
)

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

Parameters

NameTypeDescription
itIterableAn iterator of tuples where each tuple contains an object and a list of its dependencies.

edges()

@classmethod
def edges() - > Generator

Return generator that yields for all edges in the graph.

Returns

TypeDescription
GeneratorA generator yielding objects that have at least one outgoing edge (dependency).

to_dot()

@classmethod
def to_dot(
fh: IO,
formatter: [GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter)
)

Convert the graph to DOT format.

Parameters

NameTypeDescription
fhIOA file, or a file-like object to write the graph to.
formatter[GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter)Custom graph formatter to use.

format()

@classmethod
def format(
obj: Any
) - > Any

Formats a node object using the configured graph formatter.

Parameters

NameTypeDescription
objAnyThe node object to be formatted.

Returns

TypeDescription
AnyThe formatted representation of the object, or the object itself if no formatter is set.

repr_node()

@classmethod
def repr_node(
obj: Any,
level: int,
fmt: str
) - > str

Generates a formatted string representation of a node and its recursive dependencies.

Parameters

NameTypeDescription
objAnyThe node object to represent.
levelintThe current indentation level for nested dependencies.
fmtstrA format string used to display the node and its valency.

Returns

TypeDescription
strA multi-line string representing the node's branch in the dependency graph.