omlish 0.0.0.dev432__py3-none-any.whl → 0.0.0.dev434__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.
Files changed (46) hide show
  1. omlish/__about__.py +3 -3
  2. omlish/asyncs/all.py +0 -13
  3. omlish/inject/__init__.py +152 -126
  4. omlish/inject/binder.py +7 -4
  5. omlish/inject/impl/elements.py +6 -8
  6. omlish/inject/impl/injector.py +58 -32
  7. omlish/inject/impl/inspect.py +1 -0
  8. omlish/inject/impl/maysync.py +44 -0
  9. omlish/inject/impl/multis.py +5 -5
  10. omlish/inject/impl/privates.py +8 -8
  11. omlish/inject/impl/providers.py +24 -31
  12. omlish/inject/impl/providers2.py +43 -0
  13. omlish/inject/impl/scopes.py +19 -25
  14. omlish/inject/impl/sync.py +42 -0
  15. omlish/inject/injector.py +9 -11
  16. omlish/inject/inspect.py +1 -3
  17. omlish/inject/listeners.py +4 -4
  18. omlish/inject/managed.py +52 -20
  19. omlish/inject/maysync.py +27 -0
  20. omlish/inject/providers.py +6 -0
  21. omlish/inject/scopes.py +38 -10
  22. omlish/inject/sync.py +46 -0
  23. omlish/lang/__init__.py +23 -6
  24. omlish/lang/asyncs.py +18 -0
  25. omlish/lang/contextmanagers.py +23 -0
  26. omlish/lang/imports/capture.py +491 -0
  27. omlish/lang/imports/lazy.py +0 -25
  28. omlish/lang/imports/proxy.py +62 -0
  29. omlish/lang/imports/proxyinit.py +28 -518
  30. omlish/lang/resources.py +1 -1
  31. omlish/lite/asyncs.py +21 -0
  32. omlish/lite/maysync.py +21 -0
  33. omlish/logs/contexts.py +4 -3
  34. omlish/logs/std/records.py +29 -19
  35. omlish/logs/typed/bindings.py +84 -37
  36. omlish/logs/typed/types.py +16 -1
  37. omlish/marshal/__init__.py +1 -1
  38. omlish/typedvalues/__init__.py +1 -1
  39. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/METADATA +3 -6
  40. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/RECORD +44 -39
  41. omlish/asyncs/bridge.py +0 -359
  42. omlish/asyncs/utils.py +0 -18
  43. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/WHEEL +0 -0
  44. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/entry_points.txt +0 -0
  45. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/licenses/LICENSE +0 -0
  46. {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/top_level.txt +0 -0
omlish/inject/scopes.py CHANGED
@@ -7,16 +7,17 @@ from .. import dataclasses as dc
7
7
  from .. import lang
8
8
  from .bindings import Binding
9
9
  from .elements import Element
10
+ from .injector import AsyncInjector
10
11
  from .keys import Key
11
12
  from .keys import as_key
12
13
  from .providers import Provider
13
14
  from .types import Scope
14
15
 
15
16
 
16
- if ta.TYPE_CHECKING:
17
- from . import injector as injector_
18
- else:
19
- injector_ = lang.proxy_import('.injector', __package__)
17
+ with lang.auto_proxy_import(globals()):
18
+ from . import injector as _injector
19
+ from . import maysync as _maysync
20
+ from . import sync as _sync
20
21
 
21
22
 
22
23
  ##
@@ -65,7 +66,7 @@ class SeededScope(Scope, lang.Final):
65
66
 
66
67
  class Manager(lang.Abstract):
67
68
  @abc.abstractmethod
68
- def __call__(self, seeds: ta.Mapping[Key, ta.Any]) -> ta.ContextManager[None]:
69
+ def __call__(self, seeds: ta.Mapping[Key, ta.Any]) -> ta.AsyncContextManager[None]:
69
70
  raise NotImplementedError
70
71
 
71
72
 
@@ -81,11 +82,38 @@ def bind_scope_seed(k: ta.Any, ss: SeededScope) -> Element:
81
82
  return Binding(k, ScopeSeededProvider(ss, k))
82
83
 
83
84
 
84
- @contextlib.contextmanager
85
- def enter_seeded_scope(
86
- i: injector_.Injector,
85
+ ##
86
+
87
+
88
+ @contextlib.asynccontextmanager
89
+ async def async_enter_seeded_scope(
90
+ i: '_injector.AsyncInjector',
87
91
  ss: SeededScope,
88
92
  keys: ta.Mapping[Key, ta.Any],
89
- ) -> ta.Generator[None]:
90
- with i.provide(Key(SeededScope.Manager, tag=ss))(keys):
93
+ ) -> ta.AsyncGenerator[None]:
94
+ async with (await i.provide(Key(SeededScope.Manager, tag=ss)))(keys):
91
95
  yield
96
+
97
+
98
+ def enter_seeded_scope(
99
+ i: '_sync.Injector',
100
+ ss: SeededScope,
101
+ keys: ta.Mapping[Key, ta.Any],
102
+ ) -> ta.ContextManager[None]:
103
+ return lang.run_maysync_context_manager(async_enter_seeded_scope(
104
+ i[AsyncInjector],
105
+ ss,
106
+ keys,
107
+ ))
108
+
109
+
110
+ def maysync_enter_seeded_scope(
111
+ i: '_maysync.MaysyncInjector',
112
+ ss: SeededScope,
113
+ keys: ta.Mapping[Key, ta.Any],
114
+ ) -> ta.ContextManager[None]:
115
+ return lang.sync_async_context_manager(async_enter_seeded_scope(
116
+ i[AsyncInjector],
117
+ ss,
118
+ keys,
119
+ ))
omlish/inject/sync.py ADDED
@@ -0,0 +1,46 @@
1
+ import abc
2
+ import typing as ta
3
+
4
+ from .. import lang
5
+ from .elements import Elemental
6
+ from .elements import as_elements
7
+ from .inspect import KwargsTarget
8
+ from .keys import Key
9
+
10
+
11
+ with lang.auto_proxy_import(globals()):
12
+ from .impl import sync as _sync
13
+
14
+
15
+ T = ta.TypeVar('T')
16
+
17
+
18
+ ##
19
+
20
+
21
+ class Injector(lang.Abstract):
22
+ @abc.abstractmethod
23
+ def try_provide(self, key: ta.Any) -> lang.Maybe[ta.Any]:
24
+ raise NotImplementedError
25
+
26
+ @abc.abstractmethod
27
+ def provide(self, key: ta.Any) -> ta.Any:
28
+ raise NotImplementedError
29
+
30
+ @abc.abstractmethod
31
+ def provide_kwargs(self, kt: KwargsTarget) -> ta.Mapping[str, ta.Any]:
32
+ raise NotImplementedError
33
+
34
+ @abc.abstractmethod
35
+ def inject(self, obj: ta.Any) -> ta.Any:
36
+ raise NotImplementedError
37
+
38
+ def __getitem__(
39
+ self,
40
+ target: Key[T] | type[T],
41
+ ) -> T:
42
+ return self.provide(target)
43
+
44
+
45
+ def create_injector(*args: Elemental) -> Injector:
46
+ return _sync.create_injector(as_elements(*args))
omlish/lang/__init__.py CHANGED
@@ -15,6 +15,9 @@ with _auto_proxy_init(
15
15
 
16
16
  sync_await,
17
17
  sync_async_list,
18
+
19
+ SyncAsyncContextManager,
20
+ sync_async_context_manager,
18
21
  )
19
22
 
20
23
  from .attrstorage import ( # noqa
@@ -184,6 +187,9 @@ with _auto_proxy_init(
184
187
  Timer,
185
188
 
186
189
  double_check_setdefault,
190
+
191
+ call_with_exit_stack,
192
+ call_with_async_exit_stack,
187
193
  )
188
194
 
189
195
  from .datetimes import ( # noqa
@@ -260,6 +266,12 @@ with _auto_proxy_init(
260
266
  nextgen,
261
267
  )
262
268
 
269
+ from .imports.capture import ( # noqa
270
+ ImportCaptureError,
271
+ ImportCaptureErrors,
272
+ ImportCapture,
273
+ )
274
+
263
275
  from .imports.conditional import ( # noqa
264
276
  register_conditional_import,
265
277
  trigger_conditional_imports,
@@ -267,15 +279,17 @@ with _auto_proxy_init(
267
279
 
268
280
  from .imports.lazy import ( # noqa
269
281
  lazy_import,
282
+ )
283
+
284
+ from .imports.proxy import ( # noqa
270
285
  proxy_import,
286
+
287
+ auto_proxy_import,
271
288
  )
272
289
 
273
290
  from .imports.proxyinit import ( # noqa
274
291
  proxy_init,
275
292
 
276
- AutoProxyInitError,
277
- AutoProxyInitErrors,
278
- AutoProxyInit,
279
293
  auto_proxy_init,
280
294
  )
281
295
 
@@ -479,9 +493,6 @@ with _auto_proxy_init(
479
493
  )
480
494
 
481
495
  from ..lite.maysync import ( # noqa
482
- mark_maysync,
483
- is_maysync,
484
-
485
496
  AnyMaysyncFn,
486
497
 
487
498
  MaywaitableAlreadyConsumedError,
@@ -496,6 +507,12 @@ with _auto_proxy_init(
496
507
  is_running_maysync,
497
508
 
498
509
  run_maysync,
510
+
511
+ RunMaysyncContextManager,
512
+ run_maysync_context_manager,
513
+
514
+ mark_maysync,
515
+ is_maysync,
499
516
  )
500
517
 
501
518
  from ..lite.objects import ( # noqa
omlish/lang/asyncs.py CHANGED
@@ -79,3 +79,21 @@ def sync_async_list(
79
79
  raise TypeError(lst)
80
80
 
81
81
  return lst
82
+
83
+
84
+ @ta.final
85
+ class SyncAsyncContextManager(ta.Generic[T]):
86
+ def __init__(self, acm: ta.AsyncContextManager[T]) -> None:
87
+ self._acm = acm
88
+
89
+ def __repr__(self) -> str:
90
+ return f'{self.__class__.__name__}({self._acm!r})'
91
+
92
+ def __enter__(self) -> T:
93
+ return sync_await(self._acm.__aenter__())
94
+
95
+ def __exit__(self, exc_type, exc_val, exc_tb):
96
+ return sync_await(self._acm.__aexit__(exc_type, exc_val, exc_tb))
97
+
98
+
99
+ sync_async_context_manager = SyncAsyncContextManager
@@ -20,6 +20,8 @@ T = ta.TypeVar('T')
20
20
  K = ta.TypeVar('K')
21
21
  V = ta.TypeVar('V')
22
22
 
23
+ P = ta.ParamSpec('P')
24
+
23
25
 
24
26
  ##
25
27
 
@@ -382,3 +384,24 @@ def double_check_setdefault(
382
384
  v = fn()
383
385
  dct[k] = v
384
386
  return v
387
+
388
+
389
+ ##
390
+
391
+
392
+ def call_with_exit_stack(
393
+ fn: ta.Callable[ta.Concatenate[contextlib.ExitStack, P], T],
394
+ *args: ta.Any,
395
+ **kwargs: ta.Any,
396
+ ) -> T:
397
+ with contextlib.ExitStack() as es:
398
+ return fn(es, *args, **kwargs)
399
+
400
+
401
+ async def call_with_async_exit_stack(
402
+ fn: ta.Callable[ta.Concatenate[contextlib.AsyncExitStack, P], ta.Awaitable[T]],
403
+ *args: ta.Any,
404
+ **kwargs: ta.Any,
405
+ ) -> T:
406
+ async with contextlib.AsyncExitStack() as aes:
407
+ return await fn(aes, *args, **kwargs)