anydi 0.29.1__py3-none-any.whl → 0.30.0__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
@@ -15,7 +15,7 @@ from anydi import Container
15
15
 
16
16
 
17
17
  def register_settings(
18
- container: Container, prefix: str = "django.conf.setting."
18
+ container: Container, prefix: str = "django.conf.settings."
19
19
  ) -> None:
20
20
  """Register Django settings into the container."""
21
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.29.1
3
+ Version: 0.30.0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -22,6 +22,7 @@ Classifier: Programming Language :: Python :: 3.10
22
22
  Classifier: Programming Language :: Python :: 3.11
23
23
  Classifier: Programming Language :: Python :: 3.12
24
24
  Classifier: Programming Language :: Python :: 3 :: Only
25
+ Classifier: Programming Language :: Python :: 3.13
25
26
  Classifier: Topic :: Internet
26
27
  Classifier: Topic :: Software Development
27
28
  Classifier: Topic :: Software Development :: Libraries
@@ -1,17 +1,17 @@
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
12
12
  anydi/ext/django/_container.py,sha256=cxVoYQG16WP0S_Yv4TnLwuaaT7NVEOhLWO-YdALJUb4,418
13
13
  anydi/ext/django/_settings.py,sha256=cKzFBGtPCsexZ2ZcInubBukIebhxzNfa3F0KuwoZYaA,844
14
- anydi/ext/django/_utils.py,sha256=E0GGxsEJiSJsA4-8AcEwfdUi_iK7qGpKfGNRDKmDqEg,3976
14
+ anydi/ext/django/_utils.py,sha256=8-VqdWjgzSE145v6WCgcP0cXG5wtez3ZVGOSD30vD5o,3977
15
15
  anydi/ext/django/apps.py,sha256=-gj_tqb6goeYMNItr6nwWHYXZwDOdiH8anby0YwnUmw,2866
16
16
  anydi/ext/django/middleware.py,sha256=iVHWtE829khMY-BXbNNt0g2FrIApKprna7dCG9ObEis,823
17
17
  anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8iWWrk,546
@@ -24,8 +24,8 @@ anydi/ext/pytest_plugin.py,sha256=3OWphc4nEzla46_8KR7LXtwGns5eol_YlUWfTf4Cr2Q,39
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.1.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
28
- anydi-0.29.1.dist-info/METADATA,sha256=4yY2manpxlkXgCN9XvOMSZuL50vVwzXov7yfep3pw94,5111
29
- anydi-0.29.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
- anydi-0.29.1.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
31
- anydi-0.29.1.dist-info/RECORD,,
27
+ anydi-0.30.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
28
+ anydi-0.30.0.dist-info/METADATA,sha256=DFCfcxI3AhedhOr8XEEb5JfGRv5daeZnxQlN1C_RPUA,5162
29
+ anydi-0.30.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
+ anydi-0.30.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
31
+ anydi-0.30.0.dist-info/RECORD,,
File without changes