Source code for doot.workflow.actions.util.util

 1#!/usr/bin/env python3
 2"""
 3Utility actions, such as a debugger
 4
 5
 6"""
 7
 8# Imports:
 9from __future__ import annotations
10
11# ##-- stdlib imports
12import bdb
13# import abc
14import datetime
15import enum
16import functools as ftz
17import itertools as itz
18import logging as logmod
19import pathlib as pl
20import re
21import time
22import types
23import weakref
24# from copy import deepcopy
25# from dataclasses import InitVar, dataclass, field
26from typing import (TYPE_CHECKING, Any, Callable, ClassVar, Final, Generator,
27                    Generic, Iterable, Iterator, Mapping, Match,
28                    MutableMapping, Protocol, Sequence, Tuple, TypeAlias,
29                    TypeGuard, TypeVar, cast, final, overload,
30                    runtime_checkable)
31from uuid import UUID, uuid1
32
33# ##-- end stdlib imports
34
35# ##-- 1st party imports
36import doot
37import doot.errors
38from doot.util.dkey import DKey
39
40# ##-- end 1st party imports
41
42##-- logging
43logging = logmod.getLogger(__name__)
44##-- end logging
45
[docs] 46def action_debugger(spec, state): 47 """ A Simple entry function for debugging spec and state """ 48 def pstate(): 49 doot.report.gen.trace("Printing State:") 50 doot.report.gen.trace(state) 51 52 def pspec(): 53 doot.report.gen.trace("Printing Spec:") 54 doot.report.gen.trace(spec) 55 56 doot.report.gen.trace("* Entering breakpoint *") 57 doot.report.gen.trace("* Call pspec() and pstate() to inspect the spec and state *") 58 59 breakpoint() 60 61 return None
62
[docs] 63def typecheck(spec, state): 64 """ a simple action to check the expansion of certain keys """ 65 for key,target_type in spec.kwargs: 66 try: 67 d_key = DKey(key) 68 value = d_key.expand(state) 69 value_type = type(value) 70 fullname = value_type.__qualname__ 71 if target_type != fullname: 72 raise doot.errors.KeyExpansionError("Type Error: state.%s : %s != %s", key, fullname, target_type) 73 74 doot.report.gen.detail("Type Matches: state.%s : %s", key, target_type) 75 76 except (AttributeError, KeyError): 77 raise doot.errors.KeyAccessError("State key missing: %s", key)