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.
@@ -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 Lifecycle
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 LifecycleListener(ta.Generic[LifecycleT]):
20
- def on_starting(self, obj: LifecycleT) -> None:
21
- pass
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: LifecycleT) -> None:
24
- pass
29
+ def on_started(self, obj: AnyLifecycleT) -> R | None:
30
+ return None
25
31
 
26
- def on_stopping(self, obj: LifecycleT) -> None:
27
- pass
32
+ def on_stopping(self, obj: AnyLifecycleT) -> R | None:
33
+ return None
28
34
 
29
- def on_stopped(self, obj: LifecycleT) -> None:
30
- pass
35
+ def on_stopped(self, obj: AnyLifecycleT) -> R | None:
36
+ return None
31
37
 
32
38
 
33
- class LifecycleController(Lifecycle, ta.Generic[LifecycleT]):
39
+ class AnyLifecycleController(AnyLifecycle[R], lang.Abstract, ta.Generic[AnyLifecycleT, R]):
34
40
  def __init__(
35
41
  self,
36
- lifecycle: LifecycleT,
37
- *,
38
- lock: lang.DefaultLockable = None,
42
+ lifecycle: AnyLifecycleT,
39
43
  ) -> None:
40
44
  super().__init__()
41
45
 
42
- self._lifecycle: LifecycleT = check.isinstance(lifecycle, Lifecycle) # type: ignore
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[LifecycleListener[LifecycleT]] = []
49
+ self._listeners: list[AnyLifecycleListener[AnyLifecycleT, R]] = []
47
50
 
48
51
  defs.repr('lifecycle', 'state')
49
52
 
50
53
  @property
51
- def lifecycle(self) -> LifecycleT:
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: LifecycleListener[LifecycleT]) -> 'LifecycleController':
59
- self._listeners.append(check.isinstance(listener, LifecycleListener))
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[[LifecycleListener[LifecycleT]], ta.Callable[[LifecycleT], None]] | None = None, # noqa
67
- post_listener_fn: ta.Callable[[LifecycleListener[LifecycleT]], ta.Callable[[LifecycleT], None]] | None = None, # noqa
68
- ) -> None:
69
- with self._lock():
70
- if pre_listener_fn is not None:
71
- for listener in self._listeners:
72
- pre_listener_fn(listener)(self._lifecycle)
73
- check.state(self._state in transition.old)
74
- self._state = transition.new_intermediate
75
- try:
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
- from .callers import ( # noqa
2
- LoggingCaller,
3
- )
1
+ # rufF: noqa: I001
2
+ from .. import lang as _lang
4
3
 
5
- from .color import ( # noqa
6
- ColorLogFormatter,
7
- )
8
4
 
9
- from .filters import ( # noqa
10
- TidLogFilter,
11
- )
5
+ with _lang.auto_proxy_init(globals()):
6
+ ##
12
7
 
13
- from .handlers import ( # noqa
14
- ListHandler,
15
- )
8
+ from .callers import ( # noqa
9
+ LoggingCaller,
10
+ )
16
11
 
17
- from .json import ( # noqa
18
- JsonLogFormatter,
19
- )
12
+ from .color import ( # noqa
13
+ ColorLogFormatter,
14
+ )
20
15
 
21
- from .noisy import ( # noqa
22
- silence_noisy_loggers,
23
- )
16
+ from .filters import ( # noqa
17
+ TidLogFilter,
18
+ )
24
19
 
25
- from .protocol import ( # noqa
26
- LogLevel,
20
+ from .handlers import ( # noqa
21
+ ListHandler,
22
+ )
27
23
 
28
- Logging,
29
- NopLogging,
30
- AbstractLogging,
31
- StdlibLogging,
32
- )
24
+ from .json import ( # noqa
25
+ JsonLogFormatter,
26
+ )
33
27
 
34
- from .proxy import ( # noqa
35
- ProxyLogFilterer,
36
- ProxyLogHandler,
37
- )
28
+ from .noisy import ( # noqa
29
+ silence_noisy_loggers,
30
+ )
38
31
 
39
- from .standard import ( # noqa
40
- STANDARD_LOG_FORMAT_PARTS,
41
- StandardLogFormatter,
32
+ from .protocol import ( # noqa
33
+ LogLevel,
42
34
 
43
- StandardConfiguredLogHandler,
35
+ Logging,
36
+ NopLogging,
37
+ AbstractLogging,
38
+ StdlibLogging,
39
+ )
44
40
 
45
- configure_standard_logging,
46
- )
41
+ from .proxy import ( # noqa
42
+ ProxyLogFilterer,
43
+ ProxyLogHandler,
44
+ )
47
45
 
48
- from .utils import ( # noqa
49
- error_logging,
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 .bits import ( # noqa
2
- get_bit,
3
- get_bits,
4
- set_bit,
5
- set_bits,
6
- )
7
-
8
- from .c import ( # noqa
9
- cdiv,
10
- cmod,
11
- )
12
-
13
- from .fixed import ( # noqa
14
- CheckedFixedWidthIntError,
15
- OverflowFixedWidthIntError,
16
- UnderflowFixedWidthIntError,
17
-
18
- FixedWidthInt,
19
-
20
- SignedInt,
21
- UnsignedInt,
22
-
23
- CheckedInt,
24
- ClampedInt,
25
-
26
- AnyInt8,
27
- AnyInt16,
28
- AnyInt32,
29
- AnyInt64,
30
- AnyInt128,
31
-
32
- CheckedInt8,
33
- CheckedInt16,
34
- CheckedInt32,
35
- CheckedInt64,
36
- CheckedInt128,
37
-
38
- CheckedUint8,
39
- CheckedUint16,
40
- CheckedUint32,
41
- CheckedUint64,
42
- CheckedUint128,
43
-
44
- ClampedInt8,
45
- ClampedInt16,
46
- ClampedInt32,
47
- ClampedInt64,
48
- ClampedInt128,
49
-
50
- ClampedUint8,
51
- ClampedUint16,
52
- ClampedUint32,
53
- ClampedUint64,
54
- ClampedUint128,
55
-
56
- WrappedInt8,
57
- WrappedInt16,
58
- WrappedInt32,
59
- WrappedInt64,
60
- WrappedInt128,
61
-
62
- WrappedUint8,
63
- WrappedUint16,
64
- WrappedUint32,
65
- WrappedUint64,
66
- WrappedUint128,
67
- )
68
-
69
- from .floats import ( # noqa
70
- isclose,
71
- float_to_bytes,
72
- bytes_to_float,
73
- )
74
-
75
- from .stats import ( # noqa
76
- get_quantile,
77
-
78
- Stats,
79
- )
80
-
81
- from .histogram import ( # noqa
82
- SamplingHistogram,
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
+ )
@@ -4,7 +4,7 @@ import abc
4
4
  import sys
5
5
  import typing as ta
6
6
 
7
- from ..lite.maysyncs import make_maysync
7
+ from ..lite.maysync import make_maysync
8
8
  from .asyncs import AbstractAsyncSubprocesses
9
9
  from .run import SubprocessRun
10
10
  from .run import SubprocessRunOutput
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omlish
3
- Version: 0.0.0.dev418
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
- - **[maysyncs](https://github.com/wrmsr/omlish/blob/master/omlish/lite/maysyncs.py)** - A lightweight means of sharing
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,