From daa6235cafbecd4900df3509b00472bbe8c60f4b Mon Sep 17 00:00:00 2001 From: Hesam Noorin Date: Sun, 1 Feb 2026 19:58:21 +0330 Subject: [PATCH] Upgrade to Django 5.2 & Python 3.12 (#249) * feat: add support for Django 5.0, 5.1, and 5.2 * fix: resolve Python 3.12 build failures in docs and lint environments --- MANIFEST.in | 1 + README.rst | 8 ++++---- docs/conf.py | 16 ++++++++++++---- setup.py | 17 +++++++++++------ tox.ini | 29 +++++++++++++++++------------ 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 898a12e..c401e7a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,6 +7,7 @@ include CODE_OF_CONDUCT.md include requirements.txt include tox.ini include .pre-commit-config.yaml +include .readthedocs.yaml recursive-include docs * recursive-include exampleapp * recursive-include defender/templates *.html diff --git a/README.rst b/README.rst index edc0903..7a43767 100644 --- a/README.rst +++ b/README.rst @@ -108,8 +108,8 @@ Admin pages Requirements ------------ -* Python: 3.7, 3.8, 3.9, 3.10, PyPy -* Django: 3.x, 4.x +* Python: 3.8, 3.9, 3.10, 3.11, 3.12, PyPy +* Django: 3.2, 4.2, 5.0, 5.1, 5.2 * Redis: 5.x, 6.x, 7.x @@ -534,8 +534,8 @@ Below is a sample ``BasicAuthenticationDefender`` class based on ``rest_framewor from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm from django.contrib.auth.tokens import default_token_generator from django.utils.http import urlsafe_base64_decode as uid_decoder - from django.utils.translation import ugettext_lazy as _ - from django.utils.encoding import force_text + from django.utils.translation import gettext_lazy as _ + from django.utils.encoding import force_str from rest_framework import serializers, exceptions, HTTP_HEADER_ENCODING from rest_framework.exceptions import ValidationError from defender import utils as defender_utils diff --git a/docs/conf.py b/docs/conf.py index fad7888..92b574b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,11 @@ # import os # import sys # sys.path.insert(0, os.path.abspath(".")) -from pkg_resources import get_distribution +try: + from importlib import metadata +except ImportError: + # Running on pre-3.8 Python; use importlib-metadata package + import importlib_metadata as metadata # -- Project information ----------------------------------------------------- @@ -22,7 +26,11 @@ copyright = "2024, Ken Cochrane" author = "Ken Cochrane" # The full version, including alpha/beta/rc tags. -release = get_distribution("django-defender").version +try: + release = metadata.version("django-defender") +except metadata.PackageNotFoundError: + # package is not installed + release = "0.0.0" # The short X.Y version. version = ".".join(release.split(".")[:2]) @@ -38,7 +46,7 @@ master_doc = "index" extensions = [] # Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] +templates_path = [] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -56,4 +64,4 @@ html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +html_static_path = [] diff --git a/setup.py b/setup.py index ace56e5..2dbd15d 100644 --- a/setup.py +++ b/setup.py @@ -34,16 +34,21 @@ setup( "Framework :: Django :: 3.2", "Framework :: Django :: 4.0", "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", + "Framework :: Django :: 5.0", + "Framework :: Django :: 5.1", + "Framework :: Django :: 5.2", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3 :: Only', - "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", "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 :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", @@ -59,12 +64,12 @@ setup( include_package_data=True, packages=find_packages(), package_data=get_package_data("defender"), - python_requires='~=3.7', - install_requires=["Django", "redis"], + python_requires="~=3.8", + install_requires=["Django", "redis>=4.0.0"], tests_require=[ "mockredispy>=2.9.0.11,<3.0", "coverage", "celery", - "django-redis-cache", + "django-redis", ], ) diff --git a/tox.ini b/tox.ini index a1b4209..ecf33e1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,27 +1,29 @@ [tox] envlist = # list of supported Django/Python versions: - py{37,38,39,py3}-dj{32} - py{38,39,310,311}-dj{40,41,42} - py{311}-dj{main} - py38-{lint,docs} + py{38,39,py3}-dj{32} + py{38,39,310,311,312}-dj{42} + py{310,311,312}-dj{50,51,52,main} + py312-{lint,docs} [gh-actions] python = - 3.7: py37 3.8: py38 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 pypy3: pypy3 [testenv] deps = + setuptools -rrequirements.txt dj32: django>=3.2,<4.0 - dj40: django>=4.0,<4.1 - dj41: django>=4.1,<4.2 - dj42: django>=4.2,<4.3 + dj42: django>=4.2,<5.0 + dj50: django>=5.0,<5.1 + dj51: django>=5.1,<5.2 + dj52: django>=5.2,<5.3 djmain: https://github.com/django/django/archive/main.tar.gz usedevelop = True commands = @@ -33,19 +35,22 @@ ignore_outcome = ignore_errors = djmain: True -[testenv:py38-docs] -basepython = python3.8 +[testenv:py312-docs] +basepython = python3.12 deps = -rrequirements.txt Sphinx sphinx_rtd_theme + setuptools commands = sphinx-build -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html -[testenv:py38-lint] -basepython = python3.8 +[testenv:py312-lint] +basepython = python3.12 deps = twine check-manifest + setuptools + setuptools_scm commands = check-manifest -v python setup.py sdist