omlish 0.0.0.dev418__py3-none-any.whl → 0.0.0.dev420__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- omlish/__about__.py +2 -2
- omlish/configs/all.py +39 -32
- omlish/configs/processing/all.py +32 -26
- omlish/daemons/launching.py +1 -1
- omlish/formats/json/backends/default.py +14 -7
- omlish/formats/json/backends/orjson.py +1 -0
- omlish/formats/toml/parser.py +2 -2
- omlish/lang/__init__.py +31 -11
- omlish/lang/contextmanagers.py +81 -16
- omlish/lang/imports/proxyinit.py +2 -2
- omlish/lang/{maysyncs.py → maysync.py} +3 -3
- omlish/lifecycles/__init__.py +14 -1
- omlish/lifecycles/abstract.py +40 -0
- omlish/lifecycles/base.py +73 -23
- omlish/lifecycles/controller.py +94 -47
- omlish/logs/all.py +45 -38
- omlish/marshal/base/registries.py +6 -0
- omlish/math/__init__.py +89 -83
- omlish/subprocesses/{maysyncs.py → maysync.py} +1 -1
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/METADATA +2 -2
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/RECORD +26 -26
- /omlish/lite/{maysyncs.py → maysync.py} +0 -0
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev418.dist-info → omlish-0.0.0.dev420.dist-info}/top_level.txt +0 -0
omlish/lifecycles/controller.py
CHANGED
@@ -1,99 +1,95 @@
|
|
1
|
+
import abc
|
1
2
|
import typing as ta
|
2
3
|
|
3
4
|
from .. import check
|
4
5
|
from .. import defs
|
5
6
|
from .. import lang
|
6
|
-
from .base import
|
7
|
+
from .base import AnyLifecycle # noqa
|
8
|
+
from .base import Lifecycle # noqa
|
7
9
|
from .states import LifecycleState
|
8
10
|
from .states import LifecycleStates
|
9
11
|
from .transitions import LifecycleTransition
|
10
12
|
from .transitions import LifecycleTransitions
|
11
13
|
|
12
14
|
|
15
|
+
R = ta.TypeVar('R')
|
16
|
+
|
17
|
+
AnyLifecycleT = ta.TypeVar('AnyLifecycleT', bound='AnyLifecycle')
|
18
|
+
|
13
19
|
LifecycleT = ta.TypeVar('LifecycleT', bound='Lifecycle')
|
14
20
|
|
15
21
|
|
16
22
|
##
|
17
23
|
|
18
24
|
|
19
|
-
class
|
20
|
-
def on_starting(self, obj:
|
21
|
-
|
25
|
+
class AnyLifecycleListener(ta.Generic[AnyLifecycleT, R]):
|
26
|
+
def on_starting(self, obj: AnyLifecycleT) -> R | None:
|
27
|
+
return None
|
22
28
|
|
23
|
-
def on_started(self, obj:
|
24
|
-
|
29
|
+
def on_started(self, obj: AnyLifecycleT) -> R | None:
|
30
|
+
return None
|
25
31
|
|
26
|
-
def on_stopping(self, obj:
|
27
|
-
|
32
|
+
def on_stopping(self, obj: AnyLifecycleT) -> R | None:
|
33
|
+
return None
|
28
34
|
|
29
|
-
def on_stopped(self, obj:
|
30
|
-
|
35
|
+
def on_stopped(self, obj: AnyLifecycleT) -> R | None:
|
36
|
+
return None
|
31
37
|
|
32
38
|
|
33
|
-
class
|
39
|
+
class AnyLifecycleController(AnyLifecycle[R], lang.Abstract, ta.Generic[AnyLifecycleT, R]):
|
34
40
|
def __init__(
|
35
41
|
self,
|
36
|
-
lifecycle:
|
37
|
-
*,
|
38
|
-
lock: lang.DefaultLockable = None,
|
42
|
+
lifecycle: AnyLifecycleT,
|
39
43
|
) -> None:
|
40
44
|
super().__init__()
|
41
45
|
|
42
|
-
self._lifecycle:
|
43
|
-
self._lock = lang.default_lock(lock, False)
|
46
|
+
self._lifecycle: AnyLifecycleT = check.isinstance(lifecycle, AnyLifecycle) # type: ignore
|
44
47
|
|
45
48
|
self._state = LifecycleStates.NEW
|
46
|
-
self._listeners: list[
|
49
|
+
self._listeners: list[AnyLifecycleListener[AnyLifecycleT, R]] = []
|
47
50
|
|
48
51
|
defs.repr('lifecycle', 'state')
|
49
52
|
|
50
53
|
@property
|
51
|
-
def lifecycle(self) ->
|
54
|
+
def lifecycle(self) -> AnyLifecycleT:
|
52
55
|
return self._lifecycle
|
53
56
|
|
54
57
|
@property
|
55
58
|
def state(self) -> LifecycleState:
|
56
59
|
return self._state
|
57
60
|
|
58
|
-
def add_listener(self, listener:
|
59
|
-
self._listeners.append(check.isinstance(listener,
|
61
|
+
def add_listener(self, listener: AnyLifecycleListener[AnyLifecycleT, R]) -> ta.Self:
|
62
|
+
self._listeners.append(check.isinstance(listener, AnyLifecycleListener))
|
60
63
|
return self
|
61
64
|
|
65
|
+
@abc.abstractmethod
|
62
66
|
def _advance(
|
63
67
|
self,
|
64
68
|
transition: LifecycleTransition,
|
65
|
-
lifecycle_fn: ta.Callable[[], None],
|
66
|
-
pre_listener_fn: ta.Callable[
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
lifecycle_fn()
|
77
|
-
except Exception:
|
78
|
-
self._state = transition.new_failed
|
79
|
-
raise
|
80
|
-
self._state = transition.new_succeeded
|
81
|
-
if post_listener_fn is not None:
|
82
|
-
for listener in self._listeners:
|
83
|
-
post_listener_fn(listener)(self._lifecycle)
|
69
|
+
lifecycle_fn: ta.Callable[[], R | None],
|
70
|
+
pre_listener_fn: ta.Callable[
|
71
|
+
[AnyLifecycleListener[AnyLifecycleT, R]],
|
72
|
+
ta.Callable[[AnyLifecycleT], R | None],
|
73
|
+
] | None = None,
|
74
|
+
post_listener_fn: ta.Callable[
|
75
|
+
[AnyLifecycleListener[AnyLifecycleT, R]],
|
76
|
+
ta.Callable[[AnyLifecycleT], R | None],
|
77
|
+
] | None = None,
|
78
|
+
) -> R | None:
|
79
|
+
raise NotImplementedError
|
84
80
|
|
85
81
|
##
|
86
82
|
|
87
83
|
@ta.override
|
88
|
-
def lifecycle_construct(self) -> None:
|
89
|
-
self._advance(
|
84
|
+
def lifecycle_construct(self) -> R | None:
|
85
|
+
return self._advance(
|
90
86
|
LifecycleTransitions.CONSTRUCT,
|
91
87
|
self._lifecycle.lifecycle_construct,
|
92
88
|
)
|
93
89
|
|
94
90
|
@ta.override
|
95
|
-
def lifecycle_start(self) -> None:
|
96
|
-
self._advance(
|
91
|
+
def lifecycle_start(self) -> R | None:
|
92
|
+
return self._advance(
|
97
93
|
LifecycleTransitions.START,
|
98
94
|
self._lifecycle.lifecycle_start,
|
99
95
|
lambda l: l.on_starting,
|
@@ -101,8 +97,8 @@ class LifecycleController(Lifecycle, ta.Generic[LifecycleT]):
|
|
101
97
|
)
|
102
98
|
|
103
99
|
@ta.override
|
104
|
-
def lifecycle_stop(self) -> None:
|
105
|
-
self._advance(
|
100
|
+
def lifecycle_stop(self) -> R | None:
|
101
|
+
return self._advance(
|
106
102
|
LifecycleTransitions.STOP,
|
107
103
|
self._lifecycle.lifecycle_stop,
|
108
104
|
lambda l: l.on_stopping,
|
@@ -110,8 +106,59 @@ class LifecycleController(Lifecycle, ta.Generic[LifecycleT]):
|
|
110
106
|
)
|
111
107
|
|
112
108
|
@ta.override
|
113
|
-
def lifecycle_destroy(self) -> None:
|
114
|
-
self._advance(
|
109
|
+
def lifecycle_destroy(self) -> R | None:
|
110
|
+
return self._advance(
|
115
111
|
LifecycleTransitions.DESTROY,
|
116
112
|
self._lifecycle.lifecycle_destroy,
|
117
113
|
)
|
114
|
+
|
115
|
+
|
116
|
+
##
|
117
|
+
|
118
|
+
|
119
|
+
LifecycleListener: ta.TypeAlias = AnyLifecycleListener[LifecycleT, None]
|
120
|
+
|
121
|
+
|
122
|
+
class LifecycleController(
|
123
|
+
AnyLifecycleController[LifecycleT, None],
|
124
|
+
Lifecycle,
|
125
|
+
ta.Generic[LifecycleT],
|
126
|
+
):
|
127
|
+
def __init__(
|
128
|
+
self,
|
129
|
+
lifecycle: LifecycleT,
|
130
|
+
*,
|
131
|
+
lock: lang.DefaultLockable = None,
|
132
|
+
) -> None:
|
133
|
+
super().__init__(lifecycle)
|
134
|
+
|
135
|
+
self._lock = lang.default_lock(lock, False)
|
136
|
+
|
137
|
+
def _advance(
|
138
|
+
self,
|
139
|
+
transition: LifecycleTransition,
|
140
|
+
lifecycle_fn: ta.Callable[[], None],
|
141
|
+
pre_listener_fn: ta.Callable[
|
142
|
+
[LifecycleListener[LifecycleT]],
|
143
|
+
ta.Callable[[LifecycleT], None],
|
144
|
+
] | None = None,
|
145
|
+
post_listener_fn: ta.Callable[
|
146
|
+
[LifecycleListener[LifecycleT]],
|
147
|
+
ta.Callable[[LifecycleT], None],
|
148
|
+
] | None = None,
|
149
|
+
) -> None:
|
150
|
+
with self._lock():
|
151
|
+
if pre_listener_fn is not None:
|
152
|
+
for listener in self._listeners:
|
153
|
+
pre_listener_fn(listener)(self._lifecycle)
|
154
|
+
check.state(self._state in transition.old)
|
155
|
+
self._state = transition.new_intermediate
|
156
|
+
try:
|
157
|
+
lifecycle_fn()
|
158
|
+
except Exception:
|
159
|
+
self._state = transition.new_failed
|
160
|
+
raise
|
161
|
+
self._state = transition.new_succeeded
|
162
|
+
if post_listener_fn is not None:
|
163
|
+
for listener in self._listeners:
|
164
|
+
post_listener_fn(listener)(self._lifecycle)
|
omlish/logs/all.py
CHANGED
@@ -1,50 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
)
|
1
|
+
# rufF: noqa: I001
|
2
|
+
from .. import lang as _lang
|
4
3
|
|
5
|
-
from .color import ( # noqa
|
6
|
-
ColorLogFormatter,
|
7
|
-
)
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
)
|
5
|
+
with _lang.auto_proxy_init(globals()):
|
6
|
+
##
|
12
7
|
|
13
|
-
from .
|
14
|
-
|
15
|
-
)
|
8
|
+
from .callers import ( # noqa
|
9
|
+
LoggingCaller,
|
10
|
+
)
|
16
11
|
|
17
|
-
from .
|
18
|
-
|
19
|
-
)
|
12
|
+
from .color import ( # noqa
|
13
|
+
ColorLogFormatter,
|
14
|
+
)
|
20
15
|
|
21
|
-
from .
|
22
|
-
|
23
|
-
)
|
16
|
+
from .filters import ( # noqa
|
17
|
+
TidLogFilter,
|
18
|
+
)
|
24
19
|
|
25
|
-
from .
|
26
|
-
|
20
|
+
from .handlers import ( # noqa
|
21
|
+
ListHandler,
|
22
|
+
)
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
StdlibLogging,
|
32
|
-
)
|
24
|
+
from .json import ( # noqa
|
25
|
+
JsonLogFormatter,
|
26
|
+
)
|
33
27
|
|
34
|
-
from .
|
35
|
-
|
36
|
-
|
37
|
-
)
|
28
|
+
from .noisy import ( # noqa
|
29
|
+
silence_noisy_loggers,
|
30
|
+
)
|
38
31
|
|
39
|
-
from .
|
40
|
-
|
41
|
-
StandardLogFormatter,
|
32
|
+
from .protocol import ( # noqa
|
33
|
+
LogLevel,
|
42
34
|
|
43
|
-
|
35
|
+
Logging,
|
36
|
+
NopLogging,
|
37
|
+
AbstractLogging,
|
38
|
+
StdlibLogging,
|
39
|
+
)
|
44
40
|
|
45
|
-
|
46
|
-
|
41
|
+
from .proxy import ( # noqa
|
42
|
+
ProxyLogFilterer,
|
43
|
+
ProxyLogHandler,
|
44
|
+
)
|
47
45
|
|
48
|
-
from .
|
49
|
-
|
50
|
-
|
46
|
+
from .standard import ( # noqa
|
47
|
+
STANDARD_LOG_FORMAT_PARTS,
|
48
|
+
StandardLogFormatter,
|
49
|
+
|
50
|
+
StandardConfiguredLogHandler,
|
51
|
+
|
52
|
+
configure_standard_logging,
|
53
|
+
)
|
54
|
+
|
55
|
+
from .utils import ( # noqa
|
56
|
+
error_logging,
|
57
|
+
)
|
@@ -53,6 +53,7 @@ class Registry(ta.Generic[RegistryItemT]):
|
|
53
53
|
self._dct: dict[ta.Any, _KeyRegistryItems[RegistryItemT]] = {}
|
54
54
|
self._id_dct: ta.MutableMapping[ta.Any, _KeyRegistryItems[RegistryItemT]] = col.IdentityKeyDict()
|
55
55
|
|
56
|
+
self._version = 0
|
56
57
|
self._sealed = False
|
57
58
|
|
58
59
|
#
|
@@ -84,6 +85,9 @@ class Registry(ta.Generic[RegistryItemT]):
|
|
84
85
|
*items: RegistryItemT,
|
85
86
|
identity: bool = False,
|
86
87
|
) -> ta.Self:
|
88
|
+
if not items:
|
89
|
+
return self
|
90
|
+
|
87
91
|
with self._lock:
|
88
92
|
if self._sealed:
|
89
93
|
raise RegistrySealedError(self)
|
@@ -93,6 +97,8 @@ class Registry(ta.Generic[RegistryItemT]):
|
|
93
97
|
sr = dct[key] = _KeyRegistryItems(key)
|
94
98
|
sr.add(*items)
|
95
99
|
|
100
|
+
self._version += 1
|
101
|
+
|
96
102
|
return self
|
97
103
|
|
98
104
|
#
|
omlish/math/__init__.py
CHANGED
@@ -1,83 +1,89 @@
|
|
1
|
-
from
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
)
|
74
|
-
|
75
|
-
from .
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
)
|
80
|
-
|
81
|
-
from .
|
82
|
-
|
83
|
-
|
1
|
+
from .. import lang as _lang
|
2
|
+
|
3
|
+
|
4
|
+
with _lang.auto_proxy_init(globals()):
|
5
|
+
##
|
6
|
+
|
7
|
+
from .bits import ( # noqa
|
8
|
+
get_bit,
|
9
|
+
get_bits,
|
10
|
+
set_bit,
|
11
|
+
set_bits,
|
12
|
+
)
|
13
|
+
|
14
|
+
from .c import ( # noqa
|
15
|
+
cdiv,
|
16
|
+
cmod,
|
17
|
+
)
|
18
|
+
|
19
|
+
from .fixed import ( # noqa
|
20
|
+
CheckedFixedWidthIntError,
|
21
|
+
OverflowFixedWidthIntError,
|
22
|
+
UnderflowFixedWidthIntError,
|
23
|
+
|
24
|
+
FixedWidthInt,
|
25
|
+
|
26
|
+
SignedInt,
|
27
|
+
UnsignedInt,
|
28
|
+
|
29
|
+
CheckedInt,
|
30
|
+
ClampedInt,
|
31
|
+
|
32
|
+
AnyInt8,
|
33
|
+
AnyInt16,
|
34
|
+
AnyInt32,
|
35
|
+
AnyInt64,
|
36
|
+
AnyInt128,
|
37
|
+
|
38
|
+
CheckedInt8,
|
39
|
+
CheckedInt16,
|
40
|
+
CheckedInt32,
|
41
|
+
CheckedInt64,
|
42
|
+
CheckedInt128,
|
43
|
+
|
44
|
+
CheckedUint8,
|
45
|
+
CheckedUint16,
|
46
|
+
CheckedUint32,
|
47
|
+
CheckedUint64,
|
48
|
+
CheckedUint128,
|
49
|
+
|
50
|
+
ClampedInt8,
|
51
|
+
ClampedInt16,
|
52
|
+
ClampedInt32,
|
53
|
+
ClampedInt64,
|
54
|
+
ClampedInt128,
|
55
|
+
|
56
|
+
ClampedUint8,
|
57
|
+
ClampedUint16,
|
58
|
+
ClampedUint32,
|
59
|
+
ClampedUint64,
|
60
|
+
ClampedUint128,
|
61
|
+
|
62
|
+
WrappedInt8,
|
63
|
+
WrappedInt16,
|
64
|
+
WrappedInt32,
|
65
|
+
WrappedInt64,
|
66
|
+
WrappedInt128,
|
67
|
+
|
68
|
+
WrappedUint8,
|
69
|
+
WrappedUint16,
|
70
|
+
WrappedUint32,
|
71
|
+
WrappedUint64,
|
72
|
+
WrappedUint128,
|
73
|
+
)
|
74
|
+
|
75
|
+
from .floats import ( # noqa
|
76
|
+
isclose,
|
77
|
+
float_to_bytes,
|
78
|
+
bytes_to_float,
|
79
|
+
)
|
80
|
+
|
81
|
+
from .stats import ( # noqa
|
82
|
+
get_quantile,
|
83
|
+
|
84
|
+
Stats,
|
85
|
+
)
|
86
|
+
|
87
|
+
from .histogram import ( # noqa
|
88
|
+
SamplingHistogram,
|
89
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: omlish
|
3
|
-
Version: 0.0.0.
|
3
|
+
Version: 0.0.0.dev420
|
4
4
|
Summary: omlish
|
5
5
|
Author: wrmsr
|
6
6
|
License-Expression: BSD-3-Clause
|
@@ -132,7 +132,7 @@ dependencies of any kind**.
|
|
132
132
|
of the presence or absence of an object, as in [many](https://en.cppreference.com/w/cpp/utility/optional)
|
133
133
|
[other](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)
|
134
134
|
[languages](https://doc.rust-lang.org/std/option/).
|
135
|
-
- **[
|
135
|
+
- **[maysync](https://github.com/wrmsr/omlish/blob/master/omlish/lite/maysync.py)** - A lightweight means of sharing
|
136
136
|
code between sync and async contexts, eliminating the need for maintaining sync and async versions of functions.
|
137
137
|
|
138
138
|
- **[bootstrap](https://github.com/wrmsr/omlish/blob/master/omlish/bootstrap)** - A centralized, configurable,
|