anydi 0.29.0__py3-none-any.whl → 0.29.2__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 CHANGED
@@ -72,7 +72,7 @@ class Container:
72
72
  self,
73
73
  *,
74
74
  providers: Mapping[type[Any], Provider] | None = None,
75
- modules: Sequence[Module | type[Module] | Callable[[Container], None]]
75
+ modules: Sequence[Module | type[Module] | Callable[[Container], None] | str]
76
76
  | None = None,
77
77
  strict: bool = False,
78
78
  ) -> None:
@@ -410,7 +410,7 @@ class Container:
410
410
  return None
411
411
 
412
412
  def register_module(
413
- self, module: Module | type[Module] | Callable[[Container], None]
413
+ self, module: Module | type[Module] | Callable[[Container], None] | str
414
414
  ) -> None:
415
415
  """Register a module as a callable, module type, or module instance.
416
416
 
anydi/_module.py CHANGED
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, Callable, TypeVar
8
8
  from typing_extensions import Concatenate, NamedTuple, ParamSpec
9
9
 
10
10
  from ._types import Scope
11
+ from ._utils import import_string
11
12
 
12
13
  if TYPE_CHECKING:
13
14
  from ._container import Container
@@ -67,21 +68,27 @@ class ModuleRegistry:
67
68
  self.container = container
68
69
 
69
70
  def register(
70
- self, module: Module | type[Module] | Callable[[Container], None]
71
+ self, module: Module | type[Module] | Callable[[Container], None] | str
71
72
  ) -> None:
72
73
  """Register a module as a callable, module type, or module instance.
73
74
 
74
75
  Args:
75
76
  module: The module to register.
76
77
  """
78
+
77
79
  # Callable Module
78
80
  if inspect.isfunction(module):
79
81
  module(self.container)
80
82
  return
81
83
 
84
+ # Module path
85
+ if isinstance(module, str):
86
+ module = import_string(module)
87
+
82
88
  # Class based Module or Module type
83
89
  if inspect.isclass(module) and issubclass(module, Module):
84
90
  module = module()
91
+
85
92
  if isinstance(module, Module):
86
93
  module.configure(self.container)
87
94
  for provider_name, decorator_args in module.providers:
anydi/_utils.py CHANGED
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import builtins
6
6
  import functools
7
+ import importlib
7
8
  import inspect
8
9
  import sys
9
10
  from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar
@@ -129,3 +130,27 @@ async def run_async(
129
130
  "it first, or consider using `anydi[full]` instead."
130
131
  )
131
132
  return await anyio.to_thread.run_sync(functools.partial(func, *args, **kwargs))
133
+
134
+
135
+ def import_string(dotted_path: str) -> Any:
136
+ """
137
+ Import a module or a specific attribute from a module using its dotted string path.
138
+
139
+ Args:
140
+ dotted_path: The dotted path to the object to import.
141
+
142
+ Returns:
143
+ object: The imported module or attribute/class/function.
144
+
145
+ Raises:
146
+ ImportError: If the import fails.
147
+ """
148
+ try:
149
+ module_path, _, attribute_name = dotted_path.rpartition(".")
150
+ if module_path:
151
+ module = importlib.import_module(module_path)
152
+ return getattr(module, attribute_name)
153
+ else:
154
+ return importlib.import_module(attribute_name)
155
+ except (ImportError, AttributeError) as exc:
156
+ raise ImportError(f"Cannot import '{dotted_path}': {exc}") from exc
@@ -13,7 +13,7 @@ def install(
13
13
  settings: BaseSettings | Iterable[BaseSettings],
14
14
  container: Container,
15
15
  *,
16
- prefix: str = ".settings",
16
+ prefix: str = "settings.",
17
17
  ) -> None:
18
18
  """Install Pydantic settings into an AnyDI container."""
19
19
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.29.0
3
+ Version: 0.29.2
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -1,11 +1,11 @@
1
1
  anydi/__init__.py,sha256=aeaBp5vq09sG-e9sqqs9qpUtUIDNfOdFPrlAfE5Ku9E,584
2
- anydi/_container.py,sha256=-vpiYl2Tx2QK9wl74DiF5qLFRudJ3e78TqEyuyOrthE,29055
2
+ anydi/_container.py,sha256=MyKiQNHKAQ3gb1GzcCZqp6VyUGq2irqqYT7XxX9PXQU,29067
3
3
  anydi/_context.py,sha256=Wm4DT8Ie_TPchWmIBe8Q9f90dQrGd5lY8H5K85rStgY,12706
4
4
  anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
5
- anydi/_module.py,sha256=E1TfLud_Af-MPB83PxIzHVA1jlDW2FGaRP_il1a6y3Y,3675
5
+ anydi/_module.py,sha256=PoMdn-6KlDSiq-0Z7TesSnG-_fg6tyGxC1pjNydplTk,3819
6
6
  anydi/_scanner.py,sha256=cyEk-K2Q8ssZStq8GrxMeEcCuAZMw-RXrjlgWEevKCs,6667
7
7
  anydi/_types.py,sha256=i8xFxz8pmFj7SGqwOwae_P9VtiRie6DVLwfaLibLwhc,3653
8
- anydi/_utils.py,sha256=q6vEI3_vmZ5sMNau2E5EVk3uMG5geDnXYOW83-vW08M,3857
8
+ anydi/_utils.py,sha256=Z6Hdf68LW4f8vihFaxg4kbVICzddP5A1nYXa5Id9AfE,4640
9
9
  anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  anydi/ext/_utils.py,sha256=2kxLPTMM9Ro3s6-knbqYzONlqRB3hMcwZFFRQGHcFUg,2691
11
11
  anydi/ext/django/__init__.py,sha256=QI1IABCVgSDTUoh7M9WMECKXwB3xvh04HfQ9TOWw1Mk,223
@@ -19,13 +19,13 @@ 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=L4rkWYIO4ZZuWH-8M8NT6_J0bT0Dz_EWO3B6Oj1iFBI,2024
22
- anydi/ext/pydantic_settings.py,sha256=UwJWByusXLKvlIp5gBHslgUom2bK93QZwwFhJgzY1gg,1490
22
+ anydi/ext/pydantic_settings.py,sha256=PciVSSyRzk1Uu3Ppz-Y58pqcsZyUVIcZIzYOgJMB_4I,1490
23
23
  anydi/ext/pytest_plugin.py,sha256=3OWphc4nEzla46_8KR7LXtwGns5eol_YlUWfTf4Cr2Q,3952
24
24
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
26
26
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- anydi-0.29.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
28
- anydi-0.29.0.dist-info/METADATA,sha256=HgsJLUAb-SP361yfEM5mI4Y7Q6MWNiA2sL1m1RIccl4,5111
29
- anydi-0.29.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
- anydi-0.29.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
31
- anydi-0.29.0.dist-info/RECORD,,
27
+ anydi-0.29.2.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
28
+ anydi-0.29.2.dist-info/METADATA,sha256=fFZGKKiHkGJkCDY3wAe-kaPuAP9x2UxOtvZModtB39k,5111
29
+ anydi-0.29.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
+ anydi-0.29.2.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
31
+ anydi-0.29.2.dist-info/RECORD,,
File without changes