Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support django >5 and python >3.12 #98

Merged
merged 8 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade packaging tools
Expand All @@ -34,7 +36,7 @@ jobs:
ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")
TOXENV=$(tox --listenvs | grep "^py$ENV_PREFIX" | tr '\n' ',') python -m tox
- name: Report coverage
if: matrix.python-version == '3.10' && github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize')
if: matrix.python-version == '3.13' && github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'synchronize')
uses: 5monkeys/cobertura-action@master
with:
path: coverage.xml
Expand All @@ -50,11 +52,11 @@ jobs:
name: Run type checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.13"
- name: Upgrade packaging tools
run: python -m pip install --upgrade pip setuptools virtualenv
- name: Install dependencies
Expand All @@ -66,7 +68,7 @@ jobs:
name: Lint
uses: less-action/reusables/.github/workflows/pre-commit.yaml@v2
with:
python-version: "3.10"
python-version: "3.13"

check-build:
name: Check packaging
Expand Down
42 changes: 39 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ on:

jobs:
build-and-publish:
uses: less-action/reusables/.github/workflows/python-publish.yaml@v6
secrets:
pypi_api_token: ${{ secrets.PYPI_API_TOKEN }}
name: Build and publish
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
cache-dependency-path: ${{ inputs.requirements_file }}
check-latest: true
- name: Install dependencies
run: python3 -m pip install --upgrade build pkginfo
- name: Build
run: python3 -m build --sdist --wheel .
# NOTE: Copied and modified from less-action/reusables
- name: Verify release version
run: |
pkg_info_version=$(
python3 <(cat << EOF
from pathlib import Path
from pkginfo import Wheel
wheel = Wheel(next(Path("dist").glob("*.whl")))
print(wheel.version)
EOF
)
)
if [[ "$pkg_info_version" != "${{ github.event.release.tag_name }}" ]]; then
echo "💥 The version of the built wheel doesn't match the release tag."
echo
echo "Release tag: '${{ github.event.release.tag_name }}'"
echo "Packaged version: '$pkg_info_version'"
exit 1
fi
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3.13
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
Expand Down Expand Up @@ -36,7 +36,7 @@ repos:
- id: check-manifest
# See https://github.com/mgedmin/check-manifest/issues/141
args: ["--no-build-isolation"]
additional_dependencies: [setuptools-scm]
additional_dependencies: [setuptools, wheel, setuptools-scm]

exclude: |
(?x)(
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2021 5 Monkeys
Copyright (c) 2014-2025 5 Monkeys

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 5 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ with the ``drf`` extra to keep those in sync:

Currently tested only for

- Django 3.2 under Python 3.7-3.9
- Django 3.2 under Python 3.8-3.10
- Django 4.0 under Python 3.8-3.10
- Django 4.1 under Python 3.8-3.10
- Django 4.2 under Python 3.8-3.10
- Django 4.1 under Python 3.8-3.13
- Django 4.2 under Python 3.8-3.13
- Django 5.0 under Python 3.10-3.13
- Django 5.1 under Python 3.10-3.13

Pull requests welcome!

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=57.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ["py38", "py39", "py310", "py311"]
target-version = ["py38", "py39", "py310", "py311", "py312"]

[tool.ruff]
src = ["src"]
Expand Down
12 changes: 10 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ classifiers =
Development Status :: 5 - Production/Stable
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13
Framework :: Django
Framework :: Django :: 3.2
Framework :: Django :: 4.0
Framework :: Django :: 4.1
Framework :: Django :: 4.2
Framework :: Django :: 5.0
Framework :: Django :: 5.1
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Expand Down
4 changes: 2 additions & 2 deletions src/bananas/admin/api/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_admin_meta(cls) -> ModelDict:
if admin is not None:
meta.update(
{
key: getattr(admin, key) # type: ignore[misc, call-overload]
key: getattr(admin, key)
for key in filter(
lambda key: key in meta, # type: ignore[arg-type]
lambda key: key in meta,
admin.__dict__.keys(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/bananas/admin/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def create(self, request: Request) -> Response:
raise serializers.ValidationError(password_form.errors) # type: ignore[arg-type]

password_form.save()
update_session_auth_hash(request, password_form.user)
update_session_auth_hash(request, password_form.user) # type: ignore[arg-type]

return Response(status=status.HTTP_204_NO_CONTENT)

Expand Down
7 changes: 4 additions & 3 deletions src/bananas/admin/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def admin_view(

admin_login_url = reverse_lazy("admin:login")
view = user_passes_test(
lambda u: u.is_active and hasattr(u, "is_staff") and u.is_staff, login_url=admin_login_url # type: ignore[arg-type, return-value]
lambda u: u.is_active and hasattr(u, "is_staff") and u.is_staff,
login_url=admin_login_url,
)(view)
view = permission_required(perm, login_url=admin_login_url)(view)
return view
Expand Down Expand Up @@ -355,8 +356,8 @@ def get_view_tools(self) -> List[ViewTool]:
# Mypy doesn't change type on a len(...) call
# See: https://github.com/python/mypy/issues/1178
if len(tool) == 3:
tool, perm = cast(Tuple[str, str, str], tool)[:-1], tool[-1]
text, link = cast(Tuple[str, str], tool)
tool, perm = tool[:-1], tool[-1]
text, link = tool
tool = ViewTool(text, link, perm=perm)
else:
# Assume ViewTool
Expand Down
4 changes: 2 additions & 2 deletions src/bananas/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def get_settings() -> Dict[str, Any]:
parse = get_parser(SETTINGS_TYPES[key])
else:
# Determine parser by django setting type
parse = get_parser(type(default_value))
parse = get_parser(type(default_value)) # type: ignore[type-var]

value = parse(value)
value = parse(value) # type: ignore[assignment]

settings[key] = value

Expand Down
26 changes: 16 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
# Currently `pip install tox==3.0.0rc2`

[tox]
envlist = py38-django{ 32, 40, 41, 42 }
py39-django{ 32, 40, 41, 42 }
py310-django{ 32, 40, 41, 42 }
py311-django{ 41, 42 }
envlist = py38-django{ 32, 40, 41, 42 }
py39-django{ 32, 40, 41, 42 }
py310-django{ 32, 40, 41, 42, 50, 51 }
py311-django{ 41, 42, 50, 51 }
py312-django{ 41, 42, 50, 51 }
py313-django{ 41, 42, 50, 51 }
# Shouldn't be any need to run with no DRF for each python
py311-no-rest-framework
py313-no-rest-framework
type-check
skipsdist = true

Expand All @@ -36,26 +38,30 @@ deps =
django40: Django<4.1
django41: Django<4.2
django42: Django<4.3
django50: Django<5.1
django51: Django<5.2
django32: djangorestframework>=3.12.0,<3.13
django40: djangorestframework>=3.14.0,<3.15
django41: djangorestframework>=3.14.0,<3.15
# TODO: Change to proper version when a version with this commit is available.
django42: https://github.com/encode/django-rest-framework/archive/ea03e95174f46003e7e917b623c5316247b8b316.zip
django42: djangorestframework>=3.15.0,<3.16
django50: djangorestframework>=3.15.0,<3.16
django51: djangorestframework>=3.15.0,<3.16


[testenv:py311-no-rest-framework]

[testenv:py313-no-rest-framework]
commands =
pytest {posargs}
deps =
.
Django>=2.2,<=4.2
Django>=2.2,<=5.2
pytest
pytest-cov
pytest-django


[testenv:type-check]
basepython = python3.10
basepython = python3.13
skip_install = true
commands =
mypy
Expand Down
Loading