modern-di 0.4.0__tar.gz → 0.4.2__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.

Potentially problematic release.


This version of modern-di might be problematic. Click here for more details.

Files changed (52) hide show
  1. modern_di-0.4.2/.github/workflows/publish.yml +26 -0
  2. {modern_di-0.4.0 → modern_di-0.4.2}/Justfile +2 -2
  3. {modern_di-0.4.0 → modern_di-0.4.2}/PKG-INFO +1 -1
  4. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/pyproject.toml +3 -3
  5. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/__init__.py +4 -0
  6. modern_di-0.4.2/modern_di/providers/context_adapter.py +27 -0
  7. {modern_di-0.4.0 → modern_di-0.4.2}/pyproject.toml +6 -0
  8. modern_di-0.4.2/tests/providers/__init__.py +0 -0
  9. modern_di-0.4.2/tests/providers/test_context_adapter.py +30 -0
  10. modern_di-0.4.0/.github/workflows/publish.yml +0 -41
  11. modern_di-0.4.0/integrations/fastapi/Justfile +0 -23
  12. {modern_di-0.4.0 → modern_di-0.4.2}/.github/workflows/core-ci.yml +0 -0
  13. {modern_di-0.4.0 → modern_di-0.4.2}/.github/workflows/fastapi-ci.yml +0 -0
  14. {modern_di-0.4.0 → modern_di-0.4.2}/.gitignore +0 -0
  15. {modern_di-0.4.0 → modern_di-0.4.2}/.readthedocs.yaml +0 -0
  16. {modern_di-0.4.0 → modern_di-0.4.2}/LICENSE +0 -0
  17. {modern_di-0.4.0 → modern_di-0.4.2}/README.md +0 -0
  18. {modern_di-0.4.0 → modern_di-0.4.2}/docs/conf.py +0 -0
  19. {modern_di-0.4.0 → modern_di-0.4.2}/docs/dev/contributing.md +0 -0
  20. {modern_di-0.4.0 → modern_di-0.4.2}/docs/dev/development-notes.md +0 -0
  21. {modern_di-0.4.0 → modern_di-0.4.2}/docs/index.md +0 -0
  22. {modern_di-0.4.0 → modern_di-0.4.2}/docs/requirements.txt +0 -0
  23. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/README.md +0 -0
  24. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/modern_di_fastapi/__init__.py +0 -0
  25. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/modern_di_fastapi/depends.py +0 -0
  26. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/modern_di_fastapi/middleware.py +0 -0
  27. {modern_di-0.4.0/modern_di → modern_di-0.4.2/integrations/fastapi/modern_di_fastapi}/py.typed +0 -0
  28. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/tests/__init__.py +0 -0
  29. {modern_di-0.4.0 → modern_di-0.4.2}/integrations/fastapi/tests/test_fastapi_di.py +0 -0
  30. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/__init__.py +0 -0
  31. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/container.py +0 -0
  32. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/graph.py +0 -0
  33. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/provider_state.py +0 -0
  34. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/abstract.py +0 -0
  35. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/dict.py +0 -0
  36. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/factory.py +0 -0
  37. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/list.py +0 -0
  38. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/resource.py +0 -0
  39. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/selector.py +0 -0
  40. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/providers/singleton.py +0 -0
  41. /modern_di-0.4.0/tests/__init__.py → /modern_di-0.4.2/modern_di/py.typed +0 -0
  42. {modern_di-0.4.0 → modern_di-0.4.2}/modern_di/scope.py +0 -0
  43. {modern_di-0.4.0/tests/providers → modern_di-0.4.2/tests}/__init__.py +0 -0
  44. {modern_di-0.4.0 → modern_di-0.4.2}/tests/creators.py +0 -0
  45. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_dict.py +0 -0
  46. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_factory.py +0 -0
  47. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_list.py +0 -0
  48. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_resource.py +0 -0
  49. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_selector.py +0 -0
  50. {modern_di-0.4.0 → modern_di-0.4.2}/tests/providers/test_singleton.py +0 -0
  51. {modern_di-0.4.0 → modern_di-0.4.2}/tests/test_container.py +0 -0
  52. {modern_di-0.4.0 → modern_di-0.4.2}/tests/test_graph.py +0 -0
@@ -0,0 +1,26 @@
1
+ name: Publish Package
2
+
3
+ on:
4
+ release:
5
+ types:
6
+ - published
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: extractions/setup-just@v2
14
+ - uses: astral-sh/setup-uv@v3
15
+ with:
16
+ enable-cache: true
17
+ cache-dependency-glob: "pyproject.toml"
18
+ - run: just publish modern-di
19
+ if: startsWith(github.ref_name, 'core')
20
+ env:
21
+ PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
22
+
23
+ - run: just publish modern-di-fastapi
24
+ if: startsWith(github.ref_name, 'fastapi')
25
+ env:
26
+ PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -17,7 +17,7 @@ lint-ci:
17
17
  test *args:
18
18
  uv run pytest tests {{ args }}
19
19
 
20
- publish:
20
+ publish package:
21
21
  rm -rf dist
22
- uv build
22
+ uv build --package {{package}}
23
23
  uv publish --token $PYPI_TOKEN
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: modern-di
3
- Version: 0.4.0
3
+ Version: 0.4.2
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"
@@ -52,6 +49,9 @@ build-backend = "hatchling.build"
52
49
  source = "vcs"
53
50
  fallback-version = "0"
54
51
 
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["integrations/fastapi"]
54
+
55
55
  [tool.mypy]
56
56
  python_version = "3.10"
57
57
  strict = true
@@ -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
@@ -1,41 +0,0 @@
1
- name: Publish Package
2
-
3
- on:
4
- release:
5
- types:
6
- - published
7
-
8
- jobs:
9
- publish-core:
10
- if: startsWith(github.ref_name, 'core')
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v4
14
- - uses: extractions/setup-just@v2
15
- - uses: astral-sh/setup-uv@v3
16
- with:
17
- enable-cache: true
18
- cache-dependency-glob: "pyproject.toml"
19
- - run: just publish
20
- env:
21
- PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
22
-
23
- publish-fastapi:
24
- if: startsWith(github.ref_name, 'fastapi')
25
- runs-on: ubuntu-latest
26
- defaults:
27
- run:
28
- working-directory: integrations/fastapi
29
- steps:
30
- - uses: actions/checkout@v4
31
- - uses: extractions/setup-just@v2
32
- - uses: astral-sh/setup-uv@v3
33
- with:
34
- enable-cache: true
35
- cache-dependency-glob: "pyproject.toml"
36
- - run: |
37
- export SETUPTOOLS_SCM_PRETEND_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^fastapi-//; s/-.*$//')
38
- echo "SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION"
39
- just publish
40
- env:
41
- PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -1,23 +0,0 @@
1
- default: install lint test
2
-
3
- install:
4
- uv lock --upgrade
5
- uv sync --all-extras --frozen
6
-
7
- lint:
8
- uv run ruff format .
9
- uv run ruff check . --fix
10
- uv run mypy .
11
-
12
- lint-ci:
13
- uv run ruff format . --check
14
- uv run ruff check . --no-fix
15
- uv run mypy .
16
-
17
- test *args:
18
- uv run pytest {{ args }}
19
-
20
- publish:
21
- rm -rf dist
22
- uv build
23
- uv publish --token $PYPI_TOKEN
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