Dependencies

Direct dependencies are the tasks named by a step’s dependency declarations, after task placeholders and result queries are expanded. Full dependencies also include the dependencies of those tasks.

get_task_dependencies returns direct dependencies for one task. get_full_task_dependencies returns the full mapping for the recipe and detects cycles. reverse_task_dependencies reverses a mapping so that each task lists its dependants.

These functions do not limit the results inspected by selectors. See Result reference scope for the scope of outcome references.

Methods for resolving result dependencies

momotor.options.dependencies.get_full_task_dependencies(recipe, config)

Generate the full dependency tree for all steps in the recipe. For each task, list every task it depends on, including dependencies of dependencies.

Task ordering is preserved: the tasks listed in the result, both the dict keys and the tuple values, are in the same order as the definitions in the recipe.

Parameters:
  • recipe (RecipeBundle) – the recipe containing the steps

  • config (ConfigBundle | None) – (optionally) the config containing step options

Return type:

dict[StepTaskId, tuple[StepTaskId, ...]]

Returns:

the tasks to tasks mapping. the ordering is guaranteed to be same as the order of the steps in the recipe

Raises:
momotor.options.dependencies.get_task_dependencies(recipe, config, task_id)

Get direct dependencies for a single task.

Task ordering is preserved: the tasks listed in the result are in the same order as the definitions in the recipe.

Parameters:
  • recipe (RecipeBundle) – the recipe containing the steps

  • config (ConfigBundle | None) – (optionally) the config containing step options

  • task_id (StepTaskId) – the task to generate the dependencies of

Return type:

tuple[StepTaskId, ...]

Returns:

the dependencies

Raises:

InvalidDependencies – if the recipe contains invalid dependencies

momotor.options.dependencies.reverse_task_dependencies(dependencies)

Reverses the dependency tree generated by get_full_task_dependencies(). Each task maps to the tasks that depend on it.

Task ordering is preserved: the tasks listed in the result, both the dict keys and the tuple values, are in the same order as in the dependencies argument.

Parameters:

dependencies (Mapping[StepTaskId, Iterable[StepTaskId]]) – the task dependencies

Return type:

dict[StepTaskId, tuple[StepTaskId, ...]]

Returns:

the reverse dependencies