onsrap.graph module¶
- class onsrap.graph.StageGraph(stages: list[~onsrap.stage.Stage] = <factory>)¶
Bases:
objectRepresents an order to run stages.
Holds an order that stages need to run in based on dependencies and logic.
- Parameters:
stages (list of
Stageclass items)
- classmethod from_stages(stages: Iterable[Stage]) StageGraph¶
This is the primary constructor for StageGraph, which performs validation and normalization of the stage list.
- Parameters:
stages (Iterable of
Stageclass instances)- Return type:
The
stagesparameter as a list.
- topological_order() list[Stage]¶
Return the stages in an order that respects their dependencies.
In graph terms, this is a topological sort: if stage
Bdepends on stageA, thenAwill always appear beforeBin the returned list. The word “topological” here does not refer to geographic maps or terrain; it means we are arranging nodes in a dependency-safe order.The implementation works by repeatedly selecting stages that currently have no unmet dependencies. Those stages are “ready” to run because nothing else needs to happen first. After a ready stage is placed in the output order, the algorithm removes it from the dependency lists of the stages that depend on it. That may free up more stages, which are then added to the ready list.
- Returns:
A list of stages ordered in the way that they need to be run through the
pipeline.
- Raises:
DependencyCycleError – If the algorithm cannot place every stage, the graph contains either a cycle or a dependency that could not be resolved.
- validate() None¶
Validate the stage graph for issues such as duplicate stage names, missing dependencies, and cycles.
- Raises:
DuplicateStageError – If the stage name appears multiple times in the stage list.
MissingDependencyError – If there are unknown dependencies.