modern-di 0.4.3__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.
- {modern_di-0.4.3 → modern_di-0.5.1}/PKG-INFO +2 -3
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/container.py +18 -11
- modern_di-0.5.1/modern_di/scope.py +9 -0
- modern_di-0.5.1/pyproject.toml +45 -0
- modern_di-0.4.3/.github/workflows/core-ci.yml +0 -52
- modern_di-0.4.3/.github/workflows/fastapi-ci.yml +0 -54
- modern_di-0.4.3/.github/workflows/publish.yml +0 -30
- modern_di-0.4.3/.readthedocs.yaml +0 -13
- modern_di-0.4.3/Justfile +0 -23
- modern_di-0.4.3/LICENSE +0 -21
- modern_di-0.4.3/README.md +0 -20
- modern_di-0.4.3/docs/conf.py +0 -34
- modern_di-0.4.3/docs/dev/contributing.md +0 -19
- modern_di-0.4.3/docs/dev/development-notes.md +0 -25
- modern_di-0.4.3/docs/index.md +0 -11
- modern_di-0.4.3/docs/requirements.txt +0 -4
- modern_di-0.4.3/integrations/fastapi/Justfile +0 -18
- modern_di-0.4.3/integrations/fastapi/README.md +0 -6
- modern_di-0.4.3/integrations/fastapi/modern_di_fastapi/__init__.py +0 -9
- modern_di-0.4.3/integrations/fastapi/modern_di_fastapi/main.py +0 -38
- modern_di-0.4.3/integrations/fastapi/pyproject.toml +0 -87
- modern_di-0.4.3/integrations/fastapi/tests/__init__.py +0 -0
- modern_di-0.4.3/integrations/fastapi/tests/conftest.py +0 -28
- modern_di-0.4.3/integrations/fastapi/tests/dependencies.py +0 -17
- modern_di-0.4.3/integrations/fastapi/tests/test_fastapi_di.py +0 -30
- modern_di-0.4.3/modern_di/py.typed +0 -0
- modern_di-0.4.3/modern_di/scope.py +0 -8
- modern_di-0.4.3/pyproject.toml +0 -91
- modern_di-0.4.3/tests/__init__.py +0 -0
- modern_di-0.4.3/tests/creators.py +0 -22
- modern_di-0.4.3/tests/providers/__init__.py +0 -0
- modern_di-0.4.3/tests/providers/test_context_adapter.py +0 -30
- modern_di-0.4.3/tests/providers/test_dict.py +0 -24
- modern_di-0.4.3/tests/providers/test_factory.py +0 -93
- modern_di-0.4.3/tests/providers/test_list.py +0 -24
- modern_di-0.4.3/tests/providers/test_resource.py +0 -119
- modern_di-0.4.3/tests/providers/test_selector.py +0 -45
- modern_di-0.4.3/tests/providers/test_singleton.py +0 -115
- modern_di-0.4.3/tests/test_container.py +0 -41
- modern_di-0.4.3/tests/test_graph.py +0 -39
- {modern_di-0.4.3 → modern_di-0.5.1}/.gitignore +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/__init__.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/graph.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/provider_state.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/__init__.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/abstract.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/context_adapter.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/dict.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/factory.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/list.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/resource.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/selector.py +0 -0
- {modern_di-0.4.3 → modern_di-0.5.1}/modern_di/providers/singleton.py +0 -0
- {modern_di-0.4.3/integrations/fastapi/modern_di_fastapi → modern_di-0.5.1/modern_di}/py.typed +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: modern-di
|
|
3
|
-
Version: 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
|
-
|
|
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
|
|
@@ -23,10 +23,6 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
|
|
|
23
23
|
parent_container: typing.Optional["Container"] = None,
|
|
24
24
|
context: dict[str, typing.Any] | None = None,
|
|
25
25
|
) -> None:
|
|
26
|
-
if scope.value != 1 and parent_container is None:
|
|
27
|
-
msg = "Only first scope can be used without parent_container"
|
|
28
|
-
raise RuntimeError(msg)
|
|
29
|
-
|
|
30
26
|
self.scope = scope
|
|
31
27
|
self.parent_container = parent_container
|
|
32
28
|
self.context: dict[str, typing.Any] = context or {}
|
|
@@ -45,16 +41,22 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
|
|
|
45
41
|
msg = "Enter the context first"
|
|
46
42
|
raise RuntimeError(msg)
|
|
47
43
|
|
|
48
|
-
def build_child_container(
|
|
44
|
+
def build_child_container(
|
|
45
|
+
self, context: dict[str, typing.Any] | None = None, scope: enum.IntEnum | None = None
|
|
46
|
+
) -> "typing_extensions.Self":
|
|
49
47
|
self._check_entered()
|
|
48
|
+
if scope and scope <= self.scope:
|
|
49
|
+
msg = "Scope of child container must be more than current scope"
|
|
50
|
+
raise RuntimeError(msg)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
if not scope:
|
|
53
|
+
try:
|
|
54
|
+
scope = self.scope.__class__(self.scope.value + 1)
|
|
55
|
+
except ValueError as exc:
|
|
56
|
+
msg = f"Max scope is reached, {self.scope.name}"
|
|
57
|
+
raise RuntimeError(msg) from exc
|
|
56
58
|
|
|
57
|
-
return self.__class__(scope=
|
|
59
|
+
return self.__class__(scope=scope, parent_container=self, context=context)
|
|
58
60
|
|
|
59
61
|
def find_container(self, scope: enum.IntEnum) -> "typing_extensions.Self":
|
|
60
62
|
container = self
|
|
@@ -64,6 +66,11 @@ class Container(contextlib.AbstractAsyncContextManager["Container"]):
|
|
|
64
66
|
|
|
65
67
|
while container.scope > scope and container.parent_container:
|
|
66
68
|
container = typing.cast("typing_extensions.Self", container.parent_container)
|
|
69
|
+
|
|
70
|
+
if container.scope != scope:
|
|
71
|
+
msg = f"Scope {scope.name} is skipped"
|
|
72
|
+
raise RuntimeError(msg)
|
|
73
|
+
|
|
67
74
|
return container
|
|
68
75
|
|
|
69
76
|
def fetch_provider_state(
|
|
@@ -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 }}
|
modern_di-0.4.3/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.4.3/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.4.3/README.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"Modern-DI"
|
|
2
|
-
==
|
|
3
|
-
|
|
4
|
-
| Project | Badges |
|
|
5
|
-
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
6
|
-
| common | [](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration) [](https://github.com/modern-python/modern-di/stargazers) |
|
|
7
|
-
| modern-di | [](https://pypi.python.org/pypi/modern-di ) [](https://pypistats.org/packages/modern-di) |
|
|
8
|
-
| modern-di-fastapi | [](https://pypi.python.org/pypi/modern-di-fastapi) [](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)
|
modern_di-0.4.3/docs/conf.py
DELETED
|
@@ -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
|
modern_di-0.4.3/docs/index.md
DELETED
|
@@ -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,38 +0,0 @@
|
|
|
1
|
-
import dataclasses
|
|
2
|
-
import enum
|
|
3
|
-
import typing
|
|
4
|
-
|
|
5
|
-
import fastapi
|
|
6
|
-
from modern_di import Container, Scope, providers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
T_co = typing.TypeVar("T_co", covariant=True)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def setup_di(app: fastapi.FastAPI, scope: enum.IntEnum = Scope.APP) -> Container:
|
|
13
|
-
app.state.di_container = Container(scope=scope)
|
|
14
|
-
return app.state.di_container
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def fetch_di_container(app: fastapi.FastAPI) -> Container:
|
|
18
|
-
return typing.cast(Container, app.state.di_container)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async def build_request_container(request: fastapi.Request) -> typing.AsyncIterator[Container]:
|
|
22
|
-
container: Container = fetch_di_container(request.app)
|
|
23
|
-
async with container.build_child_container(context={"request": request}) as request_container:
|
|
24
|
-
yield request_container
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclasses.dataclass(slots=True, frozen=True)
|
|
28
|
-
class Dependency(typing.Generic[T_co]):
|
|
29
|
-
dependency: providers.AbstractProvider[T_co]
|
|
30
|
-
|
|
31
|
-
async def __call__(
|
|
32
|
-
self, request_container: typing.Annotated[Container, fastapi.Depends(build_request_container)]
|
|
33
|
-
) -> T_co:
|
|
34
|
-
return await self.dependency.async_resolve(request_container)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def Provide(dependency: providers.AbstractProvider[T_co], *, use_cache: bool = True) -> T_co: # noqa: N802
|
|
38
|
-
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 httpx
|
|
6
|
-
import pytest
|
|
7
|
-
from asgi_lifespan import LifespanManager
|
|
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) -> httpx.AsyncClient:
|
|
28
|
-
return httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://test")
|
|
@@ -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
|