modern-di 0.4.0__tar.gz → 0.4.1__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.
Files changed (51) hide show
  1. {modern_di-0.4.0 → modern_di-0.4.1}/PKG-INFO +1 -1
  2. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/pyproject.toml +0 -3
  3. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/__init__.py +4 -0
  4. modern_di-0.4.1/modern_di/providers/context_adapter.py +27 -0
  5. {modern_di-0.4.0 → modern_di-0.4.1}/pyproject.toml +6 -0
  6. modern_di-0.4.1/tests/providers/__init__.py +0 -0
  7. modern_di-0.4.1/tests/providers/test_context_adapter.py +30 -0
  8. {modern_di-0.4.0 → modern_di-0.4.1}/.github/workflows/core-ci.yml +0 -0
  9. {modern_di-0.4.0 → modern_di-0.4.1}/.github/workflows/fastapi-ci.yml +0 -0
  10. {modern_di-0.4.0 → modern_di-0.4.1}/.github/workflows/publish.yml +0 -0
  11. {modern_di-0.4.0 → modern_di-0.4.1}/.gitignore +0 -0
  12. {modern_di-0.4.0 → modern_di-0.4.1}/.readthedocs.yaml +0 -0
  13. {modern_di-0.4.0 → modern_di-0.4.1}/Justfile +0 -0
  14. {modern_di-0.4.0 → modern_di-0.4.1}/LICENSE +0 -0
  15. {modern_di-0.4.0 → modern_di-0.4.1}/README.md +0 -0
  16. {modern_di-0.4.0 → modern_di-0.4.1}/docs/conf.py +0 -0
  17. {modern_di-0.4.0 → modern_di-0.4.1}/docs/dev/contributing.md +0 -0
  18. {modern_di-0.4.0 → modern_di-0.4.1}/docs/dev/development-notes.md +0 -0
  19. {modern_di-0.4.0 → modern_di-0.4.1}/docs/index.md +0 -0
  20. {modern_di-0.4.0 → modern_di-0.4.1}/docs/requirements.txt +0 -0
  21. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/Justfile +0 -0
  22. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/README.md +0 -0
  23. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/modern_di_fastapi/__init__.py +0 -0
  24. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/modern_di_fastapi/depends.py +0 -0
  25. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/modern_di_fastapi/middleware.py +0 -0
  26. {modern_di-0.4.0/modern_di → modern_di-0.4.1/integrations/fastapi/modern_di_fastapi}/py.typed +0 -0
  27. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/tests/__init__.py +0 -0
  28. {modern_di-0.4.0 → modern_di-0.4.1}/integrations/fastapi/tests/test_fastapi_di.py +0 -0
  29. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/__init__.py +0 -0
  30. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/container.py +0 -0
  31. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/graph.py +0 -0
  32. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/provider_state.py +0 -0
  33. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/abstract.py +0 -0
  34. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/dict.py +0 -0
  35. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/factory.py +0 -0
  36. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/list.py +0 -0
  37. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/resource.py +0 -0
  38. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/selector.py +0 -0
  39. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/providers/singleton.py +0 -0
  40. /modern_di-0.4.0/tests/__init__.py → /modern_di-0.4.1/modern_di/py.typed +0 -0
  41. {modern_di-0.4.0 → modern_di-0.4.1}/modern_di/scope.py +0 -0
  42. {modern_di-0.4.0/tests/providers → modern_di-0.4.1/tests}/__init__.py +0 -0
  43. {modern_di-0.4.0 → modern_di-0.4.1}/tests/creators.py +0 -0
  44. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_dict.py +0 -0
  45. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_factory.py +0 -0
  46. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_list.py +0 -0
  47. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_resource.py +0 -0
  48. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_selector.py +0 -0
  49. {modern_di-0.4.0 → modern_di-0.4.1}/tests/providers/test_singleton.py +0 -0
  50. {modern_di-0.4.0 → modern_di-0.4.1}/tests/test_container.py +0 -0
  51. {modern_di-0.4.0 → modern_di-0.4.1}/tests/test_graph.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: modern-di
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Dependency Injection framework with IOC-container and scopes
5
5
  Project-URL: repository, https://github.com/modern-python/modern-di
