Skip to content

Commit

Permalink
Merge branch 'release/4.44.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Dec 7, 2024
2 parents abf2a25 + 83d71ac commit 704e36a
Show file tree
Hide file tree
Showing 25 changed files with 403 additions and 269,022 deletions.
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

12 changes: 11 additions & 1 deletion .github/workflows/tests-and-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ jobs:
env:
TOXENV: ${{ matrix.python-version }}

test-different-pydantic-versions:
name: Run tests with different pydantic versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- run: pip install tox
- run: tox -e pydantic-v1,pydantic-v2

test-coverage:
name: Run tests with coverage
runs-on: ubuntu-latest
Expand All @@ -50,7 +61,6 @@ jobs:
with:
python-version: 3.12
- run: pip install tox 'cython>=3,<4'
- run: make cythonize
- run: tox -vv
env:
TOXENV: coveralls
Expand Down
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ venv*/
# Vim Rope
.ropeproject/

# C extensions
src/dependency_injector/*.h
src/dependency_injector/*.so
src/dependency_injector/containers/*.h
src/dependency_injector/containers/*.so
src/dependency_injector/providers/*.h
src/dependency_injector/providers/*.so
# Cython artifacts
src/**/*.c
src/**/*.h
src/**/*.so
src/**/*.html

# Workspace for samples
.workspace/
Expand Down
49 changes: 0 additions & 49 deletions .pylintrc

This file was deleted.

32 changes: 10 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
VERSION := $(shell python setup.py --version)

CYTHON_SRC := $(shell find src/dependency_injector -name '*.pyx')

CYTHON_DIRECTIVES = -Xlanguage_level=3

ifdef DEPENDENCY_INJECTOR_DEBUG_MODE
CYTHON_DIRECTIVES += -Xprofile=True
CYTHON_DIRECTIVES += -Xlinetrace=True
endif

export COVERAGE_RCFILE := pyproject.toml

clean:
# Clean sources
Expand All @@ -25,21 +17,17 @@ clean:
find examples -name '*.py[co]' -delete
find examples -name '__pycache__' -delete

cythonize:
# Compile Cython to C
cython -a $(CYTHON_DIRECTIVES) $(CYTHON_SRC)
build: clean
# Compile C extensions
python setup.py build_ext --inplace
# Move all Cython html reports
mkdir -p reports/cython/
find src -name '*.html' -exec mv {} reports/cython/ \;

build: clean cythonize
# Compile C extensions
python setup.py build_ext --inplace

docs-live:
sphinx-autobuild docs docs/_build/html

install: uninstall clean cythonize
install: uninstall clean build
pip install -ve .

uninstall:
Expand All @@ -48,9 +36,9 @@ uninstall:
test:
# Unit tests with coverage report
coverage erase
coverage run --rcfile=./.coveragerc -m pytest -c tests/.configs/pytest.ini
coverage report --rcfile=./.coveragerc
coverage html --rcfile=./.coveragerc
coverage run -m pytest -c tests/.configs/pytest.ini
coverage report
coverage html

check:
flake8 src/dependency_injector/
Expand All @@ -61,9 +49,9 @@ check:

mypy tests/typing

test-publish: cythonize
test-publish: build
# Create distributions
python setup.py sdist
python -m build --sdist
# Upload distributions to PyPI
twine upload --repository testpypi dist/dependency-injector-$(VERSION)*

Expand Down
8 changes: 8 additions & 0 deletions docs/main/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_

4.44.0
--------
- Implement support for Pydantic 2. PR: `#832 <https://github.com/ets-labs/python-dependency-injector/pull/832>`_.
- Implement `PEP-517 <https://peps.python.org/pep-0517/>`_, `PEP-518 <https://peps.python.org/pep-0518/>`_, and
`PEP-621 <https://peps.python.org/pep-0621/>`_. PR: `#829 <https://github.com/ets-labs/python-dependency-injector/pull/829>`_.

Many thanks to `ZipFile <https://github.com/ZipFile>`_ for both contributions.

