Skip to content

Commit 704e36a

Browse files
committed
Merge branch 'release/4.44.0' into master
2 parents abf2a25 + 83d71ac commit 704e36a

File tree

25 files changed

+403
-269022
lines changed

25 files changed

+403
-269022
lines changed

.coveragerc

-10
This file was deleted.

.github/workflows/tests-and-linters.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ jobs:
3636
env:
3737
TOXENV: ${{ matrix.python-version }}
3838

39+
test-different-pydantic-versions:
40+
name: Run tests with different pydantic versions
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v3
44+
- uses: actions/setup-python@v4
45+
with:
46+
python-version: "3.12"
47+
- run: pip install tox
48+
- run: tox -e pydantic-v1,pydantic-v2
49+
3950
test-coverage:
4051
name: Run tests with coverage
4152
runs-on: ubuntu-latest
@@ -50,7 +61,6 @@ jobs:
5061
with:
5162
python-version: 3.12
5263
- run: pip install tox 'cython>=3,<4'
53-
- run: make cythonize
5464
- run: tox -vv
5565
env:
5666
TOXENV: coveralls

.gitignore

+5-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ venv*/
6363
# Vim Rope
6464
.ropeproject/
6565

66-
# C extensions
67-
src/dependency_injector/*.h
68-
src/dependency_injector/*.so
69-
src/dependency_injector/containers/*.h
70-
src/dependency_injector/containers/*.so
71-
src/dependency_injector/providers/*.h
72-
src/dependency_injector/providers/*.so
66+
# Cython artifacts
67+
src/**/*.c
68+
src/**/*.h
69+
src/**/*.so
70+
src/**/*.html
7371

7472
# Workspace for samples
7573
.workspace/

.pylintrc

-49
This file was deleted.

Makefile

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
VERSION := $(shell python setup.py --version)
22

3-
CYTHON_SRC := $(shell find src/dependency_injector -name '*.pyx')
4-
5-
CYTHON_DIRECTIVES = -Xlanguage_level=3
6-
7-
ifdef DEPENDENCY_INJECTOR_DEBUG_MODE
8-
CYTHON_DIRECTIVES += -Xprofile=True
9-
CYTHON_DIRECTIVES += -Xlinetrace=True
10-
endif
11-
3+
export COVERAGE_RCFILE := pyproject.toml
124

135
clean:
146
# Clean sources
@@ -25,21 +17,17 @@ clean:
2517
find examples -name '*.py[co]' -delete
2618
find examples -name '__pycache__' -delete
2719

28-
cythonize:
29-
# Compile Cython to C
30-
cython -a $(CYTHON_DIRECTIVES) $(CYTHON_SRC)
20+
build: clean
21+
# Compile C extensions
22+
python setup.py build_ext --inplace
3123
# Move all Cython html reports
3224
mkdir -p reports/cython/
3325
find src -name '*.html' -exec mv {} reports/cython/ \;
3426

35-
build: clean cythonize
36-
# Compile C extensions
37-
python setup.py build_ext --inplace
38-
3927
docs-live:
4028
sphinx-autobuild docs docs/_build/html
4129

42-
install: uninstall clean cythonize
30+
install: uninstall clean build
4331
pip install -ve .
4432

4533
uninstall:
@@ -48,9 +36,9 @@ uninstall:
4836
test:
4937
# Unit tests with coverage report
5038
coverage erase
51-
coverage run --rcfile=./.coveragerc -m pytest -c tests/.configs/pytest.ini
52-
coverage report --rcfile=./.coveragerc
53-
coverage html --rcfile=./.coveragerc
39+
coverage run -m pytest -c tests/.configs/pytest.ini
40+
coverage report
41+
coverage html
5442

5543
check:
5644
flake8 src/dependency_injector/
@@ -61,9 +49,9 @@ check:
6149

6250
mypy tests/typing
6351

64-
test-publish: cythonize
52+
test-publish: build
6553
# Create distributions
66-
python setup.py sdist
54+
python -m build --sdist
6755
# Upload distributions to PyPI
6856
twine upload --repository testpypi dist/dependency-injector-$(VERSION)*
6957

docs/main/changelog.rst

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ that were made in every particular version.
77
From version 0.7.6 *Dependency Injector* framework strictly
88
follows `Semantic versioning`_
99

10+
4.44.0
11+
--------
12+
- Implement support for Pydantic 2. PR: `#832 <https://github.com/ets-labs/python-dependency-injector/pull/832>`_.
13+
- Implement `PEP-517 <https://peps.python.org/pep-0517/>`_, `PEP-518 <https://peps.python.org/pep-0518/>`_, and
14+
`PEP-621 <https://peps.python.org/pep-0621/>`_. PR: `#829 <https://github.com/ets-labs/python-dependency-injector/pull/829>`_.
15+
16+
Many thanks to `ZipFile <https://github.com/ZipFile>`_ for both contributions.
17+
1018
4.43.0
1119
--------
1220
- Add support for Python 3.13.

docs/providers/configuration.rst

+13-8
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,22 @@ See also: :ref:`configuration-envs-interpolation`.
183183
Loading from a Pydantic settings
184184
--------------------------------
185185

186-
``Configuration`` provider can load configuration from a ``pydantic`` settings object using the
186+
``Configuration`` provider can load configuration from a ``pydantic_settings.BaseSettings`` object using the
187187
:py:meth:`Configuration.from_pydantic` method:
188188