6
6
  Project-URL: docs, https://modern-di.readthedocs.io
@@ -41,9 +41,6 @@ dev = [
41
41
  "asgi-lifespan",
42
42
  ]
43
43
 
44
- [tool.uv.sources]
45
- modern-di = { path = "../../" }
46
-
47
44
  [build-system]
48
45
  requires = ["hatchling", "hatch-vcs"]
49
46
  build-backend = "hatchling.build"
@@ -1,3 +1,5 @@
1
+ from modern_di.providers.abstract import AbstractProvider
2
+ from modern_di.providers.context_adapter import ContextAdapter
1
3
  from modern_di.providers.dict import Dict
2
4
  from modern_di.providers.factory import Factory
3
5
  from modern_di.providers.list import List
@@ -7,6 +9,8 @@ from modern_di.providers.singleton import Singleton
7
9
 
8
10
 
9
11
  __all__ = [
12
+ "AbstractProvider",
13
+ "ContextAdapter",
10
14
  "Factory",
11
15
  "Dict",
12
16
  "List",
@@ -0,0 +1,27 @@
1
+ import enum
2
+ import typing
3
+
4
+ from modern_di import Container
5
+ from modern_di.providers import AbstractProvider
6
+
7
+
8
+ T_co = typing.TypeVar("T_co", covariant=True)
9
+ P = typing.ParamSpec("P")
10
+
11
+
12
+ class ContextAdapter(AbstractProvider[T_co]):
13
+ __slots__ = [*AbstractProvider.BASE_SLOTS, "_function"]
14
+
15
+ def __init__(
16
+ self,
17
+ scope: enum.IntEnum,
18
+ function: typing.Callable[..., T_co],
19
+ ) -> None:
20
+ super().__init__(scope)
21
+ self._function = function
22
+
23
+ async def async_resolve(self, container: Container) -> T_co:
24
+ return self._function(**container.find_container(self.scope).context)
25
+
26
+ def sync_resolve(self, container: Container) -> T_co:
27
+ return self._function(**container.find_container(self.scope).context)
@@ -35,6 +35,12 @@ dev = [
35
35
  "typing-extensions",
36
36
  ]
37
37
 
38
+ [tool.uv.workspace]
39
+ members = ["integrations/*"]
40
+
41
+ [tool.uv.sources]
42
+ modern-di = { workspace = true }
43
+
38
44
  [build-system]
39
45
  requires = ["hatchling", "hatch-vcs"]
40
46
  build-backend = "hatchling.build"
File without changes
@@ -0,0 +1,30 @@
1
+ import datetime
2
+
3
+ from modern_di import Container, Scope, providers
4
+
5
+
6
+ def context_adapter_function(*, now: datetime.datetime, **_: object) -> datetime.datetime:
7
+ return now
8
+
9
+
10
+ context_adapter = providers.ContextAdapter(Scope.APP, context_adapter_function)
11
+ request_context_adapter = providers.ContextAdapter(Scope.REQUEST, context_adapter_function)
12
+
13
+
14
+ async def test_context_adapter() -> None:
15
+ now = datetime.datetime.now(tz=datetime.timezone.utc)
16
+ async with Container(scope=Scope.APP, context={"now": now}) as app_container:
17
+ instance1 = await context_adapter.async_resolve(app_container)
18
+ instance2 = context_adapter.sync_resolve(app_container)
19
+ assert instance1 is instance2 is now
20
+
21
+
22
+ async def test_context_adapter_in_request_scope() -> None:
23
+ now = datetime.datetime.now(tz=datetime.timezone.utc)
24
+ async with (
25
+ Container(scope=Scope.APP) as app_container,
26
+ app_container.build_child_container(context={"now": now}) as request_container,
27
+ ):
28
+ instance1 = await request_context_adapter.async_resolve(request_container)
29
+ instance2 = request_context_adapter.sync_resolve(request_container)
30
+ assert instance1 is instance2 is now
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