anydi 0.26.2__tar.gz → 0.26.2a0__tar.gz
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-0.26.2 → anydi-0.26.2a0}/PKG-INFO +1 -1
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/pytest_plugin.py +24 -17
- {anydi-0.26.2 → anydi-0.26.2a0}/pyproject.toml +1 -1
- {anydi-0.26.2 → anydi-0.26.2a0}/LICENSE +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/README.md +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/__init__.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_container.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_context.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_logger.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_module.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_scanner.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_types.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/_utils.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/__init__.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/_container.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/apps.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/fastapi.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.26.2 → anydi-0.26.2a0}/anydi/py.typed +0 -0
|
@@ -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"
|
|
@@ -64,15 +71,17 @@ def _anydi_injected_parameter_iterator(
|
|
|
64
71
|
_anydi_unresolved: list[str],
|
|
65
72
|
) -> Callable[[], Iterator[tuple[str, Any]]]:
|
|
66
73
|
registered_fixtures = request.session._fixturemanager._arg2fixturedefs # noqa
|
|
74
|
+
inject_auto = cast(bool, request.config.getini("anydi_inject_auto"))
|
|
67
75
|
|
|
68
76
|
def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
|
|
69
77
|
for parameter in get_typed_parameters(request.function):
|
|
70
78
|
interface = parameter.annotation
|
|
71
|
-
if
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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:
|
|
76
85
|
continue
|
|
77
86
|
yield parameter.name, interface
|
|
78
87
|
|
|
@@ -95,18 +104,17 @@ def _anydi_inject(
|
|
|
95
104
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
96
105
|
|
|
97
106
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
98
|
-
# Skip if the interface is not registered
|
|
99
|
-
if container.strict and not container.is_registered(interface):
|
|
100
|
-
continue
|
|
101
|
-
|
|
102
107
|
# Release the instance if it was already resolved
|
|
103
108
|
if container.is_resolved(interface):
|
|
104
109
|
container.release(interface)
|
|
105
110
|
|
|
106
111
|
try:
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
# Resolve the instance
|
|
113
|
+
instance = container.resolve(interface)
|
|
114
|
+
except LookupError:
|
|
109
115
|
_anydi_unresolved.append(interface)
|
|
116
|
+
continue
|
|
117
|
+
request.node.funcargs[argname] = instance
|
|
110
118
|
|
|
111
119
|
|
|
112
120
|
@pytest.fixture(autouse=True)
|
|
@@ -124,15 +132,14 @@ async def _anydi_ainject(
|
|
|
124
132
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
125
133
|
|
|
126
134
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
127
|
-
# Skip if the interface is not registered
|
|
128
|
-
if container.strict and not container.is_registered(interface):
|
|
129
|
-
continue
|
|
130
|
-
|
|
131
135
|
# Release the instance if it was already resolved
|
|
132
136
|
if container.is_resolved(interface):
|
|
133
137
|
container.release(interface)
|
|
134
138
|
|
|
135
139
|
try:
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
# Resolve the instance
|
|
141
|
+
instance = await container.aresolve(interface)
|
|
142
|
+
except LookupError:
|
|
138
143
|
_anydi_unresolved.append(interface)
|
|
144
|
+
continue
|
|
145
|
+
request.node.funcargs[argname] = instance
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|