Source code for doot.control.runner._interface

 1#!/usr/bin/env python3
 2"""
 3
 4"""
 5# ruff: noqa:
 6
 7# Imports:
 8from __future__ import annotations
 9
10# ##-- stdlib imports
11import datetime
12import enum
13import functools as ftz
14import itertools as itz
15import logging as logmod
16import pathlib as pl
17import re
18import time
19import types
20import collections
21import contextlib
22import hashlib
23from copy import deepcopy
24from uuid import UUID, uuid1
25from weakref import ref
26import atexit # for @atexit.register
27import faulthandler
28# ##-- end stdlib imports
29
30# ##-- types
31# isort: off
32import abc
33import collections.abc
34from typing import TYPE_CHECKING, cast, assert_type, assert_never
35from typing import Generic, NewType, Never
36# Protocols:
37from typing import Protocol, runtime_checkable
38# Typing Decorators:
39from typing import no_type_check, final, override, overload
40
41if TYPE_CHECKING:
42    from jgdv import Maybe, Traceback
43    from typing import Final
44    from typing import ClassVar, Any, LiteralString
45    from typing import Self, Literal, ContextManager
46    from typing import TypeGuard
47    from collections.abc import Iterable, Iterator, Callable, Generator
48    from collections.abc import Sequence, Mapping, MutableMapping, Hashable
49
50    from doot.control.tracker._interface import WorkflowTracker_p
51    from doot.workflow._interface import Artifact_i, Task_p
52##--|
53
54# isort: on
55# ##-- end types
56
57##-- logging
58logging = logmod.getLogger(__name__)
59##-- end logging
60
61# Vars:
62type Handler = bool|type[ContextManager]|ContextManager
63# Body:
64
[docs] 65@runtime_checkable 66class RunnerHandlers_p(Protocol): 67
[docs] 68 def run_next_task(self) -> None: ...
69
[docs] 70 def handle_success[T:Maybe[Task_p|Artifact_i]](self, task:T) -> T: ...
71
[docs] 72 def handle_failure(self, failure:Exception) -> None: ...
73
[docs] 74 def notify_artifact(self, art:Artifact_i) -> None: ...
75
[docs] 76 def sleep_after(self, task:Maybe[Task_p|Artifact_i]) -> None: ...
77
[docs] 78@runtime_checkable 79class WorkflowRunner_p(Protocol): 80 """ 81 Run tasks, actions, and jobs 82 """ 83 84 def __init__(self, *, tracker:WorkflowTracker_p): ... 85 def __call__(self, *tasks:str, handler:Maybe[Handler]=None) -> bool: ... 86 def __enter__(self) -> Self: ... 87 88 def __exit__(self, etype:Maybe[type], err:Maybe[Exception], tb:Maybe[Traceback]) -> bool: ...