omlish 0.0.0.dev484__py3-none-any.whl → 0.0.0.dev506__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.

Potentially problematic release.


This version of omlish might be problematic. Click here for more details.

Files changed (93) hide show
  1. omlish/CODESTYLE.md +345 -0
  2. omlish/README.md +199 -0
  3. omlish/__about__.py +12 -5
  4. omlish/_check.cc +209 -0
  5. omlish/check.py +11 -0
  6. omlish/dataclasses/__init__.py +4 -0
  7. omlish/dataclasses/impl/concerns/frozen.py +4 -1
  8. omlish/dataclasses/impl/generation/plans.py +2 -17
  9. omlish/dataclasses/impl/generation/processor.py +2 -2
  10. omlish/dataclasses/impl/processing/driving.py +13 -1
  11. omlish/dataclasses/tools/replace.py +27 -0
  12. omlish/diag/_pycharm/runhack.py +1 -1
  13. omlish/dispatch/functions.py +1 -1
  14. omlish/formats/json/stream/lexing.py +13 -5
  15. omlish/formats/json/stream/parsing.py +1 -1
  16. omlish/inject/README.md +430 -0
  17. omlish/inject/__init__.py +20 -11
  18. omlish/inject/_dataclasses.py +1545 -1383
  19. omlish/inject/binder.py +7 -4
  20. omlish/inject/eagers.py +2 -4
  21. omlish/inject/elements.py +4 -0
  22. omlish/inject/helpers/late.py +76 -0
  23. omlish/inject/{managed.py → helpers/managed.py} +37 -34
  24. omlish/inject/impl/elements.py +7 -4
  25. omlish/inject/impl/injector.py +14 -26
  26. omlish/inject/impl/inspect.py +0 -8
  27. omlish/inject/impl/origins.py +1 -0
  28. omlish/inject/impl/privates.py +2 -6
  29. omlish/inject/impl/providers.py +0 -4
  30. omlish/inject/impl/scopes.py +14 -18
  31. omlish/inject/inspect.py +10 -1
  32. omlish/inject/multis.py +0 -3
  33. omlish/inject/scopes.py +7 -5
  34. omlish/io/buffers.py +35 -8
  35. omlish/lang/__init__.py +10 -0
  36. omlish/lang/classes/simple.py +2 -1
  37. omlish/lang/iterables.py +6 -0
  38. omlish/lang/objects.py +13 -0
  39. omlish/lang/outcomes.py +1 -1
  40. omlish/lang/recursion.py +1 -1
  41. omlish/lang/sequences.py +33 -0
  42. omlish/lifecycles/README.md +30 -0
  43. omlish/lifecycles/__init__.py +87 -13
  44. omlish/lifecycles/_dataclasses.py +1388 -0
  45. omlish/lifecycles/base.py +178 -64
  46. omlish/lifecycles/contextmanagers.py +113 -4
  47. omlish/lifecycles/controller.py +150 -87
  48. omlish/lifecycles/injection.py +143 -0
  49. omlish/lifecycles/listeners.py +56 -0
  50. omlish/lifecycles/managed.py +142 -0
  51. omlish/lifecycles/manager.py +218 -93
  52. omlish/lifecycles/states.py +2 -0
  53. omlish/lifecycles/transitions.py +3 -0
  54. omlish/lifecycles/unwrap.py +57 -0
  55. omlish/lite/maybes.py +7 -0
  56. omlish/lite/typing.py +33 -0
  57. omlish/logs/_amalg.py +1 -1
  58. omlish/logs/all.py +36 -11
  59. omlish/logs/asyncs.py +73 -0
  60. omlish/logs/base.py +101 -12
  61. omlish/logs/bisync.py +99 -0
  62. omlish/logs/contexts.py +4 -1
  63. omlish/logs/lists.py +125 -0
  64. omlish/logs/modules.py +19 -1
  65. omlish/logs/std/loggers.py +6 -1
  66. omlish/logs/std/noisy.py +11 -9
  67. omlish/logs/{standard.py → std/standard.py} +3 -4
  68. omlish/logs/utils.py +16 -1
  69. omlish/marshal/_dataclasses.py +813 -813
  70. omlish/reflect/__init__.py +43 -26
  71. omlish/reflect/ops.py +10 -1
  72. omlish/specs/jmespath/_dataclasses.py +597 -597
  73. omlish/specs/jsonschema/keywords/_dataclasses.py +244 -244
  74. omlish/sql/__init__.py +24 -5
  75. omlish/sql/api/dbapi.py +1 -1
  76. omlish/sql/dbapi/__init__.py +15 -0
  77. omlish/sql/{dbapi.py → dbapi/drivers.py} +2 -2
  78. omlish/sql/queries/__init__.py +3 -0
  79. omlish/testing/pytest/plugins/asyncs/plugin.py +2 -0
  80. omlish/text/docwrap/cli.py +5 -0
  81. omlish/typedvalues/_collection.cc +500 -0
  82. omlish/typedvalues/collection.py +159 -62
  83. omlish/typedvalues/generic.py +5 -4
  84. omlish/typedvalues/values.py +6 -0
  85. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/METADATA +14 -9
  86. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/RECORD +92 -77
  87. omlish/lifecycles/abstract.py +0 -86
  88. /omlish/inject/{impl → helpers}/proxy.py +0 -0
  89. /omlish/sql/{abc.py → dbapi/abc.py} +0 -0
  90. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/WHEEL +0 -0
  91. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/entry_points.txt +0 -0
  92. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/licenses/LICENSE +0 -0
  93. {omlish-0.0.0.dev484.dist-info → omlish-0.0.0.dev506.dist-info}/top_level.txt +0 -0
