Source code for dootle.control.fsm._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
 30from importlib.metadata import EntryPoint
 31
 32# ##-- types
 33# isort: off
 34import abc
 35import collections.abc
 36from typing import TYPE_CHECKING, cast, assert_type, assert_never
 37from typing import Generic, NewType, Never
 38# Protocols:
 39from typing import Protocol, runtime_checkable
 40# Typing Decorators:
 41from typing import no_type_check, final, override, overload
 42# from dataclasses import InitVar, dataclass, field
 43# from pydantic import BaseModel, Field, model_validator, field_validator, ValidationError
 44
 45if TYPE_CHECKING:
 46    from jgdv import Maybe
 47    from typing import Final
 48    from typing import ClassVar, Any, LiteralString
 49    from typing import Self, Literal
 50    from typing import TypeGuard
 51    from collections.abc import Iterable, Iterator, Callable, Generator
 52    from collections.abc import Sequence, Mapping, MutableMapping, Hashable
 53
 54    from doot.control.tracker._interface import WorkflowTracker_p
 55    from statemachine import State
 56
 57##--|
 58
 59# isort: on
 60# ##-- end types
 61
 62##-- logging
 63logging = logmod.getLogger(__name__)
 64##-- end logging
 65
 66# Vars:
 67MAX_LOOP        : Final[int]         = 100
 68SETUP_GROUP     : Final[str]         = "setup"
 69ACTION_GROUP    : Final[str]         = "actions"
 70FAIL_GROUP      : Final[str]         = "on_fail"
 71DEPENDS_GROUP   : Final[str]         = "depends_on"
 72CLEANUP_GROUP   : Final[str]         = "cleanup"
 73
 74TASK_EP         : Final[EntryPoint]  = EntryPoint("task", group="doot.aliases.task", value="dootle.control.fsm.task:FSMTask")
 75ALIASES_UPDATE  : Final[dict]        = {
 76    "task" : [TASK_EP],
 77}
 78# Body:
 79
[docs] 80@runtime_checkable 81class TaskModel_Conditions_p(Protocol): 82 """ The conditions a TaskTrackFSM calls """ 83
[docs] 84 def spec_missing(self, *, tracker:WorkflowTracker_p) -> bool: ...
85
[docs] 86 def should_disable(self, source:State, *, tracker:WorkflowTracker_p) -> bool: ...
87
[docs] 88 def should_wait(self, *, tracker:WorkflowTracker_p) -> bool: ...
89
[docs] 90 def should_timeout(self) -> bool: ...
91
[docs] 92 def should_skip(self) -> bool: ...
93
[docs] 94 def should_halt(self) -> bool: ...
95
[docs] 96 def should_fail(self) -> bool: ...
97
[docs] 98 def state_is_needed(self, *, tracker:WorkflowTracker_p) -> bool: ...
99
[docs] 100@runtime_checkable 101class TaskModel_Callbacks_p(Protocol): 102 """ 103 Describes the callbacks for the FSM of a task 104 """ 105
[docs] 106 def on_enter_INIT(self, *, tracker:WorkflowTracker_p) -> None: ... # noqa: N802
107
[docs] 108 def on_enter_RUNNING(self, *, step:int, tracker:WorkflowTracker_p) -> None: ... # noqa: N802
109
[docs] 110 def on_enter_HALTED(self, *, tracker:WorkflowTracker_p) -> None: ... # noqa: N802
111
[docs] 112 def on_enter_FAILED(self, *, tracker:WorkflowTracker_p) -> None: ... # noqa: N802
113
[docs] 114 def on_exit_TEARDOWN(self) -> None: ... # noqa: N802
115
[docs] 116class TaskModel_p(TaskModel_Callbacks_p, TaskModel_Conditions_p, Protocol): 117 """ 118 Combines the TaskModel Conditions and Callbacks protocols 119 """ 120 pass
121
[docs] 122@runtime_checkable 123class ArtifactModel_p(Protocol): 124 """ Describes the callbacks for an FSM of a task """ 125
[docs] 126 def is_stale(self) -> bool: ...
127
[docs] 128 def should_clean(self) -> bool: ...
129
[docs] 130 def does_exist(self) -> bool: ...