modern-di 0.5.0__tar.gz → 0.5.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.

Potentially problematic release.


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

Files changed (54) hide show
  1. {modern_di-0.5.0 → modern_di-0.5.1}/PKG-INFO +2 -3
  2. modern_di-0.5.1/pyproject.toml +45 -0
  3. modern_di-0.5.0/.github/workflows/core-ci.yml +0 -52
  4. modern_di-0.5.0/.github/workflows/fastapi-ci.yml +0 -54
  5. modern_di-0.5.0/.github/workflows/publish.yml +0 -30
  6. modern_di-0.5.0/.readthedocs.yaml +0 -13
  7. modern_di-0.5.0/Justfile +0 -23
  8. modern_di-0.5.0/LICENSE +0 -21
  9. modern_di-0.5.0/README.md +0 -20
  10. modern_di-0.5.0/docs/conf.py +0 -34
  11. modern_di-0.5.0/docs/dev/contributing.md +0 -19
  12. modern_di-0.5.0/docs/dev/development-notes.md +0 -25
  13. modern_di-0.5.0/docs/index.md +0 -11
  14. modern_di-0.5.0/docs/requirements.txt +0 -4
  15. modern_di-0.5.0/integrations/fastapi/Justfile +0 -18
  16. modern_di-0.5.0/integrations/fastapi/README.md +0 -6
  17. modern_di-0.5.0/integrations/fastapi/modern_di_fastapi/__init__.py +0 -9
  18. modern_di-0.5.0/integrations/fastapi/modern_di_fastapi/main.py +0 -47
  19. modern_di-0.5.0/integrations/fastapi/pyproject.toml +0 -87
  20. modern_di-0.5.0/integrations/fastapi/tests/__init__.py +0 -0
  21. modern_di-0.5.0/integrations/fastapi/tests/conftest.py +0 -28
  22. modern_di-0.5.0/integrations/fastapi/tests/dependencies.py +0 -17
  23. modern_di-0.5.0/integrations/fastapi/tests/test_routes.py +0 -57
  24. modern_di-0.5.0/integrations/fastapi/tests/test_websockets.py +0 -33
  25. modern_di-0.5.0/modern_di/py.typed +0 -0
  26. modern_di-0.5.0/pyproject.toml +0 -91
  27. modern_di-0.5.0/tests/__init__.py +0 -0
  28. modern_di-0.5.0/tests/creators.py +0 -22
  29. modern_di-0.5.0/tests/providers/__init__.py +0 -0
  30. modern_di-0.5.0/tests/providers/test_context_adapter.py +0 -30
  31. modern_di-0.5.0/tests/providers/test_dict.py +0 -24
  32. modern_di-0.5.0/tests/providers/test_factory.py +0 -93
  33. modern_di-0.5.0/tests/providers/test_list.py +0 -24
  34. modern_di-0.5.0/tests/providers/test_resource.py +0 -119
  35. modern_di-0.5.0/tests/providers/test_selector.py +0 -45
  36. modern_di-0.5.0/tests/providers/test_singleton.py +0 -115
  37. modern_di-0.5.0/tests/test_container.py +0 -46
  38. modern_di-0.5.0/tests/test_graph.py +0 -39
  39. {modern_di-0.5.0 → modern_di-0.5.1}/.gitignore +0 -0
  40. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/__init__.py +0 -0
  41. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/container.py +0 -0
  42. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/graph.py +0 -0
  43. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/provider_state.py +0 -0
  44. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/__init__.py +0 -0
  45. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/abstract.py +0 -0
  46. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/context_adapter.py +0 -0
  47. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/dict.py +0 -0
  48. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/factory.py +0 -0
  49. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/list.py +0 -0
  50. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/resource.py +0 -0
  51. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/selector.py +0 -0
  52. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/providers/singleton.py +0 -0
  53. {modern_di-0.5.0/integrations/fastapi/modern_di_fastapi → modern_di-0.5.1/modern_di}/py.typed +0 -0
  54. {modern_di-0.5.0 → modern_di-0.5.1}/modern_di/scope.py +0 -0
