Source code for doot.control._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 re
 17import time
 18import types
 19import collections
 20import contextlib
 21import hashlib
 22from copy import deepcopy
 23from uuid import UUID, uuid1
 24from weakref import ref
 25import atexit # for @atexit.register
 26import faulthandler
 27# ##-- end stdlib imports
 28
 29# ##-- types
 30# isort: off
 31import abc
 32import collections.abc
 33from typing import TYPE_CHECKING, cast, assert_type, assert_never
 34from typing import Generic, NewType
 35# Protocols:
 36from typing import Protocol, runtime_checkable
 37# Typing Decorators:
 38from typing import no_type_check, final
 39import pathlib as pl
 40
 41if TYPE_CHECKING:
 42    from typing import Final
 43    from typing import ClassVar, Any, LiteralString
 44    from typing import Never, Self, Literal
 45    from typing import TypeGuard
 46    from collections.abc import Iterable, Iterator, Callable, Generator
 47    from collections.abc import Sequence, Mapping, MutableMapping, Hashable
 48
 49    from logging import Logger
 50
 51    from jgdv import Maybe
 52    from jgdv.cli import ParseMachine
 53    from jgdv.cli._interface import ParseReport_d
 54    from jgdv.structs.chainguard import ChainGuard
 55    from jgdv.logging import JGDVLogConfig
 56    from jgdv.structs.locator import JGDVLocator
 57    from doot.cmd._interface import Command_p
 58    from doot.errors import DootError
 59
 60    from .._interface import Loadable
 61
 62##--|
 63
 64# isort: on
 65# ##-- end types
 66
 67##-- logging
 68logging = logmod.getLogger(__name__)
 69##-- end logging
 70
 71# Vars:
 72LOG_PREFIX  : Final[str]  = "----"
 73PYPROJ      : Final[str]  = "pyproject.toml"
 74ROOT_ELEM   : Final[str]  = "doot"
 75# Body:
 76
[docs] 77@runtime_checkable 78class Overlord_p(Protocol): 79 """ 80 protocol for the doot accesspoint, 81 used for setting up and using Doot programmatically 82 """ 83
[docs] 84 def setup(self, *, targets:Maybe[list[Loadable]]=None, prefix:str) -> None: ...
85
[docs] 86 def load(self) -> None: ...
87
[docs] 88 def load_reporter(self, target:str="default") -> None: ...
89
[docs] 90 def verify_config_version(self, ver:Maybe[str], sources:str|pl.Path, *, override:Maybe[str]=None) -> None: ...
91
[docs] 92 def update_aliases(self, *, data:dict|ChainGuard) -> None: ...
93
[docs] 94 def update_cmd_args(self, data:ParseReport_d|dict) -> None: ...
95
[docs] 96 def update_global_task_state(self, data:ChainGuard, *, source:Maybe[str]=None) -> None: ...
97
[docs] 98 def update_import_path(self, *paths:pl.Path) -> None: ...
99
[docs] 100class Overlord_i(Overlord_p, Protocol): 101 """ 102 protocol for the doot accesspoint, 103 used for setting up and using Doot programmatically 104 """ 105 __version__ : str 106 config : ChainGuard 107 constants : ChainGuard 108 aliases : ChainGuard 109 cmd_aliases : ChainGuard 110 args : ChainGuard 111 locs : JGDVLocator 112 configs_loaded_from : list[str|pl.Path] 113 global_task_state : dict 114 path_ext : list[str] 115 is_setup : bool 116 loaded_plugins : ChainGuard 117 loaded_cmds : ChainGuard 118 loaded_tasks : ChainGuard
119
[docs] 120@runtime_checkable 121class Main_p(Protocol): 122 """ 123 protocol for doot as a main program 124 """ 125 126 def __init__(self, *, args:Maybe[list]=None) -> None: ... 127 128 def __call__(self) -> None: ... 129
[docs] 130 @property 131 def name(self) -> str: ...
[docs] 132 def handle_cli_args(self) -> Maybe[int]: ...
133
[docs] 134 def help(self) -> str: ...
135
[docs] 136 def setup_logging(self) -> None: ...
137
[docs] 138class Main_i(Main_p, Protocol): 139 """ 140 protocol for doot as a main program 141 """ 142 143 result_code : int 144 prog_name : str 145 raw_args : list[str] 146 current_cmd : Maybe[Command_p] 147 parser : Maybe[ParseMachine] 148 log_config : JGDVLogConfig