python-injection 0.9.5__py3-none-any.whl → 0.9.6__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 python-injection might be problematic. Click here for more details.
- injection/__init__.py +3 -3
- injection/__init__.pyi +13 -13
- injection/{common → _core/common}/lazy.py +1 -1
- injection/{common/tools → _core/common}/threading.py +2 -1
- injection/{core → _core}/module.py +27 -28
- injection/utils.py +8 -8
- {python_injection-0.9.5.dist-info → python_injection-0.9.6.dist-info}/METADATA +1 -1
- python_injection-0.9.6.dist-info/RECORD +20 -0
- injection/common/tools/__init__.py +0 -0
- python_injection-0.9.5.dist-info/RECORD +0 -21
- /injection/{core → _core}/__init__.py +0 -0
- /injection/{common → _core/common}/__init__.py +0 -0
- /injection/{common → _core/common}/event.py +0 -0
- /injection/{common → _core/common}/invertible.py +0 -0
- /injection/{common/tools → _core/common}/type.py +0 -0
- {python_injection-0.9.5.dist-info → python_injection-0.9.6.dist-info}/WHEEL +0 -0
injection/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from .
|
|
2
|
-
from .
|
|
3
|
-
from .
|
|
1
|
+
from ._core import Injectable, Module
|
|
2
|
+
from ._core import Mode as InjectableMode
|
|
3
|
+
from ._core import Priority as ModulePriority
|
|
4
4
|
|
|
5
5
|
__all__ = (
|
|
6
6
|
"Injectable",
|
injection/__init__.pyi
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
2
|
from collections.abc import Callable
|
|
3
3
|
from contextlib import ContextDecorator
|
|
4
|
-
from enum import
|
|
4
|
+
from enum import Enum
|
|
5
5
|
from logging import Logger
|
|
6
6
|
from types import UnionType
|
|
7
7
|
from typing import (
|
|
@@ -13,11 +13,11 @@ from typing import (
|
|
|
13
13
|
runtime_checkable,
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
18
|
-
from .
|
|
19
|
-
from .
|
|
20
|
-
from .
|
|
16
|
+
from ._core import InjectableFactory as _InjectableFactory
|
|
17
|
+
from ._core import ModeStr as InjectableModeStr
|
|
18
|
+
from ._core import PriorityStr as ModulePriorityStr
|
|
19
|
+
from ._core.common.invertible import Invertible as _Invertible
|
|
20
|
+
from ._core.common.type import TypeInfo as _TypeInfo
|
|
21
21
|
|
|
22
22
|
_: Module = ...
|
|
23
23
|
|
|
@@ -62,9 +62,9 @@ class Module:
|
|
|
62
62
|
wrapped: Callable[..., T] = ...,
|
|
63
63
|
/,
|
|
64
64
|
*,
|
|
65
|
-
cls:
|
|
65
|
+
cls: _InjectableFactory[T] = ...,
|
|
66
66
|
inject: bool = ...,
|
|
67
|
-
on:
|
|
67
|
+
on: _TypeInfo[T] = ...,
|
|
68
68
|
mode: InjectableMode | InjectableModeStr = ...,
|
|
69
69
|
):
|
|
70
70
|
"""
|
|
@@ -79,7 +79,7 @@ class Module:
|
|
|
79
79
|
/,
|
|
80
80
|
*,
|
|
81
81
|
inject: bool = ...,
|
|
82
|
-
on:
|
|
82
|
+
on: _TypeInfo[T] = ...,
|
|
83
83
|
mode: InjectableMode | InjectableModeStr = ...,
|
|
84
84
|
):
|
|
85
85
|
"""
|
|
@@ -98,7 +98,7 @@ class Module:
|
|
|
98
98
|
def set_constant[T](
|
|
99
99
|
self,
|
|
100
100
|
instance: T,
|
|
101
|
-
on:
|
|
101
|
+
on: _TypeInfo[T] = ...,
|
|
102
102
|
*,
|
|
103
103
|
mode: InjectableMode | InjectableModeStr = ...,
|
|
104
104
|
) -> Self:
|
|
@@ -125,7 +125,7 @@ class Module:
|
|
|
125
125
|
cls: type[T],
|
|
126
126
|
*,
|
|
127
127
|
cache: bool = ...,
|
|
128
|
-
) ->
|
|
128
|
+
) -> _Invertible[T | None]:
|
|
129
129
|
"""
|
|
130
130
|
Function used to retrieve an instance associated with the type passed in
|
|
131
131
|
parameter or `None`. Return a `Invertible` object. To access the instance
|
|
@@ -199,7 +199,7 @@ class Module:
|
|
|
199
199
|
"""
|
|
200
200
|
|
|
201
201
|
@final
|
|
202
|
-
class ModulePriority(
|
|
202
|
+
class ModulePriority(Enum):
|
|
203
203
|
LOW = ...
|
|
204
204
|
HIGH = ...
|
|
205
205
|
|
|
@@ -212,7 +212,7 @@ class Injectable[T](Protocol):
|
|
|
212
212
|
def get_instance(self) -> T: ...
|
|
213
213
|
|
|
214
214
|
@final
|
|
215
|
-
class InjectableMode(
|
|
215
|
+
class InjectableMode(Enum):
|
|
216
216
|
FALLBACK = ...
|
|
217
217
|
NORMAL = ...
|
|
218
218
|
OVERRIDE = ...
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
1
2
|
from contextlib import contextmanager
|
|
2
3
|
from threading import RLock
|
|
3
4
|
|
|
@@ -5,7 +6,7 @@ __all__ = ("synchronized",)
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
@contextmanager
|
|
8
|
-
def synchronized():
|
|
9
|
+
def synchronized() -> Iterator[RLock]:
|
|
9
10
|
lock = RLock()
|
|
10
11
|
|
|
11
12
|
with lock:
|
|
@@ -30,12 +30,13 @@ from typing import (
|
|
|
30
30
|
Self,
|
|
31
31
|
runtime_checkable,
|
|
32
32
|
)
|
|
33
|
+
from uuid import uuid4
|
|
33
34
|
|
|
34
|
-
from injection.common.event import Event, EventChannel, EventListener
|
|
35
|
-
from injection.common.invertible import Invertible, SimpleInvertible
|
|
36
|
-
from injection.common.lazy import Lazy, LazyMapping
|
|
37
|
-
from injection.common.
|
|
38
|
-
from injection.common.
|
|
35
|
+
from injection._core.common.event import Event, EventChannel, EventListener
|
|
36
|
+
from injection._core.common.invertible import Invertible, SimpleInvertible
|
|
37
|
+
from injection._core.common.lazy import Lazy, LazyMapping
|
|
38
|
+
from injection._core.common.threading import synchronized
|
|
39
|
+
from injection._core.common.type import (
|
|
39
40
|
TypeInfo,
|
|
40
41
|
TypeReport,
|
|
41
42
|
analyze_types,
|
|
@@ -65,12 +66,12 @@ Events
|
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
@dataclass(frozen=True, slots=True)
|
|
68
|
-
class
|
|
69
|
-
|
|
69
|
+
class LocatorEvent(Event, ABC):
|
|
70
|
+
locator: Locator
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
@dataclass(frozen=True, slots=True)
|
|
73
|
-
class
|
|
74
|
+
class LocatorDependenciesUpdated(LocatorEvent):
|
|
74
75
|
reports: Collection[TypeReport]
|
|
75
76
|
mode: Mode
|
|
76
77
|
|
|
@@ -78,8 +79,8 @@ class ContainerDependenciesUpdated(ContainerEvent):
|
|
|
78
79
|
length = len(self.reports)
|
|
79
80
|
formatted_types = ", ".join(f"`{report.type}`" for report in self.reports)
|
|
80
81
|
return (
|
|
81
|
-
f"{length}
|
|
82
|
-
f"
|
|
82
|
+
f"{length} dependenc{"ies" if length > 1 else "y"} have been "
|
|
83
|
+
f"updated{f": {formatted_types}" if formatted_types else ""}."
|
|
83
84
|
)
|
|
84
85
|
|
|
85
86
|
|
|
@@ -232,7 +233,7 @@ class Broker(Protocol):
|
|
|
232
233
|
|
|
233
234
|
|
|
234
235
|
"""
|
|
235
|
-
|
|
236
|
+
Locator
|
|
236
237
|
"""
|
|
237
238
|
|
|
238
239
|
|
|
@@ -259,7 +260,7 @@ class Record[T](NamedTuple):
|
|
|
259
260
|
|
|
260
261
|
|
|
261
262
|
@dataclass(repr=False, frozen=True, slots=True)
|
|
262
|
-
class
|
|
263
|
+
class Locator(Broker):
|
|
263
264
|
__records: dict[TypeReport, Record] = field(default_factory=dict, init=False)
|
|
264
265
|
__channel: EventChannel = field(default_factory=EventChannel, init=False)
|
|
265
266
|
|
|
@@ -294,13 +295,14 @@ class Container(Broker):
|
|
|
294
295
|
mode: Mode | ModeStr,
|
|
295
296
|
) -> Self:
|
|
296
297
|
mode = Mode(mode)
|
|
298
|
+
record = Record(injectable, mode)
|
|
297
299
|
records = {
|
|
298
|
-
report:
|
|
300
|
+
report: record
|
|
299
301
|
for report in self.__prepare_reports_for_updating(classes, mode)
|
|
300
302
|
}
|
|
301
303
|
|
|
302
304
|
if records:
|
|
303
|
-
event =
|
|
305
|
+
event = LocatorDependenciesUpdated(self, records.keys(), mode)
|
|
304
306
|
|
|
305
307
|
with self.dispatch(event):
|
|
306
308
|
self.__records.update(records)
|
|
@@ -367,25 +369,25 @@ type InjectableFactory[T] = Callable[[Callable[..., T]], Injectable[T]]
|
|
|
367
369
|
|
|
368
370
|
|
|
369
371
|
@dataclass(eq=False, frozen=True, slots=True)
|
|
370
|
-
class Module(
|
|
371
|
-
name: str
|
|
372
|
+
class Module(Broker, EventListener):
|
|
373
|
+
name: str = field(default_factory=lambda: f"anonymous@{uuid4().hex[:7]}")
|
|
372
374
|
__channel: EventChannel = field(
|
|
373
375
|
default_factory=EventChannel,
|
|
374
376
|
init=False,
|
|
375
377
|
repr=False,
|
|
376
378
|
)
|
|
377
|
-
|
|
378
|
-
default_factory=
|
|
379
|
+
__locator: Locator = field(
|
|
380
|
+
default_factory=Locator,
|
|
379
381
|
init=False,
|
|
380
382
|
repr=False,
|
|
381
383
|
)
|
|
382
|
-
|
|
383
|
-
default_factory=
|
|
384
|
+
__loggers: list[Logger] = field(
|
|
385
|
+
default_factory=lambda: [getLogger(__name__)],
|
|
384
386
|
init=False,
|
|
385
387
|
repr=False,
|
|
386
388
|
)
|
|
387
|
-
|
|
388
|
-
default_factory=
|
|
389
|
+
__modules: OrderedDict[Module, None] = field(
|
|
390
|
+
default_factory=OrderedDict,
|
|
389
391
|
init=False,
|
|
390
392
|
repr=False,
|
|
391
393
|
)
|
|
@@ -393,7 +395,7 @@ class Module(EventListener, Broker):
|
|
|
393
395
|
__instances: ClassVar[dict[str, Module]] = {}
|
|
394
396
|
|
|
395
397
|
def __post_init__(self):
|
|
396
|
-
self.
|
|
398
|
+
self.__locator.add_listener(self)
|
|
397
399
|
|
|
398
400
|
def __getitem__[T](self, cls: type[T] | UnionType, /) -> Injectable[T]:
|
|
399
401
|
for broker in self.__brokers:
|
|
@@ -402,9 +404,6 @@ class Module(EventListener, Broker):
|
|
|
402
404
|
|
|
403
405
|
raise NoInjectable(cls)
|
|
404
406
|
|
|
405
|
-
def __setitem__[T](self, cls: type[T] | UnionType, injectable: Injectable[T], /):
|
|
406
|
-
self.update((cls,), injectable)
|
|
407
|
-
|
|
408
407
|
def __contains__(self, cls: type | UnionType, /) -> bool:
|
|
409
408
|
return any(cls in broker for broker in self.__brokers)
|
|
410
409
|
|
|
@@ -415,7 +414,7 @@ class Module(EventListener, Broker):
|
|
|
415
414
|
@property
|
|
416
415
|
def __brokers(self) -> Iterator[Broker]:
|
|
417
416
|
yield from tuple(self.__modules)
|
|
418
|
-
yield self.
|
|
417
|
+
yield self.__locator
|
|
419
418
|
|
|
420
419
|
def injectable[T](
|
|
421
420
|
self,
|
|
@@ -517,7 +516,7 @@ class Module(EventListener, Broker):
|
|
|
517
516
|
injectable: Injectable[T],
|
|
518
517
|
mode: Mode | ModeStr = Mode.get_default(),
|
|
519
518
|
) -> Self:
|
|
520
|
-
self.
|
|
519
|
+
self.__locator.update(classes, injectable, mode)
|
|
521
520
|
return self
|
|
522
521
|
|
|
523
522
|
def init_modules(self, *modules: Module) -> Self:
|
injection/utils.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
from collections.abc import Callable, Iterator
|
|
2
2
|
from importlib import import_module
|
|
3
3
|
from pkgutil import walk_packages
|
|
4
|
-
from types import ModuleType
|
|
4
|
+
from types import ModuleType as PythonModule
|
|
5
5
|
|
|
6
6
|
__all__ = ("load_package",)
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def load_package(
|
|
10
|
-
package:
|
|
10
|
+
package: PythonModule | str,
|
|
11
11
|
predicate: Callable[[str], bool] = lambda module_name: True,
|
|
12
|
-
) ->
|
|
12
|
+
) -> dict[str, PythonModule]:
|
|
13
13
|
"""
|
|
14
14
|
Function for importing all modules in a Python package.
|
|
15
15
|
Pass the `predicate` parameter if you want to filter the modules to be imported.
|
|
@@ -18,13 +18,13 @@ def load_package(
|
|
|
18
18
|
if isinstance(package, str):
|
|
19
19
|
package = import_module(package)
|
|
20
20
|
|
|
21
|
-
return
|
|
21
|
+
return dict(__iter_modules_from(package, predicate))
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
def
|
|
25
|
-
package:
|
|
24
|
+
def __iter_modules_from(
|
|
25
|
+
package: PythonModule,
|
|
26
26
|
predicate: Callable[[str], bool],
|
|
27
|
-
) -> Iterator[
|
|
27
|
+
) -> Iterator[tuple[str, PythonModule]]:
|
|
28
28
|
try:
|
|
29
29
|
path = package.__path__
|
|
30
30
|
except AttributeError as exc:
|
|
@@ -38,4 +38,4 @@ def __iter_modules(
|
|
|
38
38
|
if info.ispkg or not predicate(name):
|
|
39
39
|
continue
|
|
40
40
|
|
|
41
|
-
yield import_module(name)
|
|
41
|
+
yield name, import_module(name)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
injection/__init__.py,sha256=fgJUzsuSCJtNxm_3gjbN6UzOg5mOuc5jiOjiQXFL0J0,801
|
|
2
|
+
injection/__init__.pyi,sha256=D0E6rveKVN0p7wnaIxSZdXCXaPnuCMriptSijmSE0jM,6454
|
|
3
|
+
injection/_core/__init__.py,sha256=zuf0ubI2dHnbjn1059eduhS-ACIkkROa6-dhp10krh0,22
|
|
4
|
+
injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
injection/_core/common/event.py,sha256=5Rdb2m3vAMCic8cQAVkStJDbrDrW_lk6kav8wYwmexM,1283
|
|
6
|
+
injection/_core/common/invertible.py,sha256=a-fht4TxMnki-oFFaZrDz52X_LWx0NU60KQlw72pzs4,528
|
|
7
|
+
injection/_core/common/lazy.py,sha256=id5XWqk366ZcOpbd1svaLj3rqWVM9f1ZFQV5PVWnDTc,1321
|
|
8
|
+
injection/_core/common/threading.py,sha256=-JHNOKgTAQaCannZsL9xiivokvO61HEs_sPtcLrABk4,243
|
|
9
|
+
injection/_core/common/type.py,sha256=u6nJ14Z7CRqPj2JIbGd1SYRkFfL-bs5zZQE-ouf_UkY,1746
|
|
10
|
+
injection/_core/module.py,sha256=s1hHYGIgUwswYioj80pbIwB3d0z0yJBLak8acxu7qWg,22092
|
|
11
|
+
injection/exceptions.py,sha256=RsWWiWwKSMU0vxXQqQSn6CKHLMrGu4SSzYUAy9OJRXk,626
|
|
12
|
+
injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
injection/integrations/blacksheep.py,sha256=W6gscAojoPhjvYJJ1Z7Zj5EjR0beJmfoLFDq6ijdJUg,711
|
|
14
|
+
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
injection/testing/__init__.py,sha256=haC6VtEfwupbpfuq-cIR_AFZOxTMrNwG_OT3c9z2pCE,814
|
|
16
|
+
injection/testing/__init__.pyi,sha256=1L-C_6mRaL_8o3EChkrf7qAkNjhoojcxNf3HVdt5WWo,484
|
|
17
|
+
injection/utils.py,sha256=sPQXzhsvUUZ3dIRu_IyNhWYgNROY5SEYk7bXQYcId9s,1171
|
|
18
|
+
python_injection-0.9.6.dist-info/METADATA,sha256=H-Jauip9GhFNsHnlqLa1pM_pAEXKL7TXp3MLZ8XaH78,4156
|
|
19
|
+
python_injection-0.9.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
20
|
+
python_injection-0.9.6.dist-info/RECORD,,
|
|
File without changes
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
injection/__init__.py,sha256=4kwoQN5V-fcasIbZ3G3_zCbmnvGCqTilJ92Lwu62wXc,798
|
|
2
|
-
injection/__init__.pyi,sha256=wdZ6l_9LgoUDM-QC8PNq2Y4RxKisnlE89Fhxov_ujvk,6399
|
|
3
|
-
injection/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
injection/common/event.py,sha256=5Rdb2m3vAMCic8cQAVkStJDbrDrW_lk6kav8wYwmexM,1283
|
|
5
|
-
injection/common/invertible.py,sha256=a-fht4TxMnki-oFFaZrDz52X_LWx0NU60KQlw72pzs4,528
|
|
6
|
-
injection/common/lazy.py,sha256=SpQhlGBpMpeD9R5R-CdIInSVDv1XZWvnkERp1J6wsus,1315
|
|
7
|
-
injection/common/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
injection/common/tools/threading.py,sha256=HlvP6k_-eZaK8JbB2b9PP171IZVe_0W2oMYsw3ebdKA,187
|
|
9
|
-
injection/common/tools/type.py,sha256=u6nJ14Z7CRqPj2JIbGd1SYRkFfL-bs5zZQE-ouf_UkY,1746
|
|
10
|
-
injection/core/__init__.py,sha256=zuf0ubI2dHnbjn1059eduhS-ACIkkROa6-dhp10krh0,22
|
|
11
|
-
injection/core/module.py,sha256=9Kv9wa37yknlGy3xwfovE0ZRJs350VIBbl3SIYjXr_w,22157
|
|
12
|
-
injection/exceptions.py,sha256=RsWWiWwKSMU0vxXQqQSn6CKHLMrGu4SSzYUAy9OJRXk,626
|
|
13
|
-
injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
injection/integrations/blacksheep.py,sha256=W6gscAojoPhjvYJJ1Z7Zj5EjR0beJmfoLFDq6ijdJUg,711
|
|
15
|
-
injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
-
injection/testing/__init__.py,sha256=haC6VtEfwupbpfuq-cIR_AFZOxTMrNwG_OT3c9z2pCE,814
|
|
17
|
-
injection/testing/__init__.pyi,sha256=1L-C_6mRaL_8o3EChkrf7qAkNjhoojcxNf3HVdt5WWo,484
|
|
18
|
-
injection/utils.py,sha256=0nOJwQNqjeAAPVKdHTFdYczxPQVekbFeXhjJCEQmom8,1121
|
|
19
|
-
python_injection-0.9.5.dist-info/METADATA,sha256=uJUl9D0_QomYu2kqOdvK8pTBv7zfHDNpUPAqmaqJRhs,4156
|
|
20
|
-
python_injection-0.9.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
21
|
-
python_injection-0.9.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|