Skip to content

Commit 19edbfa

Browse files
mikemangerddabble
andauthored
Drop Python 3.8 and Django 5.0, add Python 3.13 and Django 5.10, update old code and fix tests (#171)
* Bump GitHub action workflows * Test against python 3.13 and django 5.2. Drop EOL versions * Simplify tox env list for django 5.1/5.2 * Fix deprecated warning in CI * Fix syntax of CI * Use Django 4.2 syntax for test HTTP headers * Use python 3 syntax for objects and super calls * Use python 3 syntax for decorators * Use python 3 syntax for strings * Add pre-commit repos for django-upgrade and pyupgrade * Remove uneeded default in middleware * Use f strings in some places * Fix flake8 issue * Updated gitignore * Updated changelog Also added the missing Django 5.2 classifier to `setup.py`. * Match quote style Co-authored-by: Anders <6058745+ddabble@users.noreply.github.com> * fixup! Match quote style * Added pre-commit-hooks --------- Co-authored-by: Anders <6058745+ddabble@users.noreply.github.com>
1 parent d9479e0 commit 19edbfa

22 files changed

+99
-69
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
1717

1818
- name: Set up Python
19-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v5
2020
with:
21-
python-version: 3.8
21+
python-version: 3.9
2222

2323
- name: Install dependencies
2424
run: |

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ jobs:
99
fail-fast: false
1010
max-parallel: 5
1111
matrix:
12-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
12+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616

1717
- name: Set up Python ${{ matrix.python-version }}
18-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
2121

2222
- name: Get pip cache dir
2323
id: pip-cache
2424
run: |
25-
echo "::set-output name=dir::$(pip cache dir)"
25+
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
2626
2727
- name: Cache
28-
uses: actions/cache@v2
28+
uses: actions/cache@v4
2929
with:
3030
path: ${{ steps.pip-cache.outputs.dir }}
3131
key:
@@ -43,6 +43,6 @@ jobs:
4343
tox -v
4444
4545
- name: Upload coverage
46-
uses: codecov/codecov-action@v1
46+
uses: codecov/codecov-action@v5
4747
with:
4848
name: Python ${{ matrix.python-version }}

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
*.pyc
2-
docs/_build
32
.tox
3+
.venv/
4+
venv/
5+
.eggs/
46
*.egg-info
57
*.egg
68
.coverage
79
coverage.xml
810
reports/
911
build/
12+
docs/_build
1013
dist/
1114
.cache/
12-
.eggs/
15+
.idea/
16+
.vscode/

.pre-commit-config.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
repos: []
1+
repos:
2+
- repo: https://github.com/adamchainz/django-upgrade
3+
rev: 1.23.1
4+
hooks:
5+
- id: django-upgrade
6+
args: [--target-version, "4.2"]
7+
- repo: https://github.com/asottile/pyupgrade
8+
rev: v3.19.1
9+
hooks:
10+
- id: pyupgrade
11+
args: [--py39-plus]
12+
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v5.0.0
15+
hooks:
16+
- id: check-executables-have-shebangs
17+
- id: check-illegal-windows-names
18+
- id: check-merge-conflict
19+
- id: end-of-file-fixer
20+
- id: fix-byte-order-marker
21+
- id: mixed-line-ending
22+
- id: trailing-whitespace

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include AUTHORS
22
include README.rst
3-
recursive-include docs *
3+
recursive-include docs *

django_hosts/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class LazySite(LazyObject):
1111

1212
def __init__(self, request, *args, **kwargs):
13-
super(LazySite, self).__init__()
13+
super().__init__()
1414
self.__dict__.update({
1515
'name': request.host.name,
1616
'args': args,

django_hosts/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def patterns(prefix, *args):
5555
return hosts
5656

5757

58-
class host(object):
58+
class host:
5959
"""
6060
The host object used in host conf together with the
6161
:func:`django_hosts.defaults.patterns` function, e.g.::
@@ -96,7 +96,7 @@ def __init__(self, regex, urlconf, name, callback=None, prefix='',
9696
self.regex = regex
9797
parent_host = getattr(settings, 'PARENT_HOST', '').lstrip('.')
9898
suffix = r'\.' + parent_host if parent_host else ''
99-
self.compiled_regex = re.compile(r'%s%s(\.|:|$)' % (regex, suffix))
99+
self.compiled_regex = re.compile(fr'{regex}{suffix}(\.|:|$)')
100100
self.urlconf = urlconf
101101
self.name = name
102102
self._scheme = scheme

django_hosts/managers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def home_page(request):
3434
"""
3535

3636
def __init__(self, field_name=None, select_related=True):
37-
super(HostSiteManager, self).__init__()
37+
super().__init__()
3838
self._field_name = field_name
3939
self._select_related = select_related
4040
self._depth = 1
@@ -81,7 +81,7 @@ def get_queryset(self, site_id=None):
8181
site_id = settings.SITE_ID
8282
if not self._is_validated:
8383
self._validate_field_name()
84-
qs = super(HostSiteManager, self).get_queryset()
84+
qs = super().get_queryset()
8585
return qs.filter(**{'%s__id__exact' % self._field_name: site_id})
8686

8787
def by_id(self, site_id=None):

django_hosts/middleware.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ class HostsBaseMiddleware(MiddlewareMixin):
1414
new_hosts_middleware = 'django_hosts.middleware.HostsRequestMiddleware'
1515
toolbar_middleware = 'debug_toolbar.middleware.DebugToolbarMiddleware'
1616

17-
# TODO: when support for Django 3.2 is removed, replace with:
18-
# def __init__(self, get_response):
19-
def __init__(self, get_response=None):
17+
def __init__(self, get_response):
2018
super().__init__(get_response)
2119
self.current_urlconf = None
2220
self.host_patterns = get_host_patterns()

django_hosts/resolvers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
from .utils import normalize_scheme, normalize_port
2020

2121

22-
@lru_cache()
22+
@lru_cache
2323
def get_hostconf():
2424
try:
2525
return settings.ROOT_HOSTCONF
2626
except AttributeError:
2727
raise ImproperlyConfigured("Missing ROOT_HOSTCONF setting")
2828

2929

30-
@lru_cache()
30+
@lru_cache
3131
def get_hostconf_module(hostconf=None):
3232
if hostconf is None:
3333
hostconf = get_hostconf()
3434
return import_module(hostconf)
3535

3636

37-
@lru_cache()
37+
@lru_cache
3838
def get_host(name=None):
3939
if name is None:
4040
try:
@@ -47,7 +47,7 @@ def get_host(name=None):
4747
raise NoReverseMatch("No host called '%s' exists" % name)
4848

4949

50-
@lru_cache()
50+
@lru_cache
5151
def get_host_patterns():
5252
hostconf = get_hostconf()
5353
module = get_hostconf_module(hostconf)
@@ -115,7 +115,7 @@ def reverse_host(host, args=None, kwargs=None):
115115
if parent_host:
116116
# only add the parent host when needed (aka www-less domain)
117117
if candidate and candidate != parent_host:
118-
candidate = '%s.%s' % (candidate, parent_host)
118+
candidate = f'{candidate}.{parent_host}'
119119
else:
120120
candidate = parent_host
121121
return candidate
@@ -189,7 +189,7 @@ def reverse(viewname, args=None, kwargs=None, prefix=None, current_app=None,
189189
else:
190190
port = normalize_port(port)
191191

192-
return iri_to_uri('%s%s%s%s' % (scheme, hostname, port, path))
192+
return iri_to_uri(f'{scheme}{hostname}{port}{path}')
193193

194194

195195
#: The lazy version of the :func:`~django_hosts.resolvers.reverse`

0 commit comments

Comments
 (0)