189189
.. literalinclude:: ../../examples/providers/configuration/configuration_pydantic.py
190190
:language: python
191191
:lines: 3-
192-
:emphasize-lines: 31
192+
:emphasize-lines: 32
193193

194-
To get the data from pydantic settings ``Configuration`` provider calls ``Settings.dict()`` method.
194+
To get the data from pydantic settings ``Configuration`` provider calls its ``model_dump()`` method.
195195
If you need to pass an argument to this call, use ``.from_pydantic()`` keyword arguments.
196196

197197
.. code-block:: python
198198
199199
container.config.from_pydantic(Settings(), exclude={"optional"})
200200
201-
Alternatively, you can provide a ``pydantic`` settings object over the configuration provider argument. In that case,
201+
Alternatively, you can provide a ``pydantic_settings.BaseSettings`` object over the configuration provider argument. In that case,
202202
the container will call ``config.from_pydantic()`` automatically:
203203

204204
.. code-block:: python
@@ -215,18 +215,23 @@ the container will call ``config.from_pydantic()`` automatically:
215215
216216
.. note::
217217

218-
``Dependency Injector`` doesn't install ``pydantic`` by default.
218+
``Dependency Injector`` doesn't install ``pydantic-settings`` by default.
219219

220220
You can install the ``Dependency Injector`` with an extra dependency::
221221

222-
pip install dependency-injector[pydantic]
222+
pip install dependency-injector[pydantic2]
223223

224-
or install ``pydantic`` directly::
224+
or install ``pydantic-settings`` directly::
225225

226-
pip install pydantic
226+
pip install pydantic-settings
227227

228228
*Don't forget to mirror the changes in the requirements file.*
229229

230+
.. note::
231+
232+
For backward-compatibility, Pydantic v1 is still supported.
233+
Passing ``pydantic.BaseSettings`` instances will work just as fine as ``pydantic_settings.BaseSettings``.
234+
230235
Loading from a dictionary
231236
-------------------------
232237

examples/miniapps/fastapi-redis/fastapiredis/tests.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from unittest import mock
44

55
import pytest
6-
from httpx import AsyncClient
6+
from httpx import ASGITransport, AsyncClient
77

88
from .application import app, container
99
from .services import Service
1010

1111

1212
@pytest.fixture
1313
def client(event_loop):
14-
client = AsyncClient(app=app, base_url="http://test")
14+
client = AsyncClient(
15+
transport=ASGITransport(app=app),
16+
base_url="http://test",
17+
)
1518
yield client
1619
event_loop.run_until_complete(client.aclose())
1720

examples/miniapps/fastapi-simple/tests.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from unittest import mock
22

33
import pytest
4-
from httpx import AsyncClient
4+
from httpx import ASGITransport, AsyncClient
55

66
from fastapi_di_example import app, container, Service
77

88

99
@pytest.fixture
1010
async def client(event_loop):
11-
async with AsyncClient(app=app, base_url="http://test") as client:
11+
async with AsyncClient(
12+
transport=ASGITransport(app=app),
13+
base_url="http://test",
14+
) as client:
1215
yield client
1316

1417

examples/miniapps/fastapi/giphynavigator/tests.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from unittest import mock
44

55
import pytest
6-
from httpx import AsyncClient
6+
from httpx import ASGITransport, AsyncClient
77

88
from giphynavigator.application import app
99
from giphynavigator.giphy import GiphyClient
1010

1111

1212
@pytest.fixture
1313
async def client():
14-
async with AsyncClient(app=app, base_url="http://test") as client:
14+
async with AsyncClient(
15+
transport=ASGITransport(app=app),
16+
base_url="http://test",
17+
) as client:
1518
yield client
1619

1720

examples/providers/configuration/configuration_pydantic.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
import os
44

55
from dependency_injector import containers, providers
6-
from pydantic import BaseSettings, Field
6+
from pydantic_settings import BaseSettings, SettingsConfigDict
77

88
# Emulate environment variables
99
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
1010
os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET"
1111

1212

1313
class AwsSettings(BaseSettings):
14+
model_config = SettingsConfigDict(env_prefix="aws_")
1415

15-
access_key_id: str = Field(env="aws_access_key_id")
16-
secret_access_key: str = Field(env="aws_secret_access_key")
16+
access_key_id: str
17+
secret_access_key: str
1718

1819

1920
class Settings(BaseSettings):
2021

2122
aws: AwsSettings = AwsSettings()
22-
optional: str = Field(default="default_value")
23+
optional: str = "default_value"
2324

2425

2526
class Container(containers.DeclarativeContainer):

examples/providers/configuration/configuration_pydantic_init.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
import os
44

55
from dependency_injector import containers, providers
6-
from pydantic import BaseSettings, Field
6+
from pydantic_settings import BaseSettings, SettingsConfigDict
77

88
# Emulate environment variables
99
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
1010
os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET"
1111

1212

1313
class AwsSettings(BaseSettings):
14+
model_config = SettingsConfigDict(env_prefix="aws_")
1415

15-
access_key_id: str = Field(env="aws_access_key_id")
16-
secret_access_key: str = Field(env="aws_secret_access_key")
16+
access_key_id: str
17+
secret_access_key: str
1718

1819

1920
class Settings(BaseSettings):
2021

2122
aws: AwsSettings = AwsSettings()
22-
optional: str = Field(default="default_value")
23+
optional: str = "default_value"
2324

2425

2526
class Container(containers.DeclarativeContainer):

0 commit comments

Comments
 (0)