@@ -1,13 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: modern-di
3
- Version: 0.5.0
3
+ Version: 0.5.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
7
7
  Author-email: Artur Shiriev <me@shiriev.ru>
8
8
  License-Expression: MIT
9
- License-File: LICENSE
10
- Keywords: dependency injector,di,ioc-container,mocks,python
9
+ Keywords: DI,dependency injector,ioc-container,mocks,python
11
10
  Classifier: Programming Language :: Python :: 3.10
12
11
  Classifier: Programming Language :: Python :: 3.11
13
12
  Classifier: Programming Language :: Python :: 3.12
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "modern-di"
3
+ description = "Dependency Injection framework with IOC-container and scopes"
4
+ authors = [{ name = "Artur Shiriev", email = "me@shiriev.ru" }]
5
+ requires-python = ">=3.10,<4"
6
+ license = "MIT"
7
+ keywords = ["DI", "dependency injector", "ioc-container", "mocks", "python"]
8
+ classifiers = [
9
+ "Programming Language :: Python :: 3.10",
10
+ "Programming Language :: Python :: 3.11",
11
+ "Programming Language :: Python :: 3.12",
12
+ "Programming Language :: Python :: 3.13",
13
+ "Typing :: Typed",
14
+ "Topic :: Software Development :: Libraries",
15
+ ]
16
+ dynamic = ["version", "readme"]
17
+
18
+ [project.urls]
19
+ repository = "https://github.com/modern-python/modern-di"
20
+ docs = "https://modern-di.readthedocs.io"
21
+
22
+ [build-system]
23
+ requires = ["hatchling", "hatch-vcs", "hatch-fancy-pypi-readme"]
24
+ build-backend = "hatchling.build"
25
+
26
+ [tool.hatch.version]
27
+ source = "vcs"
28
+ raw-options.root = "../.."
29
+ fallback-version = "0"
30
+
31
+ [tool.hatch.build]
32
+ include = ["modern_di"]
33
+
34
+ [tool.hatch.metadata.hooks.fancy-pypi-readme]
35
+ content-type = "text/markdown"
36
+
37
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
38
+ path = "../../README.md"
39
+
40
+ [tool.pytest.ini_options]
41
+ addopts = "--cov=. --cov-report term-missing"
42
+ asyncio_mode = "auto"
43
+
44
+ [tool.coverage.report]
45
+ exclude_also = ["if typing.TYPE_CHECKING:"]
@@ -1,52 +0,0 @@
1
- name: core ci
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- paths:
8
- - 'modern_di/**'
9
- - 'tests/**'
10
- - '.github/workflows/core-ci.yml'
11
- pull_request:
12
- paths:
13
- - 'modern_di/**'
14
- - 'tests/**'
15
- - '.github/workflows/core-ci.yml'
16
-
17
- concurrency:
18
- group: ${{ github.head_ref || github.run_id }} core
19
- cancel-in-progress: true
20
-
21
- jobs:
22
- lint:
23
- runs-on: ubuntu-latest
24
- steps:
25
- - uses: actions/checkout@v4
26
- - uses: extractions/setup-just@v2
27
- - uses: astral-sh/setup-uv@v3
28
- with:
29
- enable-cache: true
30
- cache-dependency-glob: "pyproject.toml"
31
- - run: uv python install 3.10
32
- - run: just install lint-ci
33
-
34
- pytest:
35
- runs-on: ubuntu-latest
36
- strategy:
37
- fail-fast: false
38
- matrix:
39
- python-version:
40
- - "3.10"
41
- - "3.11"
42
- - "3.12"
43
- - "3.13"
44
- steps:
45
- - uses: actions/checkout@v4
46
- - uses: extractions/setup-just@v2
47
- - uses: astral-sh/setup-uv@v3
48
- with:
49
- enable-cache: true
50
- cache-dependency-glob: "pyproject.toml"
51
- - run: uv python install ${{ matrix.python-version }}
52
- - run: just install test . --cov=. --cov-report xml
@@ -1,54 +0,0 @@
1
- name: fastapi ci
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- paths:
8
- - 'integrations/fastapi/**'
9
- - '.github/workflows/fastapi-ci.yml'
10
- pull_request:
11
- paths:
12
- - 'integrations/fastapi/**'
13
- - '.github/workflows/fastapi-ci.yml'
14
-
15
- defaults:
16
- run:
17
- working-directory: integrations/fastapi
18
-
19
- concurrency:
20
- group: ${{ github.head_ref || github.run_id }} fastapi
21
- cancel-in-progress: false
22
-
23
- jobs:
24
- lint:
25
- runs-on: ubuntu-latest
26
- steps:
27
- - uses: actions/checkout@v4
28
- - uses: extractions/setup-just@v2
29
- - uses: astral-sh/setup-uv@v3
30
- with:
31
- enable-cache: true
32
- cache-dependency-glob: "pyproject.toml"
33
- - run: uv python install 3.10
34
- - run: just install lint-ci
35
-
36
- pytest:
37
- runs-on: ubuntu-latest
38
- strategy:
39
- fail-fast: false
40
- matrix:
41
- python-version:
42
- - "3.10"
43
- - "3.11"
44
- - "3.12"
45
- - "3.13"
46
- steps:
47
- - uses: actions/checkout@v4
48
- - uses: extractions/setup-just@v2
49
- - uses: astral-sh/setup-uv@v3
50
- with:
51
- enable-cache: true
52
- cache-dependency-glob: "pyproject.toml"
53
- - run: uv python install ${{ matrix.python-version }}
54
- - run: just install test . --cov=. --cov-report xml
@@ -1,30 +0,0 @@
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
-
19
- - if: startsWith(github.ref_name, 'core')
20
- run: just publish modern-di
21
- env:
22
- PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
23
-
24
- - if: startsWith(github.ref_name, 'fastapi')
25
- run: |
26
- export SETUPTOOLS_SCM_PRETEND_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^fastapi-//; s/-.*$//')
27
- echo "SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION"
28
- just publish modern-di-fastapi
29
- env:
30
- PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -1,13 +0,0 @@
1
- version: 2
2
-
3
- build:
4
- os: "ubuntu-22.04"
5
- tools:
6
- python: "3.10"
7
-
8
- python:
9
- install:
10
- - requirements: docs/requirements.txt
11
-
12
- sphinx:
13
- configuration: docs/conf.py
modern_di-0.5.0/Justfile DELETED
@@ -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 tests {{ args }}
19
-
20
- publish package:
21
- rm -rf dist
22
- uv build --package {{package}}
23
- uv publish --token $PYPI_TOKEN
modern_di-0.5.0/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 modern-python
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
modern_di-0.5.0/README.md DELETED
@@ -1,20 +0,0 @@
1
- "Modern-DI"
2
- ==
3
-
4
- | Project | Badges |
5
- |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
6
- | common | [![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration) [![GitHub stars](https://img.shields.io/github/stars/modern-python/modern-di)](https://github.com/modern-python/modern-di/stargazers) |
7
- | modern-di | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di.svg)](https://pypi.python.org/pypi/modern-di ) [![downloads](https://img.shields.io/pypi/dm/modern-di.svg)](https://pypistats.org/packages/modern-di) |
8
- | modern-di-fastapi | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-fastapi.svg)](https://pypi.python.org/pypi/modern-di-fastapi) [![downloads](https://img.shields.io/pypi/dm/modern-di-fastapi.svg)](https://pypistats.org/packages/modern-di-fastapi) |
9
-
10
- Dependency injection framework for Python inspired by `dependency-injector` and `dishka`.
11
-
12
- It is in early development state and gives you the following:
13
- - DI framework with IOC-container and scopes.
14
- - Async and sync resolving.
15
- - Python 3.10-3.13 support.
16
- - Full coverage by types annotations (mypy in strict mode).
17
- - Overriding dependencies for tests.
18
- - Package with zero dependencies.
19
-
20
- 📚 [Documentation](https://modern-di.readthedocs.io)
@@ -1,34 +0,0 @@
1
- # Configuration file for the Sphinx documentation builder.
2
-
3
- # -- Project information
4
- project = "modern-di"
5
- copyright = "2024, Modern Python"
6
- author = "Modern Python Community"
7
-
8
- release = ""
9
- version = ""
10
-
11
- # -- General configuration
12
- extensions = [
13
- "sphinx_copybutton",
14
- "sphinx.ext.duration",
15
- "sphinx.ext.doctest",
16
- "sphinx.ext.autodoc",
17
- "sphinx.ext.autosummary",
18
- "sphinx.ext.intersphinx",
19
- "myst_parser",
20
- ]
21
-
22
- intersphinx_mapping = {
23
- "python": ("https://docs.python.org/3/", None),
24
- "sphinx": ("https://www.sphinx-doc.org/en/master/", None),
25
- }
26
- intersphinx_disabled_domains = ["std"]
27
-
28
- templates_path = ["_templates"]
29
-
30
- # -- Options for HTML output
31
- html_theme = "sphinx_rtd_theme"
32
-
33
- # -- Options for EPUB output
34
- epub_show_urls = "footnote"
@@ -1,19 +0,0 @@
1
- # Contributing
2
- This is an opensource project, and we are opened to new contributors.
3
-
4
- ## Getting started
5
- 1. Make sure that you have [uv](https://docs.astral.sh/uv/) and [just](https://just.systems/) installed.
6
- 2. Clone project:
7
- ```
8
- git@github.com:modern-python/modern-di.git
9
- cd modern-di
10
- ```
11
- 3. Install dependencies running `just install`
12
-
13
- ## Running linters
14
- `Ruff` and `mypy` are used for static analysis.
15
-
16
- Run all checks by command `just lint`
17
-
18
- ## Running tests
19
- Run all tests by command `just test`
@@ -1,25 +0,0 @@
1
- # Development Notes
2
- ## Base parts
3
- ### Scope
4
- - any int enum, starting from 1 with step 1
5
-
6
- ### Container
7
- - all states live in containers:
8
- - resolved dependencies
9
- - context stacks for resources
10
- - overrides
11
-
12
- ### Providers
13
- - completely stateless
14
- - if dependency is already saved or overridden in `Container`, returns it
15
- - otherwise build dependency and save it to `Container`
16
- - can have dependencies only the same or lower scope, check in init
17
-
18
- ### Graph
19
- - Cannot be instantiated
20
- - Contains graph of `Providers`
21
- - Can initialize its resources and factories to container
22
-
23
- ### Questions
24
- 1. Thread-safety
25
- 2. Configuration without global object
@@ -1,11 +0,0 @@
1
- ```{include} ../README.md
2
- ```
3
-
4
- ```{eval-rst}
5
- .. toctree::
6
- :maxdepth: 1
7
- :caption: For developers
8
-
9
- dev/development-notes
10
- dev/contributing
11
- ```
@@ -1,4 +0,0 @@
1
- sphinx==7.*
2
- sphinx-rtd-theme==2.*
3
- myst-parser
4
- sphinx-copybutton
@@ -1,18 +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 }}
@@ -1,6 +0,0 @@
1
- "Modern-DI-FastAPI"
2
- ==
3
-
4
- Integration of [Modern-DI](https://github.com/modern-python/modern-di) to FastAPI
5
-
6
- 📚 [Documentation](https://modern-di.readthedocs.io)
@@ -1,9 +0,0 @@
1
- from modern_di_fastapi.main import Provide, build_request_container, fetch_di_container, setup_di
2
-
3
-
4
- __all__ = [
5
- "Provide",
6
- "build_request_container",
7
- "fetch_di_container",
8
- "setup_di",
9
- ]
@@ -1,47 +0,0 @@
1
- import dataclasses
2
- import enum
3
- import typing
4
-
5
- import fastapi
6
- from modern_di import Container, Scope, providers
7
- from starlette.requests import HTTPConnection
8
-
9
-
10
- T_co = typing.TypeVar("T_co", covariant=True)
11
-
12
-
13
- def setup_di(app: fastapi.FastAPI, scope: enum.IntEnum = Scope.APP) -> Container:
14
- app.state.di_container = Container(scope=scope)
15
- return app.state.di_container
16
-
17
-
18
- def fetch_di_container(app: fastapi.FastAPI) -> Container:
19
- return typing.cast(Container, app.state.di_container)
20
-
21
-
22
- async def build_request_container(connection: HTTPConnection) -> typing.AsyncIterator[Container]:
23
- context: dict[str, typing.Any] = {}
24
- scope: Scope | None = None
25
- if isinstance(connection, fastapi.Request):
26
- scope = Scope.REQUEST
27
- context["request"] = connection
28
- elif isinstance(connection, fastapi.WebSocket):
29
- context["websocket"] = connection
30
- scope = Scope.SESSION
31
- container: Container = fetch_di_container(connection.app)
32
- async with container.build_child_container(context=context, scope=scope) as request_container:
33
- yield request_container
34
-
35
-
36
- @dataclasses.dataclass(slots=True, frozen=True)
37
- class Dependency(typing.Generic[T_co]):
38
- dependency: providers.AbstractProvider[T_co]
39
-
40
- async def __call__(
41
- self, request_container: typing.Annotated[Container, fastapi.Depends(build_request_container)]
42
- ) -> T_co:
43
- return await self.dependency.async_resolve(request_container)
44
-
45
-
46
- def Provide(dependency: providers.AbstractProvider[T_co], *, use_cache: bool = True) -> T_co: # noqa: N802
47
- return typing.cast(T_co, fastapi.Depends(dependency=Dependency(dependency), use_cache=use_cache))
@@ -1,87 +0,0 @@
1
- [project]
2
- name = "modern-di-fastapi"
3
- description = "Modern-DI integration for FastAPI"
4
- authors = [
5
- { name = "Artur Shiriev", email = "me@shiriev.ru" },
6
- ]
7
- readme = "README.md"
8
- requires-python = ">=3.10,<4"
9
- license = "MIT"
10
- keywords = ["DI", "dependency injector", "ioc-container", "FastAPI", "python"]
11
- classifiers = [
12
- "Programming Language :: Python :: 3.10",
13
- "Programming Language :: Python :: 3.11",
14
- "Programming Language :: Python :: 3.12",
15
- "Programming Language :: Python :: 3.13",
16
- "Typing :: Typed",
17
- "Topic :: Software Development :: Libraries",
18
- ]
19
- packages = [
20
- { include = "modern_di_fastapi" },
21
- ]
22
- dynamic = ["version"]
23
- dependencies = [
24
- "fastapi>=0.100",
25
- "modern-di",
26
- ]
27
-
28
- [project.urls]
29
- repository = "https://github.com/modern-python/modern-di"
30
- docs = "https://modern-di.readthedocs.io"
31
-
32
- [dependency-groups]
33
- dev = [
34
- "httpx",
35
- "pytest",
36
- "pytest-cov",
37
- "pytest-asyncio",
38
- "ruff",
39
- "mypy",
40
- "typing-extensions",
41
- "asgi-lifespan",
42
- ]
43
-
44
- [build-system]
45
- requires = ["hatchling", "hatch-vcs"]
46
- build-backend = "hatchling.build"
47
-
48
- [tool.hatch.version]
49
- source = "vcs"
50
- fallback-version = "0"
51
-
52
- [tool.mypy]
53
- python_version = "3.10"
54
- strict = true
55
-
56
- [tool.ruff]
57
- fix = true
58
- unsafe-fixes = true
59
- line-length = 120
60
- target-version = "py310"
61
- extend-exclude = [
62
- "docs",
63
- ]
64
-
65
- [tool.ruff.lint]
66
- select = ["ALL"]
67
- ignore = [
68
- "D1", # allow missing docstrings
69
- "S101", # allow asserts
70
- "TCH", # ignore flake8-type-checking
71
- "FBT", # allow boolean args
72
- "ANN101", # missing-type-self
73
- "ANN102", # missing-type-cls
74
- "D203", # "one-blank-line-before-class" conflicting with D211
75
- "D213", # "multi-line-summary-second-line" conflicting with D212
76
- "COM812", # flake8-commas "Trailing comma missing"
77
- "ISC001", # flake8-implicit-str-concat
78
- ]
79
- isort.lines-after-imports = 2
80
- isort.no-lines-before = ["standard-library", "local-folder"]
81
-
82
- [tool.pytest.ini_options]
83
- addopts = "--cov=. --cov-report term-missing"
84
- asyncio_mode = "auto"
85
-
86
- [tool.coverage.report]
87
- exclude_also = ["if typing.TYPE_CHECKING:"]
File without changes
@@ -1,28 +0,0 @@
1
- import contextlib
2
- import typing
3
-
4
- import fastapi
5
- import pytest
6
- from asgi_lifespan import LifespanManager
7
- from starlette.testclient import TestClient
8
-
9
- from modern_di_fastapi import setup_di
10
-
11
-
12
- @contextlib.asynccontextmanager
13
- async def lifespan(app_: fastapi.FastAPI) -> typing.AsyncIterator[None]:
14
- container = setup_di(app_)
15
- async with container:
16
- yield
17
-
18
-
19
- @pytest.fixture
20
- async def app() -> typing.AsyncIterator[fastapi.FastAPI]:
21
- app_ = fastapi.FastAPI(lifespan=lifespan)
22
- async with LifespanManager(app_):
23
- yield app_
24
-
25
-
26
- @pytest.fixture
27
- def client(app: fastapi.FastAPI) -> TestClient:
28
- return TestClient(app=app)
@@ -1,17 +0,0 @@
1
- import dataclasses
2
-
3
- import fastapi
4
-
5
-
6
- @dataclasses.dataclass(kw_only=True, slots=True)
7
- class SimpleCreator:
8
- dep1: str
9
-
10
-
11
- @dataclasses.dataclass(kw_only=True, slots=True)
12
- class DependentCreator:
13
- dep1: SimpleCreator
14
-
15
-
16
- def context_adapter_function(*, request: fastapi.Request, **_: object) -> str:
17
- return request.method
@@ -1,57 +0,0 @@
1
- import typing
2
-
3
- import fastapi
4
- import modern_di
5
- from modern_di import Scope, providers
6
- from starlette import status
7
- from starlette.testclient import TestClient
8
-
9
- from modern_di_fastapi import Provide, build_request_container
10
- from tests.dependencies import DependentCreator, SimpleCreator, context_adapter_function
11
-
12
-
13
- app_factory = providers.Factory(Scope.APP, SimpleCreator, dep1="original")
14
- request_factory = providers.Factory(Scope.REQUEST, DependentCreator, dep1=app_factory.cast)
15
- action_factory = providers.Factory(Scope.ACTION, DependentCreator, dep1=app_factory.cast)
16
- context_adapter = providers.ContextAdapter(Scope.REQUEST, context_adapter_function)
17
-
18
-
19
- def test_factories(client: TestClient, app: fastapi.FastAPI) -> None:
20
- @app.get("/")
21
- async def read_root(
22
- app_factory_instance: typing.Annotated[SimpleCreator, Provide(app_factory)],
23
- request_factory_instance: typing.Annotated[DependentCreator, Provide(request_factory)],
24
- ) -> None:
25
- assert isinstance(app_factory_instance, SimpleCreator)
26
- assert isinstance(request_factory_instance, DependentCreator)
27
- assert request_factory_instance.dep1 is not app_factory_instance
28
-
29
- response = client.get("/")
30
- assert response.status_code == status.HTTP_200_OK
31
- assert response.json() is None
32
-
33
-
34
- def test_context_adapter(client: TestClient, app: fastapi.FastAPI) -> None:
35
- @app.get("/")
36
- async def read_root(
37
- method: typing.Annotated[str, Provide(context_adapter)],
38
- ) -> None:
39
- assert method == "GET"
40
-
41
- response = client.get("/")
42
- assert response.status_code == status.HTTP_200_OK
43
- assert response.json() is None
44
-
45
-
46
- def test_factories_action_scope(client: TestClient, app: fastapi.FastAPI) -> None:
47
- @app.get("/")
48
- async def read_root(
49
- request_container: typing.Annotated[modern_di.Container, fastapi.Depends(build_request_container)],
50
- ) -> None:
51
- with request_container.build_child_container() as action_container:
52
- action_factory_instance = action_factory.sync_resolve(action_container)
53
- assert isinstance(action_factory_instance, DependentCreator)
54
-
55
- response = client.get("/")
56
- assert response.status_code == status.HTTP_200_OK
57
- assert response.json() is None