DependencyGraph
A directed acyclic graph of objects and their dependencies.
Attributes
| Attribute | Type | Description |
|---|---|---|
| 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. |
| adjacent | dict = {} | 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
| Name | Type | Description |
|---|---|---|
| it | iterator = null | An optional iterator of (obj, dependencies) tuples to build the graph from. |
| formatter | [GraphFormatter](graphformatter.md?sid=celery_utils_graph_graphformatter) = null | An 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
| Name | Type | Description |
|---|---|---|
| obj | Any | The 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
| Name | Type | Description |
|---|---|---|
| A | Any | The source object that depends on another object. |
| B | Any | The 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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
List | List: 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
| Name | Type | Description |
|---|---|---|
| obj | Any | The vertex object whose valency is to be calculated. |
Returns
| Type | Description |
|---|---|
int | The 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
| Name | Type | Description |
|---|---|---|
| it | Iterable | An 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
| Type | Description |
|---|---|
Generator | A 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
| Name | Type | Description |
|---|---|---|
| fh | IO | A 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
| Name | Type | Description |
|---|---|---|
| obj | Any | The node object to be formatted. |
Returns
| Type | Description |
|---|---|
Any | The 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
| Name | Type | Description |
|---|---|---|
| obj | Any | The node object to represent. |
| level | int | The current indentation level for nested dependencies. |
| fmt | str | A format string used to display the node and its valency. |
Returns
| Type | Description |
|---|---|
str | A multi-line string representing the node's branch in the dependency graph. |