anydi 0.26.2__py3-none-any.whl → 0.26.2a0__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.
@@ -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
- interface is parameter.empty
73
- or interface in _anydi_unresolved
74
- or parameter.name in registered_fixtures
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
- request.node.funcargs[argname] = container.resolve(interface)
108
- except Exception: # noqa
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
- request.node.funcargs[argname] = await container.aresolve(interface)
137
- except Exception: # noqa
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.26.2
3
+ Version: 0.26.2a0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -17,12 +17,12 @@ anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8
17
17
  anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI8W-oO2w,2696
18
18
  anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
19
19
  anydi/ext/fastapi.py,sha256=kVUKVKtqCx1Nfnm1oh2BMyB0G7qQKPw6OGfxFlqUqtc,5305
20
- anydi/ext/pytest_plugin.py,sha256=pFLcfxGtJfGSqtk7sPrrHFSKOaZoKZTWt5X8CT0ydmA,4242
20
+ anydi/ext/pytest_plugin.py,sha256=AQVBsyEGoQdOvXpa2TlEPYMapzL7a-oKoVcvMnQ5Epk,4477
21
21
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
23
23
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
- anydi-0.26.2.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
25
- anydi-0.26.2.dist-info/METADATA,sha256=t-t-Yma46l0AtxjL_qr-RJtMjdqGRVWjLO1VDzULZX4,5160
26
- anydi-0.26.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
27
- anydi-0.26.2.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
28
- anydi-0.26.2.dist-info/RECORD,,
24
+ anydi-0.26.2a0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
25
+ anydi-0.26.2a0.dist-info/METADATA,sha256=fpgusceJ8gJiULDDjConkYXkWEiG4GHrMgWGZ_8YDQk,5162
26
+ anydi-0.26.2a0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
27
+ anydi-0.26.2a0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
28
+ anydi-0.26.2a0.dist-info/RECORD,,