4.43.0
--------
- Add support for Python 3.13.
Expand Down
21 changes: 13 additions & 8 deletions docs/providers/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ See also: :ref:`configuration-envs-interpolation`.
Loading from a Pydantic settings
--------------------------------

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

.. literalinclude:: ../../examples/providers/configuration/configuration_pydantic.py
:language: python
:lines: 3-
:emphasize-lines: 31
:emphasize-lines: 32

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

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

.. code-block:: python
Expand All @@ -215,18 +215,23 @@ the container will call ``config.from_pydantic()`` automatically:
.. note::

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

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

pip install dependency-injector[pydantic]
pip install dependency-injector[pydantic2]

or install ``pydantic`` directly::
or install ``pydantic-settings`` directly::

pip install pydantic
pip install pydantic-settings

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

.. note::

For backward-compatibility, Pydantic v1 is still supported.
Passing ``pydantic.BaseSettings`` instances will work just as fine as ``pydantic_settings.BaseSettings``.

Loading from a dictionary
-------------------------

Expand Down
7 changes: 5 additions & 2 deletions examples/miniapps/fastapi-redis/fastapiredis/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
from unittest import mock

import pytest
from httpx import AsyncClient
from httpx import ASGITransport, AsyncClient

from .application import app, container
from .services import Service


@pytest.fixture
def client(event_loop):
client = AsyncClient(app=app, base_url="http://test")
client = AsyncClient(
transport=ASGITransport(app=app),
base_url="http://test",
)
yield client
event_loop.run_until_complete(client.aclose())

Expand Down
7 changes: 5 additions & 2 deletions examples/miniapps/fastapi-simple/tests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from unittest import mock

import pytest
from httpx import AsyncClient
from httpx import ASGITransport, AsyncClient

from fastapi_di_example import app, container, Service


@pytest.fixture
async def client(event_loop):
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(
transport=ASGITransport(app=app),
base_url="http://test",
) as client:
yield client


Expand Down
7 changes: 5 additions & 2 deletions examples/miniapps/fastapi/giphynavigator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
from unittest import mock

import pytest
from httpx import AsyncClient
from httpx import ASGITransport, AsyncClient

from giphynavigator.application import app
from giphynavigator.giphy import GiphyClient


@pytest.fixture
async def client():
async with AsyncClient(app=app, base_url="http://test") as client:
async with AsyncClient(
transport=ASGITransport(app=app),
base_url="http://test",
) as client:
yield client


Expand Down
9 changes: 5 additions & 4 deletions examples/providers/configuration/configuration_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
import os

from dependency_injector import containers, providers
from pydantic import BaseSettings, Field
from pydantic_settings import BaseSettings, SettingsConfigDict

# Emulate environment variables
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET"


class AwsSettings(BaseSettings):
model_config = SettingsConfigDict(env_prefix="aws_")

access_key_id: str = Field(env="aws_access_key_id")
secret_access_key: str = Field(env="aws_secret_access_key")
access_key_id: str
secret_access_key: str


class Settings(BaseSettings):

aws: AwsSettings = AwsSettings()
optional: str = Field(default="default_value")
optional: str = "default_value"


class Container(containers.DeclarativeContainer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
import os

from dependency_injector import containers, providers
from pydantic import BaseSettings, Field
from pydantic_settings import BaseSettings, SettingsConfigDict

# Emulate environment variables
os.environ["AWS_ACCESS_KEY_ID"] = "KEY"
os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET"


class AwsSettings(BaseSettings):
model_config = SettingsConfigDict(env_prefix="aws_")

access_key_id: str = Field(env="aws_access_key_id")
secret_access_key: str = Field(env="aws_secret_access_key")
access_key_id: str
secret_access_key: str


class Settings(BaseSettings):

aws: AwsSettings = AwsSettings()
optional: str = Field(default="default_value")
optional: str = "default_value"


class Container(containers.DeclarativeContainer):
Expand Down
Loading

0 comments on commit 704e36a

Please sign in to comment.