anydi 0.27.0a0__py3-none-any.whl → 0.27.0a1__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.
- anydi/_container.py +11 -1
- anydi/ext/pytest_plugin.py +23 -13
- {anydi-0.27.0a0.dist-info → anydi-0.27.0a1.dist-info}/METADATA +1 -1
- {anydi-0.27.0a0.dist-info → anydi-0.27.0a1.dist-info}/RECORD +7 -7
- {anydi-0.27.0a0.dist-info → anydi-0.27.0a1.dist-info}/LICENSE +0 -0
- {anydi-0.27.0a0.dist-info → anydi-0.27.0a1.dist-info}/WHEEL +0 -0
- {anydi-0.27.0a0.dist-info → anydi-0.27.0a1.dist-info}/entry_points.txt +0 -0
anydi/_container.py
CHANGED
|
@@ -225,7 +225,7 @@ class Container:
|
|
|
225
225
|
scoped_context.delete(interface)
|
|
226
226
|
|
|
227
227
|
# Cleanup provider references
|
|
228
|
-
self.
|
|
228
|
+
self._delete_provider(interface)
|
|
229
229
|
|
|
230
230
|
def _get_provider(self, interface: AnyInterface) -> Provider:
|
|
231
231
|
"""Get provider by interface.
|
|
@@ -288,6 +288,16 @@ class Container:
|
|
|
288
288
|
if provider.is_resource:
|
|
289
289
|
self._providers_cache[provider.scope].append(interface)
|
|
290
290
|
|
|
291
|
+
def _delete_provider(self, interface: AnyInterface) -> None:
|
|
292
|
+
"""Delete a provider by interface.
|
|
293
|
+
|
|
294
|
+
Args:
|
|
295
|
+
interface: The interface for which to delete the provider.
|
|
296
|
+
"""
|
|
297
|
+
provider = self._providers.pop(interface, None)
|
|
298
|
+
if provider is not None and provider.is_resource:
|
|
299
|
+
self._providers_cache[provider.scope].remove(interface)
|
|
300
|
+
|
|
291
301
|
def _validate_provider_scope(self, provider: Provider) -> None:
|
|
292
302
|
"""Validate the scope of a provider.
|
|
293
303
|
|
anydi/ext/pytest_plugin.py
CHANGED
|
@@ -6,6 +6,7 @@ from typing import Any, Callable, Iterator, cast
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
8
|
from anydi import Container
|
|
9
|
+
from anydi._types import is_marker
|
|
9
10
|
from anydi._utils import get_typed_parameters
|
|
10
11
|
|
|
11
12
|
|
|
@@ -23,6 +24,12 @@ def pytest_addoption(parser: pytest.Parser) -> None:
|
|
|
23
24
|
type="bool",
|
|
24
25
|
default=False,
|
|
25
26
|
)
|
|
27
|
+
parser.addini(
|
|
28
|
+
"anydi_inject_auto",
|
|
29
|
+
help="Automatically inject dependencies",
|
|
30
|
+
type="bool",
|
|
31
|
+
default=True,
|
|
32
|
+
)
|
|
26
33
|
|
|
27
34
|
|
|
28
35
|
CONTAINER_FIXTURE_NAME = "container"
|
|
@@ -63,13 +70,18 @@ def _anydi_injected_parameter_iterator(
|
|
|
63
70
|
request: pytest.FixtureRequest,
|
|
64
71
|
_anydi_unresolved: list[str],
|
|
65
72
|
) -> Callable[[], Iterator[tuple[str, Any]]]:
|
|
73
|
+
registered_fixtures = request.session._fixturemanager._arg2fixturedefs # noqa
|
|
74
|
+
inject_auto = cast(bool, request.config.getini("anydi_inject_auto"))
|
|
75
|
+
|
|
66
76
|
def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
|
|
67
77
|
for parameter in get_typed_parameters(request.function):
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
interface = parameter.annotation
|
|
79
|
+
if interface is parameter.empty:
|
|
80
|
+
continue
|
|
81
|
+
if not inject_auto and is_marker(parameter.default):
|
|
82
|
+
yield parameter.name, interface
|
|
83
|
+
continue
|
|
84
|
+
if interface in _anydi_unresolved or parameter.name in registered_fixtures:
|
|
73
85
|
continue
|
|
74
86
|
yield parameter.name, interface
|
|
75
87
|
|
|
@@ -92,11 +104,10 @@ def _anydi_inject(
|
|
|
92
104
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
93
105
|
|
|
94
106
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
# Release the instance if it was already resolved
|
|
108
|
+
if container.is_resolved(interface):
|
|
97
109
|
container.release(interface)
|
|
98
|
-
|
|
99
|
-
pass
|
|
110
|
+
|
|
100
111
|
try:
|
|
101
112
|
# Resolve the instance
|
|
102
113
|
instance = container.resolve(interface)
|
|
@@ -121,11 +132,10 @@ async def _anydi_ainject(
|
|
|
121
132
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
122
133
|
|
|
123
134
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
# Release the instance if it was already resolved
|
|
136
|
+
if container.is_resolved(interface):
|
|
126
137
|
container.release(interface)
|
|
127
|
-
|
|
128
|
-
pass
|
|
138
|
+
|
|
129
139
|
try:
|
|
130
140
|
# Resolve the instance
|
|
131
141
|
instance = await container.aresolve(interface)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
anydi/__init__.py,sha256=aeaBp5vq09sG-e9sqqs9qpUtUIDNfOdFPrlAfE5Ku9E,584
|
|
2
|
-
anydi/_container.py,sha256=
|
|
2
|
+
anydi/_container.py,sha256=iVmVlnhK3qfcSCvDZsbD23x2REBtBD26abqKJuLGyHs,29631
|
|
3
3
|
anydi/_context.py,sha256=e0VX0fiflzW_2O9w3HvUH3YRCwXHsruQjf3Lu-zXgDw,10815
|
|
4
4
|
anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
|
|
5
5
|
anydi/_module.py,sha256=E1TfLud_Af-MPB83PxIzHVA1jlDW2FGaRP_il1a6y3Y,3675
|
|
@@ -19,12 +19,12 @@ anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI
|
|
|
19
19
|
anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
|
|
20
20
|
anydi/ext/fastapi.py,sha256=vhfSyovXuCjvSkx6AiLOTNU975i8wDg72C5fqXQiFLw,2896
|
|
21
21
|
anydi/ext/faststream.py,sha256=svMtqFVSRTpuf4H5yeozHWmrBXi_F8cevb5d2mo3m-E,1617
|
|
22
|
-
anydi/ext/pytest_plugin.py,sha256=
|
|
22
|
+
anydi/ext/pytest_plugin.py,sha256=AQVBsyEGoQdOvXpa2TlEPYMapzL7a-oKoVcvMnQ5Epk,4477
|
|
23
23
|
anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
|
|
25
25
|
anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
-
anydi-0.27.
|
|
27
|
-
anydi-0.27.
|
|
28
|
-
anydi-0.27.
|
|
29
|
-
anydi-0.27.
|
|
30
|
-
anydi-0.27.
|
|
26
|
+
anydi-0.27.0a1.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
|
|
27
|
+
anydi-0.27.0a1.dist-info/METADATA,sha256=9k_8NOREjBfp2612k6n5nwFl3NfTWVQF8V9TrcNALh8,5162
|
|
28
|
+
anydi-0.27.0a1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
29
|
+
anydi-0.27.0a1.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
|
|
30
|
+
anydi-0.27.0a1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|