omlish/lang/objects.py CHANGED
@@ -2,6 +2,7 @@ import types
2
2
  import typing as ta
3
3
  import weakref
4
4
 
5
+ from ..lite.maybes import Maybe
5
6
  from .classes.abstract import is_abstract_class
6
7
 
7
8
 
@@ -24,6 +25,18 @@ def opt_repr(obj: ta.Any) -> str | None:
24
25
  return repr(obj)
25
26
 
26
27
 
28
+ def just_repr(obj: Maybe) -> str | None:
29
+ return obj.map(repr).or_none()
30
+
31
+
32
+ def opt_or_just_repr(obj: ta.Any) -> str | None:
33
+ if isinstance(obj, Maybe):
34
+ if obj.present:
35
+ return repr(obj)
36
+ return None
37
+ return opt_repr(obj)
38
+
39
+
27
40
  ##
28
41
 
29
42
 
omlish/lang/outcomes.py CHANGED
@@ -214,7 +214,7 @@ class Value(Outcome[ValueT_co], ta.Generic[ValueT_co]):
214
214
 
215
215
  @property
216
216
  def is_error(self) -> bool:
217
- return True
217
+ return False
218
218
 
219
219
  def value(self) -> ValueT_co:
220
220
  return self._value
omlish/lang/recursion.py CHANGED
@@ -65,7 +65,7 @@ def recursion_limiting_context(key: ta.Any, limit: int | None) -> ta.Iterator[in
65
65
  except KeyError:
66
66
  pd = None
67
67
  else:
68
- if not isinstance(pd, int) and pd > 0: # type: ignore[operator]
68
+ if not (isinstance(pd, int) and pd > 0):
69
69
  raise RuntimeError
70
70
 
71
71
  if pd is not None and pd >= limit:
omlish/lang/sequences.py CHANGED
@@ -8,6 +8,7 @@ TODO:
8
8
  - shorter repr if __len__ > some threshold
9
9
  - use materialize()?
10
10
  """
11
+ import operator
11
12
  import typing as ta
12
13
 
13
14
 
@@ -36,6 +37,38 @@ def iterrange(
36
37
  ##
37
38
 
38
39
 
40
+ def seqs_all(
41
+ fn: ta.Callable[[T, T], bool],
42
+ l_seq: ta.Sequence[T],
43
+ *r_seqs: ta.Sequence[T],
44
+ ) -> bool:
45
+ if not all(len(r_seq) == len(l_seq) for r_seq in r_seqs):
46
+ return False
47
+
48
+ return all(
49
+ fn(l, r)
50
+ for r_seq in r_seqs
51
+ for l, r in zip(l_seq, r_seq, strict=True)
52
+ )
53
+
54
+
55
+ def seqs_equal(
56
+ l_seq: ta.Sequence[T],
57
+ *r_seqs: ta.Sequence[T],
58
+ ) -> bool:
59
+ return seqs_all(operator.eq, l_seq, *r_seqs)
60
+
61
+
62
+ def seqs_identical(
63
+ l_seq: ta.Sequence[T],
64
+ *r_seqs: ta.Sequence[T],
65
+ ) -> bool:
66
+ return seqs_all(operator.is_, l_seq, *r_seqs)
67
+
68
+
69
+ ##
70
+
71
+
39
72
  @ta.final
40
73
  class SeqView(ta.Sequence[T]):
41
74
  def __init__(self, data: ta.Sequence[T], slice_: slice = slice(None)) -> None:
@@ -0,0 +1,30 @@
1
+ Lifecycle management, inspired by [governator](https://github.com/Netflix/governator/tree/master/governator-core/).
2
+
3
+ A central idea is to 'hide the guts' of a given class's lifecycle management from code interacting with it.
4
+
5
+ The main classes are as follows:
6
+
7
+ - Lifecycle / AsyncLifecycle - the code 'managed by' the rest of the lifecycle machinery. In general, user code will
8
+ hide its implementations of these from the code that otherwise interacts with it. Being the lowest level / unit of
9
+ management callbacks, it intentionally provides no additional machinery, existing solely as a skeleton of methods
10
+ which will be called by lifecycle internals - this is to reduce friction with more functional / less OO code. However,
11
+ it still chooses to be a class with multiple nullary methods, rather than a more functional-style single unary free
12
+ function: the operations present in each method are generally intended to have no overlap in practice, and their
13
+ explicit division is a conscious choice.
14
+
15
+ - LifecycleManaged / AsyncLifecycleManaged - a mixin which can be used to add lifecycle management behavior to a class.
16
+ This removes the need for manual subclassing of Lifecycle / AsyncLifecycle, providing private '\_lifecycle_<state>'
17
+ callback methods (with default no-op implementations) which subclasses may override.
18
+
19
+ - LifecycleListener / AsyncLifecycleListener - callback interfaces whose methods will be called when a lifecycle object
20
+ goes through a lifecycle state transition.
21
+
22
+ - LifecycleController / AsyncLifecycleController - these classes run the state machine for any single Lifecycle /
23
+ AsyncLifecycle instance. They are also responsible for maintaining a registry of lifecycle listeners and calling their
24
+ methods as necessary. Unlike user code, these classes are openly subclasses of Lifecycle / AsyncLifecycle, allowing
25
+ them to be called as application state dictates - they will internally ensure correct state transitions.
26
+
27
+ - LifecycleManager / AsyncLifecycleManager - these classes are responsible for construction and operation of (acyclic)
28
+ graphs of lifecycle objects. They will ensure that, as necessary according to registered dependencies, lifecycle
29
+ objects are started in the correct order, and that they are stopped in the correct order. This class is itself a
30
+ LifecycleManaged / AsyncLifecycleManaged. Notably, AsyncLifecycleManager can also manage sync Lifecycles.
@@ -1,43 +1,71 @@
1
- from .abstract import ( # noqa
2
- AbstractLifecycle,
1
+ from .. import dataclasses as _dc
3
2
 
4
- AbstractAsyncLifecycle,
3
+
4
+ _dc.init_package(
5
+ globals(),
6
+ codegen=True,
5
7
  )
6
8
 
9
+
10
+ ##
11
+
12
+
7
13
  from .base import ( # noqa
8
- AnyLifecycleCallback,
14
+ Lifecycle,
15
+ AsyncLifecycle,
9
16
  AnyLifecycle,
10
- AnyCallbackLifecycle,
17
+ ANY_LIFECYCLE_TYPES,
11
18
 
12
- LifecycleCallback,
13
- CallbackLifecycle,
14
- Lifecycle,
19
+ sync_to_async_lifecycle,
20
+ as_async_lifecycle,
21
+ async_to_sync_lifecycle,
22
+ as_sync_lifecycle,
15
23
 
16
- AsyncLifecycleCallback,
24
+ CallbackLifecycle,
17
25
  CallbackAsyncLifecycle,
18
- AsyncLifecycle,
19
26
  )
20
27
 
21
28
  from .contextmanagers import ( # noqa
22
29
  ContextManagerLifecycle,
30
+ AsyncContextManagerLifecycle,
31
+
23
32
  LifecycleContextManager,
33
+ AsyncLifecycleContextManager,
34
+
35
+ lifecycle_context_manage,
36
+ async_lifecycle_context_manage,
24
37
  )
25
38
 
26
39
  from .controller import ( # noqa
27
- AnyLifecycleListener,
40
+ LifecycleController,
41
+ AsyncLifecycleController,
28
42
  AnyLifecycleController,
43
+ ANY_LIFECYCLE_CONTROLLER_TYPES,
44
+ )
29
45
 
30
- LifecycleController,
46
+ from .listeners import ( # noqa
31
47
  LifecycleListener,
48
+ AsyncLifecycleListener,
49
+ AnyLifecycleListener,
50
+ ANY_LIFECYCLE_LISTENER_TYPES,
51
+ )
52
+
53
+ from .managed import ( # noqa
54
+ LifecycleManaged,
55
+ AsyncLifecycleManaged,
56
+ AnyLifecycleManaged,
57
+ ANY_LIFECYCLE_MANAGED_TYPES,
32
58
  )
33
59
 
34
60
  from .manager import ( # noqa
61
+ LifecycleManagerEntry,
35
62
  LifecycleManager,
63
+ AsyncLifecycleManager,
36
64
  )
37
65
 
38
66
  from .states import ( # noqa
39
- LifecycleState,
40
67
  LifecycleStateError,
68
+ LifecycleState,
41
69
  LifecycleStates,
42
70
  )
43
71
 
@@ -45,3 +73,49 @@ from .transitions import ( # noqa
45
73
  LifecycleTransition,
46
74
  LifecycleTransitions,
47
75
  )
76
+
77
+ from .unwrap import ( # noqa
78
+ unwrap_lifecycle,
79
+ unwrap_async_lifecycle,
80
+ unwrap_any_lifecycle,
81
+ )
82
+
83
+
84
+ ##
85
+
86
+
87
+ from .. import lang as _lang # noqa
88
+
89
+
90
+ with _lang.auto_proxy_init(globals()):
91
+ ##
92
+
93
+ from .injection import ( # noqa
94
+ bind_lifecycle_registrar,
95
+ bind_async_lifecycle_registrar,
96
+
97
+ bind_managed_lifecycle_manager,
98
+ bind_async_managed_lifecycle_manager,
99
+ )
100
+
101
+
102
+ ##
103
+
104
+
105
+ NEW = LifecycleStates.NEW
106
+
107
+ CONSTRUCTING = LifecycleStates.CONSTRUCTING
108
+ FAILED_CONSTRUCTING = LifecycleStates.FAILED_CONSTRUCTING
109
+ CONSTRUCTED = LifecycleStates.CONSTRUCTED
110
+
111
+ STARTING = LifecycleStates.STARTING
112
+ FAILED_STARTING = LifecycleStates.FAILED_STARTING
113
+ STARTED = LifecycleStates.STARTED
114
+
115
+ STOPPING = LifecycleStates.STOPPING
116
+ FAILED_STOPPING = LifecycleStates.FAILED_STOPPING
117
+ STOPPED = LifecycleStates.STOPPED
118
+
119
+ DESTROYING = LifecycleStates.DESTROYING
120
+ FAILED_DESTROYING = LifecycleStates.FAILED_DESTROYING
121
+ DESTROYED = LifecycleStates.DESTROYED