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.
- omlish/__about__.py +3 -3
- omlish/asyncs/all.py +0 -13
- omlish/inject/__init__.py +152 -126
- omlish/inject/binder.py +7 -4
- omlish/inject/impl/elements.py +6 -8
- omlish/inject/impl/injector.py +58 -32
- omlish/inject/impl/inspect.py +1 -0
- omlish/inject/impl/maysync.py +44 -0
- omlish/inject/impl/multis.py +5 -5
- omlish/inject/impl/privates.py +8 -8
- omlish/inject/impl/providers.py +24 -31
- omlish/inject/impl/providers2.py +43 -0
- omlish/inject/impl/scopes.py +19 -25
- omlish/inject/impl/sync.py +42 -0
- omlish/inject/injector.py +9 -11
- omlish/inject/inspect.py +1 -3
- omlish/inject/listeners.py +4 -4
- omlish/inject/managed.py +52 -20
- omlish/inject/maysync.py +27 -0
- omlish/inject/providers.py +6 -0
- omlish/inject/scopes.py +38 -10
- omlish/inject/sync.py +46 -0
- omlish/lang/__init__.py +23 -6
- omlish/lang/asyncs.py +18 -0
- omlish/lang/contextmanagers.py +23 -0
- omlish/lang/imports/capture.py +491 -0
- omlish/lang/imports/lazy.py +0 -25
- omlish/lang/imports/proxy.py +62 -0
- omlish/lang/imports/proxyinit.py +28 -518
- omlish/lang/resources.py +1 -1
- omlish/lite/asyncs.py +21 -0
- omlish/lite/maysync.py +21 -0
- omlish/logs/contexts.py +4 -3
- omlish/logs/std/records.py +29 -19
- omlish/logs/typed/bindings.py +84 -37
- omlish/logs/typed/types.py +16 -1
- omlish/marshal/__init__.py +1 -1
- omlish/typedvalues/__init__.py +1 -1
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/METADATA +3 -6
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/RECORD +44 -39
- omlish/asyncs/bridge.py +0 -359
- omlish/asyncs/utils.py +0 -18
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/WHEEL +0 -0
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/entry_points.txt +0 -0
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/licenses/LICENSE +0 -0
- {omlish-0.0.0.dev432.dist-info → omlish-0.0.0.dev434.dist-info}/top_level.txt +0 -0
omlish/__about__.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
__version__ = '0.0.0.
|
2
|
-
__revision__ = '
|
1
|
+
__version__ = '0.0.0.dev434'
|
2
|
+
__revision__ = '17585e1a0390e30925b0e2c5e65944f8f99a9dc3'
|
3
3
|
|
4
4
|
|
5
5
|
#
|
@@ -41,7 +41,7 @@ class Project(ProjectBase):
|
|
41
41
|
|
42
42
|
'greenlet ~= 3.2',
|
43
43
|
|
44
|
-
'trio ~= 0.
|
44
|
+
'trio ~= 0.31',
|
45
45
|
'trio-asyncio ~= 0.15',
|
46
46
|
],
|
47
47
|
|
omlish/asyncs/all.py
CHANGED
@@ -1,12 +1,3 @@
|
|
1
|
-
from .bridge import ( # noqa
|
2
|
-
a_to_s,
|
3
|
-
is_in_bridge,
|
4
|
-
s_to_a,
|
5
|
-
s_to_a_await,
|
6
|
-
trivial_a_to_s,
|
7
|
-
trivial_s_to_a,
|
8
|
-
)
|
9
|
-
|
10
1
|
from .flavors import ( # noqa
|
11
2
|
ContextManagerAdapter,
|
12
3
|
Flavor,
|
@@ -25,7 +16,3 @@ from .flavors import ( # noqa
|
|
25
16
|
mark_trio,
|
26
17
|
with_adapter_loop,
|
27
18
|
)
|
28
|
-
|
29
|
-
from .utils import ( # noqa
|
30
|
-
call_with_async_exit_stack,
|
31
|
-
)
|
omlish/inject/__init__.py
CHANGED
@@ -13,129 +13,155 @@ _dc.init_package(
|
|
13
13
|
##
|
14
14
|
|
15
15
|
|
16
|
-
from
|
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
|
-
from .
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
)
|
132
|
-
|
133
|
-
from .
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
16
|
+
from .. import lang as _lang # noqa
|
17
|
+
|
18
|
+
|
19
|
+
with _lang.auto_proxy_init(globals()):
|
20
|
+
##
|
21
|
+
|
22
|
+
from .binder import ( # noqa
|
23
|
+
bind,
|
24
|
+
bind_as_fn,
|
25
|
+
bind_map_entry_const,
|
26
|
+
bind_set_entry_const,
|
27
|
+
)
|
28
|
+
|
29
|
+
from .bindings import ( # noqa
|
30
|
+
Binding,
|
31
|
+
)
|
32
|
+
|
33
|
+
from .eagers import ( # noqa
|
34
|
+
Eager,
|
35
|
+
)
|
36
|
+
|
37
|
+
from .elements import ( # noqa
|
38
|
+
Element,
|
39
|
+
Elemental,
|
40
|
+
Elements,
|
41
|
+
as_elements,
|
42
|
+
)
|
43
|
+
|
44
|
+
from .errors import ( # noqa
|
45
|
+
BaseKeyError,
|
46
|
+
ConflictingKeyError,
|
47
|
+
CyclicDependencyError,
|
48
|
+
ScopeAlreadyOpenError,
|
49
|
+
ScopeError,
|
50
|
+
ScopeNotOpenError,
|
51
|
+
UnboundKeyError,
|
52
|
+
)
|
53
|
+
|
54
|
+
from .injector import ( # noqa
|
55
|
+
AsyncInjector,
|
56
|
+
create_async_injector,
|
57
|
+
)
|
58
|
+
|
59
|
+
from .inspect import ( # noqa
|
60
|
+
Kwarg,
|
61
|
+
KwargsTarget,
|
62
|
+
build_kwargs_target,
|
63
|
+
tag,
|
64
|
+
)
|
65
|
+
|
66
|
+
from .keys import ( # noqa
|
67
|
+
Key,
|
68
|
+
as_key,
|
69
|
+
)
|
70
|
+
|
71
|
+
from .listeners import ( # noqa
|
72
|
+
ProvisionListener,
|
73
|
+
ProvisionListenerBinding,
|
74
|
+
bind_provision_listener,
|
75
|
+
)
|
76
|
+
|
77
|
+
from .managed import ( # noqa
|
78
|
+
create_async_managed_injector,
|
79
|
+
make_async_managed_provider,
|
80
|
+
|
81
|
+
create_managed_injector,
|
82
|
+
make_managed_provider,
|
83
|
+
|
84
|
+
create_maysync_managed_injector,
|
85
|
+
make_maysync_managed_provider,
|
86
|
+
)
|
87
|
+
|
88
|
+
from .maysync import ( # noqa
|
89
|
+
MaysyncInjector,
|
90
|
+
create_maysync_injector,
|
91
|
+
)
|
92
|
+
|
93
|
+
from .multis import ( # noqa
|
94
|
+
MapBinding,
|
95
|
+
MapProvider,
|
96
|
+
SetBinding,
|
97
|
+
SetProvider,
|
98
|
+
MapBinder,
|
99
|
+
SetBinder,
|
100
|
+
|
101
|
+
MapBinder as map_binder, # noqa
|
102
|
+
SetBinder as set_binder, # noqa
|
103
|
+
)
|
104
|
+
|
105
|
+
|
106
|
+
from .overrides import ( # noqa
|
107
|
+
Overrides,
|
108
|
+
override,
|
109
|
+
)
|
110
|
+
|
111
|
+
from .origins import ( # noqa
|
112
|
+
HasOrigins,
|
113
|
+
Origin,
|
114
|
+
Origins,
|
115
|
+
)
|
116
|
+
|
117
|
+
from .privates import ( # noqa
|
118
|
+
Expose,
|
119
|
+
Private,
|
120
|
+
private,
|
121
|
+
|
122
|
+
Expose as expose, # noqa
|
123
|
+
)
|
124
|
+
|
125
|
+
from .providers import ( # noqa
|
126
|
+
ConstProvider,
|
127
|
+
CtorProvider,
|
128
|
+
FnProvider,
|
129
|
+
LinkProvider,
|
130
|
+
Provider,
|
131
|
+
)
|
132
|
+
|
133
|
+
from .scopes import ( # noqa
|
134
|
+
ScopeBinding,
|
135
|
+
bind_scope,
|
136
|
+
|
137
|
+
Singleton,
|
138
|
+
|
139
|
+
ThreadScope,
|
140
|
+
|
141
|
+
SeededScope,
|
142
|
+
ScopeSeededProvider,
|
143
|
+
bind_scope_seed,
|
144
|
+
|
145
|
+
async_enter_seeded_scope,
|
146
|
+
enter_seeded_scope,
|
147
|
+
maysync_enter_seeded_scope,
|
148
|
+
)
|
149
|
+
|
150
|
+
from .sync import ( # noqa
|
151
|
+
Injector,
|
152
|
+
create_injector,
|
153
|
+
)
|
154
|
+
|
155
|
+
from .tags import ( # noqa
|
156
|
+
Id,
|
157
|
+
)
|
158
|
+
|
159
|
+
from .types import ( # noqa
|
160
|
+
Scope,
|
161
|
+
Tag,
|
162
|
+
Unscoped,
|
163
|
+
)
|
164
|
+
|
165
|
+
from .utils import ( # noqa
|
166
|
+
ConstFn,
|
167
|
+
)
|
omlish/inject/binder.py
CHANGED
@@ -19,6 +19,7 @@ from .multis import SetBinding
|
|
19
19
|
from .multis import is_map_multi_key
|
20
20
|
from .multis import is_set_multi_key
|
21
21
|
from .privates import Expose
|
22
|
+
from .providers import AsyncFnProvider
|
22
23
|
from .providers import ConstProvider
|
23
24
|
from .providers import CtorProvider
|
24
25
|
from .providers import FnProvider
|
@@ -31,10 +32,8 @@ from .types import Scope
|
|
31
32
|
from .types import Unscoped
|
32
33
|
|
33
34
|
|
34
|
-
|
35
|
-
from .impl
|
36
|
-
else:
|
37
|
-
_inspect = lang.proxy_import('.impl.inspect', __package__)
|
35
|
+
with lang.auto_proxy_import(globals()):
|
36
|
+
from .impl import inspect as _inspect
|
38
37
|
|
39
38
|
|
40
39
|
T = ta.TypeVar('T')
|
@@ -83,6 +82,7 @@ def bind(
|
|
83
82
|
*,
|
84
83
|
tag: ta.Any = None,
|
85
84
|
|
85
|
+
to_async_fn: ta.Any = None,
|
86
86
|
to_fn: ta.Any = None,
|
87
87
|
to_ctor: ta.Any = None,
|
88
88
|
to_const: ta.Any = None,
|
@@ -102,6 +102,7 @@ def bind(
|
|
102
102
|
##
|
103
103
|
|
104
104
|
has_to = (
|
105
|
+
to_async_fn is not None or
|
105
106
|
to_fn is not None or
|
106
107
|
to_ctor is not None or
|
107
108
|
to_const is not None or
|
@@ -137,6 +138,8 @@ def bind(
|
|
137
138
|
##
|
138
139
|
|
139
140
|
providers: list[Provider] = []
|
141
|
+
if to_async_fn is not None:
|
142
|
+
providers.append(AsyncFnProvider(to_async_fn))
|
140
143
|
if to_fn is not None:
|
141
144
|
providers.append(FnProvider(to_fn))
|
142
145
|
if to_ctor is not None:
|
omlish/inject/impl/elements.py
CHANGED
@@ -47,14 +47,12 @@ from .multis import make_multi_provider_impl
|
|
47
47
|
from .origins import Origins
|
48
48
|
from .origins import set_origins
|
49
49
|
from .providers import ProviderImpl
|
50
|
-
from .
|
50
|
+
from .providers2 import make_provider_impl
|
51
51
|
from .scopes import make_scope_impl
|
52
52
|
|
53
53
|
|
54
|
-
|
55
|
-
from . import privates as
|
56
|
-
else:
|
57
|
-
privates_ = lang.proxy_import('.privates', __package__)
|
54
|
+
with lang.auto_proxy_import(globals()):
|
55
|
+
from . import privates as _privates
|
58
56
|
|
59
57
|
|
60
58
|
ElementT = ta.TypeVar('ElementT', bound=Element)
|
@@ -69,17 +67,17 @@ class ElementCollection(lang.Final):
|
|
69
67
|
|
70
68
|
self._es = check.isinstance(es, Elements)
|
71
69
|
|
72
|
-
self._private_infos: ta.MutableMapping[Private,
|
70
|
+
self._private_infos: ta.MutableMapping[Private, _privates.PrivateInfo] | None = None
|
73
71
|
|
74
72
|
##
|
75
73
|
|
76
|
-
def _get_private_info(self, p: Private) -> '
|
74
|
+
def _get_private_info(self, p: Private) -> '_privates.PrivateInfo':
|
77
75
|
if (pis := self._private_infos) is None:
|
78
76
|
self._private_infos = pis = col.IdentityKeyDict()
|
79
77
|
try:
|
80
78
|
return pis[p]
|
81
79
|
except KeyError:
|
82
|
-
pis[p] = ec =
|
80
|
+
pis[p] = ec = _privates.PrivateInfo(self, p)
|
83
81
|
return ec
|
84
82
|
|
85
83
|
##
|
omlish/inject/impl/injector.py
CHANGED
@@ -25,7 +25,7 @@ from ...logs import all as logs
|
|
25
25
|
from ..elements import Elements
|
26
26
|
from ..errors import CyclicDependencyError
|
27
27
|
from ..errors import UnboundKeyError
|
28
|
-
from ..injector import
|
28
|
+
from ..injector import AsyncInjector
|
29
29
|
from ..inspect import KwargsTarget
|
30
30
|
from ..keys import Key
|
31
31
|
from ..keys import as_key
|
@@ -55,15 +55,22 @@ DEFAULT_SCOPES: list[Scope] = [
|
|
55
55
|
]
|
56
56
|
|
57
57
|
|
58
|
-
class
|
59
|
-
def __init__(
|
58
|
+
class AsyncInjectorImpl(AsyncInjector, lang.Final):
|
59
|
+
def __init__(
|
60
|
+
self,
|
61
|
+
ec: ElementCollection,
|
62
|
+
p: ta.Optional['AsyncInjectorImpl'] = None,
|
63
|
+
*,
|
64
|
+
internal_consts: dict[Key, ta.Any] | None = None,
|
65
|
+
) -> None:
|
60
66
|
super().__init__()
|
61
67
|
|
62
68
|
self._ec = check.isinstance(ec, ElementCollection)
|
63
|
-
self._p:
|
69
|
+
self._p: AsyncInjectorImpl | None = check.isinstance(p, (AsyncInjectorImpl, None))
|
64
70
|
|
65
71
|
self._internal_consts: dict[Key, ta.Any] = {
|
66
|
-
Key(
|
72
|
+
Key(AsyncInjector): self,
|
73
|
+
**(internal_consts or {}),
|
67
74
|
}
|
68
75
|
|
69
76
|
self._bim = ec.binding_impl_map()
|
@@ -76,10 +83,10 @@ class InjectorImpl(Injector, lang.Final):
|
|
76
83
|
)
|
77
84
|
)
|
78
85
|
|
79
|
-
self._cs: weakref.WeakSet[
|
80
|
-
self._root:
|
86
|
+
self._cs: weakref.WeakSet[AsyncInjectorImpl] | None = None
|
87
|
+
self._root: AsyncInjectorImpl = p._root if p is not None else self # noqa
|
81
88
|
|
82
|
-
self.__cur_req:
|
89
|
+
self.__cur_req: AsyncInjectorImpl._Request | None = None
|
83
90
|
|
84
91
|
ss = [
|
85
92
|
*DEFAULT_SCOPES,
|
@@ -89,27 +96,41 @@ class InjectorImpl(Injector, lang.Final):
|
|
89
96
|
s: make_scope_impl(s) for s in ss
|
90
97
|
}
|
91
98
|
|
92
|
-
|
93
|
-
|
99
|
+
#
|
100
|
+
|
101
|
+
_has_run_init: bool = False
|
102
|
+
|
103
|
+
async def _init(self) -> bool:
|
104
|
+
if self._has_run_init:
|
105
|
+
return False
|
106
|
+
|
107
|
+
self._has_run_init = True
|
108
|
+
|
109
|
+
await self._instantiate_eagers(Unscoped())
|
110
|
+
await self._instantiate_eagers(Singleton())
|
94
111
|
|
95
|
-
|
112
|
+
return True
|
96
113
|
|
97
|
-
|
114
|
+
#
|
115
|
+
|
116
|
+
_root: 'AsyncInjectorImpl'
|
117
|
+
|
118
|
+
async def _instantiate_eagers(self, sc: Scope) -> None:
|
98
119
|
for k in self._ekbs.get(sc, ()):
|
99
|
-
self.provide(k)
|
120
|
+
await self.provide(k)
|
100
121
|
|
101
122
|
def get_scope_impl(self, sc: Scope) -> ScopeImpl:
|
102
123
|
return self._scopes[sc]
|
103
124
|
|
104
|
-
def create_child(self, ec: ElementCollection) ->
|
105
|
-
c =
|
125
|
+
def create_child(self, ec: ElementCollection) -> AsyncInjector:
|
126
|
+
c = AsyncInjectorImpl(ec, self)
|
106
127
|
if self._cs is None:
|
107
128
|
self._cs = weakref.WeakSet()
|
108
129
|
self._cs.add(c)
|
109
130
|
return c
|
110
131
|
|
111
132
|
class _Request:
|
112
|
-
def __init__(self, injector: '
|
133
|
+
def __init__(self, injector: 'AsyncInjectorImpl') -> None:
|
113
134
|
super().__init__()
|
114
135
|
|
115
136
|
self._injector = injector
|
@@ -162,10 +183,13 @@ class InjectorImpl(Injector, lang.Final):
|
|
162
183
|
finally:
|
163
184
|
self.__cur_req = None
|
164
185
|
|
165
|
-
def _try_provide(self, key: ta.Any, *, source: ta.Any = None) -> lang.Maybe[ta.Any]:
|
186
|
+
async def _try_provide(self, key: ta.Any, *, source: ta.Any = None) -> lang.Maybe[ta.Any]:
|
187
|
+
if not self._has_run_init:
|
188
|
+
await self._init()
|
189
|
+
|
166
190
|
key = as_key(key)
|
167
191
|
|
168
|
-
cr:
|
192
|
+
cr: AsyncInjectorImpl._Request
|
169
193
|
with self._current_request() as cr:
|
170
194
|
with cr.push_source(source):
|
171
195
|
if (rv := cr.handle_key(key)).present:
|
@@ -182,55 +206,57 @@ class InjectorImpl(Injector, lang.Final):
|
|
182
206
|
fn = lambda: sc.provide(bi, self) # noqa
|
183
207
|
for pl in self._pls:
|
184
208
|
fn = functools.partial(pl, self, key, bi.binding, fn)
|
185
|
-
v = fn()
|
209
|
+
v = await fn()
|
186
210
|
|
187
211
|
return cr.handle_provision(key, lang.just(v))
|
188
212
|
|
189
213
|
if self._p is not None:
|
190
|
-
pv = self._p._try_provide(key, source=source) # noqa
|
214
|
+
pv = await self._p._try_provide(key, source=source) # noqa
|
191
215
|
if pv.present:
|
192
216
|
return cr.handle_provision(key, pv)
|
193
217
|
|
194
218
|
return cr.handle_provision(key, lang.empty())
|
195
219
|
|
196
|
-
def _provide(self, key: ta.Any, *, source: ta.Any = None) -> ta.Any:
|
197
|
-
v = self._try_provide(key, source=source)
|
220
|
+
async def _provide(self, key: ta.Any, *, source: ta.Any = None) -> ta.Any:
|
221
|
+
v = await self._try_provide(key, source=source)
|
198
222
|
if v.present:
|
199
223
|
return v.must()
|
200
224
|
raise UnboundKeyError(key)
|
201
225
|
|
202
226
|
#
|
203
227
|
|
204
|
-
def try_provide(self, key: ta.Any) -> lang.Maybe[ta.Any]:
|
228
|
+
def try_provide(self, key: ta.Any) -> ta.Awaitable[lang.Maybe[ta.Any]]:
|
205
229
|
return self._try_provide(key)
|
206
230
|
|
207
|
-
def provide(self, key: ta.Any) -> ta.Any:
|
208
|
-
v = self._try_provide(key)
|
231
|
+
async def provide(self, key: ta.Any) -> ta.Any:
|
232
|
+
v = await self._try_provide(key)
|
209
233
|
if v.present:
|
210
234
|
return v.must()
|
211
235
|
raise UnboundKeyError(key)
|
212
236
|
|
213
|
-
def provide_kwargs(self, kt: KwargsTarget) -> ta.Mapping[str, ta.Any]:
|
237
|
+
async def provide_kwargs(self, kt: KwargsTarget) -> ta.Mapping[str, ta.Any]:
|
214
238
|
ret: dict[str, ta.Any] = {}
|
215
239
|
for kw in kt.kwargs:
|
216
240
|
if kw.has_default:
|
217
|
-
if not (mv := self._try_provide(kw.key, source=kt)).present:
|
241
|
+
if not (mv := await self._try_provide(kw.key, source=kt)).present:
|
218
242
|
continue
|
219
243
|
v = mv.must()
|
220
244
|
else:
|
221
|
-
v = self._provide(kw.key, source=kt)
|
245
|
+
v = await self._provide(kw.key, source=kt)
|
222
246
|
ret[kw.name] = v
|
223
247
|
return ret
|
224
248
|
|
225
|
-
def inject(self, obj: ta.Any) -> ta.Any:
|
249
|
+
async def inject(self, obj: ta.Any) -> ta.Any:
|
226
250
|
if isinstance(obj, KwargsTarget):
|
227
251
|
obj, kt = obj.obj, obj
|
228
252
|
else:
|
229
253
|
kt = build_kwargs_target(obj)
|
230
|
-
kws = self.provide_kwargs(kt)
|
254
|
+
kws = await self.provide_kwargs(kt)
|
231
255
|
# FIXME: still 'injecting' (as in has a req) if ctor needs and uses Injector
|
232
256
|
return obj(**kws)
|
233
257
|
|
234
258
|
|
235
|
-
def
|
236
|
-
|
259
|
+
async def create_async_injector(es: Elements) -> AsyncInjector:
|
260
|
+
i = AsyncInjectorImpl(ElementCollection(es))
|
261
|
+
await i._init() # noqa
|
262
|
+
return i
|
omlish/inject/impl/inspect.py
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
import typing as ta
|
2
|
+
|
3
|
+
from ... import lang
|
4
|
+
from ..elements import Elements
|
5
|
+
from ..injector import AsyncInjector
|
6
|
+
from ..inspect import KwargsTarget
|
7
|
+
from ..keys import Key
|
8
|
+
from ..maysync import MaysyncInjector
|
9
|
+
from ..sync import Injector
|
10
|
+
from .elements import ElementCollection
|
11
|
+
from .injector import AsyncInjectorImpl
|
12
|
+
|
13
|
+
|
14
|
+
##
|
15
|
+
|
16
|
+
|
17
|
+
class MaysyncInjectorImpl(MaysyncInjector, lang.Final):
|
18
|
+
_ai: AsyncInjector
|
19
|
+
|
20
|
+
def try_provide(self, key: ta.Any) -> lang.Maybe[ta.Any]:
|
21
|
+
return lang.run_maysync(self._ai.try_provide(key))
|
22
|
+
|
23
|
+
def provide(self, key: ta.Any) -> ta.Any:
|
24
|
+
return lang.run_maysync(self._ai.provide(key))
|
25
|
+
|
26
|
+
def provide_kwargs(self, kt: KwargsTarget) -> ta.Mapping[str, ta.Any]:
|
27
|
+
return lang.run_maysync(self._ai.provide_kwargs(kt))
|
28
|
+
|
29
|
+
def inject(self, obj: ta.Any) -> ta.Any:
|
30
|
+
return lang.run_maysync(self._ai.inject(obj))
|
31
|
+
|
32
|
+
|
33
|
+
def create_maysync_injector(es: Elements) -> MaysyncInjector:
|
34
|
+
si = MaysyncInjectorImpl()
|
35
|
+
ai = AsyncInjectorImpl(
|
36
|
+
ElementCollection(es),
|
37
|
+
internal_consts={
|
38
|
+
Key(MaysyncInjector): si,
|
39
|
+
Key(Injector): si,
|
40
|
+
},
|
41
|
+
)
|
42
|
+
si._ai = ai # noqa
|
43
|
+
lang.run_maysync(ai._init()) # noqa
|
44
|
+
return si
|
omlish/inject/impl/multis.py
CHANGED
@@ -3,7 +3,7 @@ import typing as ta
|
|
3
3
|
from ... import dataclasses as dc
|
4
4
|
from ... import lang
|
5
5
|
from ..elements import Element
|
6
|
-
from ..injector import
|
6
|
+
from ..injector import AsyncInjector
|
7
7
|
from ..multis import MapBinding
|
8
8
|
from ..multis import MapProvider
|
9
9
|
from ..multis import SetBinding
|
@@ -26,10 +26,10 @@ class SetProviderImpl(ProviderImpl, lang.Final):
|
|
26
26
|
for p in self.ps:
|
27
27
|
yield from p.providers
|
28
28
|
|
29
|
-
def provide(self, injector:
|
29
|
+
async def provide(self, injector: AsyncInjector) -> ta.Any:
|
30
30
|
rv = set()
|
31
31
|
for ep in self.ps:
|
32
|
-
o = ep.provide(injector)
|
32
|
+
o = await ep.provide(injector)
|
33
33
|
rv.add(o)
|
34
34
|
return rv
|
35
35
|
|
@@ -47,10 +47,10 @@ class MapProviderImpl(ProviderImpl, lang.Final):
|
|
47
47
|
for e in self.es:
|
48
48
|
yield from e.v.providers
|
49
49
|
|
50
|
-
def provide(self, injector:
|
50
|
+
async def provide(self, injector: AsyncInjector) -> ta.Any:
|
51
51
|
rv = {}
|
52
52
|
for e in self.es:
|
53
|
-
o = e.v.provide(injector)
|
53
|
+
o = await e.v.provide(injector)
|
54
54
|
rv[e.k] = o
|
55
55
|
return rv
|
56
56
|
|