diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7575b9b..61b94fe 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -4,17 +4,33 @@ on: workflow_dispatch: pull_request: types: [assigned, opened, synchronize, reopened] + permissions: contents: write pull-requests: write + jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] django-version: ['3.2', '4.0', '4.1', '4.2', '5.0', '5.1'] - fail-fast: false + + exclude: + # Python 3.9 + - python-version: '3.9' + django-version: '5.0' + - python-version: '3.9' + django-version: '5.1' + + # Python 3.13 + - python-version: '3.13' + django-version: '3.2' + - python-version: '3.13' + django-version: '4.0' + steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} @@ -26,26 +42,13 @@ jobs: with: virtualenvs-create: true virtualenvs-in-project: true - - name: Determine Django compatibility - id: check-django - run: | - if [[ "${{ matrix.python-version }}" == "3.8" && "${{ matrix.django-version }}" > "4.1" ]]; then - echo "compatible=false" >> $GITHUB_OUTPUT - elif [[ "${{ matrix.python-version }}" == "3.9" && "${{ matrix.django-version }}" > "4.2" ]]; then - echo "compatible=false" >> $GITHUB_OUTPUT - elif [[ "${{ matrix.python-version }}" < "3.10" && "${{ matrix.django-version }}" == "5.0" ]]; then - echo "compatible=false" >> $GITHUB_OUTPUT - else - echo "compatible=true" >> $GITHUB_OUTPUT - fi - name: Install dependencies - if: steps.check-django.outputs.compatible == 'true' run: | - poetry install --sync --no-interaction --no-root + poetry install --sync --no-interaction --no-root poetry run pip install "django==${{ matrix.django-version }}.*" - name: Run tests - if: steps.check-django.outputs.compatible == 'true' run: poetry run pytest . + merge: runs-on: ubuntu-latest needs: [test] @@ -57,6 +60,7 @@ jobs: env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + release: runs-on: ubuntu-latest if: "startsWith(github.ref, 'refs/tags/')" @@ -70,7 +74,7 @@ jobs: virtualenvs-in-project: true - name: Install python dependencies run: | - poetry install --sync --no-interaction --no-root --with test + poetry install --sync --no-interaction --no-root --with test poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} - name: Publish run: | diff --git a/ninja_put_patch_file_upload_middleware/middlewares.py b/ninja_put_patch_file_upload_middleware/middlewares.py index 0fe4f70..3e984e0 100644 --- a/ninja_put_patch_file_upload_middleware/middlewares.py +++ b/ninja_put_patch_file_upload_middleware/middlewares.py @@ -1,14 +1,18 @@ from collections.abc import Callable -from typing import Any +from typing import Any, Union from asgiref.sync import iscoroutinefunction, sync_to_async -from django.http import HttpRequest +from django.http import HttpRequest, HttpResponse from django.utils.decorators import sync_and_async_middleware @sync_and_async_middleware -def process_put_patch(get_response: Callable) -> Callable: - async def async_middleware(request: HttpRequest) -> Any: +def process_put_patch( + get_response: Union[ + Callable[[HttpRequest], HttpResponse], Callable[[HttpRequest], Any] + ], +) -> Union[Callable[[HttpRequest], Any], Callable[[HttpRequest], HttpResponse]]: + async def async_middleware(request: HttpRequest) -> Union[HttpResponse, Any]: if ( request.method in ("PUT", "PATCH") and request.content_type != "application/json" @@ -22,7 +26,7 @@ async def async_middleware(request: HttpRequest) -> Any: return await get_response(request) - def sync_middleware(request: HttpRequest) -> Any: + def sync_middleware(request: HttpRequest) -> Union[HttpResponse, Any]: if ( request.method in ("PUT", "PATCH") and request.content_type != "application/json" diff --git a/poetry.lock b/poetry.lock index 28811ec..41cc182 100644 --- a/poetry.lock +++ b/poetry.lock @@ -363,4 +363,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = ">=3.9" -content-hash = "fb42520962cd0f720a01e992249ec6af8acb9e11255341ed5c1eb0e94b2b762e" +content-hash = "67b8a55fe88ea0e44a3d0956c7a148fe3f3adefdb39a0ad0cc4ffc567b4e3d26" diff --git a/pyproject.toml b/pyproject.toml index 3ada2bb..1e29571 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,16 +10,16 @@ homepage = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middl repository = "https://github.com/baseplate-admin/ninja_put_patch_file_upload_middleware" keywords = ["ninja", "django-ninja", "middlewares",'put','patch','file upload'] classifiers = [ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware", - "Framework :: Django", - "Framework :: Django :: 3.2", - "Framework :: Django :: 4.1", - "Framework :: Django :: 4.2", - "Framework :: Django :: 5.0", - "Framework :: Django :: 5.1", - "Operating System :: OS Independent", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Framework :: Django :: 5.1", + "Operating System :: OS Independent", ] [tool.poetry.dependencies] @@ -29,9 +29,9 @@ django-ninja = "*" [tool.poetry.group.dev.dependencies] -pytest = ">=7.2.2,<9.0.0" -pytest-django = "^4.8.0" -pytest-asyncio = ">=0.23.6,<0.25.0" +pytest = ">=7.2.2" +pytest-django = ">=4.8.0" +pytest-asyncio = ">=0.23.6" [build-system] requires = ["poetry-core"]