Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ jobs:
fail-fast: false
max-parallel: 5
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']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
Expand All @@ -43,6 +43,6 @@ jobs:
tox -v

- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v5
with:
name: Python ${{ matrix.python-version }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
*.pyc
docs/_build
.tox
.venv/
venv/
.eggs/
*.egg-info
*.egg
.coverage
coverage.xml
reports/
build/
docs/_build
dist/
.cache/
.eggs/
.idea/
.vscode/
23 changes: 22 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
repos: []
repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.23.1
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-executables-have-shebangs
- id: check-illegal-windows-names
- id: check-merge-conflict
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include AUTHORS
include README.rst
recursive-include docs *
recursive-include docs *
2 changes: 1 addition & 1 deletion django_hosts/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class LazySite(LazyObject):

def __init__(self, request, *args, **kwargs):
super(LazySite, self).__init__()
super().__init__()
self.__dict__.update({
'name': request.host.name,
'args': args,
Expand Down
4 changes: 2 additions & 2 deletions django_hosts/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def patterns(prefix, *args):
return hosts


class host(object):
class host:
"""
The host object used in host conf together with the
:func:`django_hosts.defaults.patterns` function, e.g.::
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, regex, urlconf, name, callback=None, prefix='',
self.regex = regex
parent_host = getattr(settings, 'PARENT_HOST', '').lstrip('.')
suffix = r'\.' + parent_host if parent_host else ''
self.compiled_regex = re.compile(r'%s%s(\.|:|$)' % (regex, suffix))
self.compiled_regex = re.compile(fr'{regex}{suffix}(\.|:|$)')
self.urlconf = urlconf
self.name = name
self._scheme = scheme
Expand Down
4 changes: 2 additions & 2 deletions django_hosts/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def home_page(request):
"""

def __init__(self, field_name=None, select_related=True):
super(HostSiteManager, self).__init__()
super().__init__()
self._field_name = field_name
self._select_related = select_related
self._depth = 1
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_queryset(self, site_id=None):
site_id = settings.SITE_ID
if not self._is_validated:
self._validate_field_name()
qs = super(HostSiteManager, self).get_queryset()
qs = super().get_queryset()
return qs.filter(**{'%s__id__exact' % self._field_name: site_id})

def by_id(self, site_id=None):
Expand Down
4 changes: 1 addition & 3 deletions django_hosts/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class HostsBaseMiddleware(MiddlewareMixin):
new_hosts_middleware = 'django_hosts.middleware.HostsRequestMiddleware'
toolbar_middleware = 'debug_toolbar.middleware.DebugToolbarMiddleware'

# TODO: when support for Django 3.2 is removed, replace with:
# def __init__(self, get_response):
def __init__(self, get_response=None):
def __init__(self, get_response):
super().__init__(get_response)
self.current_urlconf = None
self.host_patterns = get_host_patterns()
Expand Down
12 changes: 6 additions & 6 deletions django_hosts/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
from .utils import normalize_scheme, normalize_port


@lru_cache()
@lru_cache
def get_hostconf():
try:
return settings.ROOT_HOSTCONF
except AttributeError:
raise ImproperlyConfigured("Missing ROOT_HOSTCONF setting")


@lru_cache()
@lru_cache
def get_hostconf_module(hostconf=None):
if hostconf is None:
hostconf = get_hostconf()
return import_module(hostconf)


@lru_cache()
@lru_cache
def get_host(name=None):
if name is None:
try:
Expand All @@ -47,7 +47,7 @@ def get_host(name=None):
raise NoReverseMatch("No host called '%s' exists" % name)


@lru_cache()
@lru_cache
def get_host_patterns():
hostconf = get_hostconf()
module = get_hostconf_module(hostconf)
Expand Down Expand Up @@ -115,7 +115,7 @@ def reverse_host(host, args=None, kwargs=None):
if parent_host:
# only add the parent host when needed (aka www-less domain)
if candidate and candidate != parent_host:
candidate = '%s.%s' % (candidate, parent_host)
candidate = f'{candidate}.{parent_host}'
else:
candidate = parent_host
return candidate
Expand Down Expand Up @@ -189,7 +189,7 @@ def reverse(viewname, args=None, kwargs=None, prefix=None, current_app=None,
else:
port = normalize_port(port)

return iri_to_uri('%s%s%s%s' % (scheme, hostname, port, path))
return iri_to_uri(f'{scheme}{hostname}{port}{path}')


#: The lazy version of the :func:`~django_hosts.resolvers.reverse`
Expand Down
13 changes: 7 additions & 6 deletions django_hosts/templatetags/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
self.host_kwargs = kwargs.pop('host_kwargs')
self.scheme = kwargs.pop('scheme')
self.port = kwargs.pop('port')
super(HostURLNode, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def maybe_resolve(self, var, context):
"""
Expand All @@ -41,17 +41,18 @@ def render(self, context):
current_urlconf = get_urlconf()
try:
set_urlconf(host.urlconf)
path = super(HostURLNode, self).render(context)
path = super().render(context)
if self.asvar:
path = context[self.asvar]
finally:
set_urlconf(current_urlconf)

host_args = [self.maybe_resolve(x, context) for x in self.host_args]

host_kwargs = dict((smart_str(k, 'ascii'),
self.maybe_resolve(v, context))
for k, v in self.host_kwargs.items())
host_kwargs = {
smart_str(k, 'ascii'): self.maybe_resolve(v, context)
for k, v in self.host_kwargs.items()
}

if self.scheme:
scheme = normalize_scheme(self.maybe_resolve(self.scheme, context))
Expand All @@ -65,7 +66,7 @@ def render(self, context):

hostname = reverse_host(host, args=host_args, kwargs=host_kwargs)

uri = iri_to_uri('%s%s%s%s' % (scheme, hostname, port, path))
uri = iri_to_uri(f'{scheme}{hostname}{port}{path}')

if self.asvar:
context[self.asvar] = uri
Expand Down
1 change: 0 additions & 1 deletion django_hosts/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

def normalize_scheme(scheme=None, default='//'):
if scheme is None:
scheme = default
Expand Down
14 changes: 12 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ Changelog
X.Y (unreleased)
----------------

- **BACKWARD-INCOMPATIBLE** Dropped support Django < 4.2.
- **BACKWARD-INCOMPATIBLE** Dropped support for Python 3.8.

- Confirmed support for Django 4.2 and 5.0 (no code changes were required).
- **BACKWARD-INCOMPATIBLE** Dropped support for Django < 4.2 and Django 5.0
(support for 5.0 was added to an unreleased version).

- **BACKWARD-INCOMPATIBLE** Removed the ``None`` default value of the
``get_response`` parameter of ``HostsBaseMiddleware()``, after the argument
was made required with Django 4.0+.

- Confirmed support for Python 3.13.

- Confirmed support for Django 4.2, 5.1 and 5.2
(no functional code changes were required).

6.0 (2023-10-27)
----------------
Expand Down
14 changes: 6 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# django-hosts documentation build configuration file, created by
# sphinx-quickstart on Mon Sep 26 16:39:46 2011.
#
Expand Down Expand Up @@ -43,8 +41,8 @@
master_doc = 'index'

# General information about the project.
project = u'django-hosts'
copyright = u'2015-2016, Jazzband members (https://jazzband.co/)'
project = 'django-hosts'
copyright = '2015-2016, Jazzband members (https://jazzband.co/)'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -185,8 +183,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-hosts.tex', u'django-hosts Documentation',
u'Jannis Leidel and contributors', 'manual'),
('index', 'django-hosts.tex', 'django-hosts Documentation',
'Jannis Leidel and contributors', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -218,8 +216,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-hosts', u'django-hosts Documentation',
[u'Jannis Leidel and contributors'], 1)
('index', 'django-hosts', 'django-hosts Documentation',
['Jannis Leidel and contributors'], 1)
]

# Example configuration for intersphinx: refer to the Python standard library.
Expand Down
1 change: 0 additions & 1 deletion docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ depending on the host that should handle the call
.. code-block:: python

client.post(..., SERVER_NAME='api-server.something')

7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read(*parts):
'Maps hostnames to URLconfs.',
long_description=read('README.rst'),
use_scm_version=True,
python_requires='>=3.8',
python_requires='>=3.9',
setup_requires=['setuptools_scm'],
url='https://django-hosts.readthedocs.io/',
project_urls={
Expand All @@ -30,17 +30,18 @@ def read(*parts):
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 4.2',
'Framework :: Django :: 5.0',
'Framework :: Django :: 5.1',
'Framework :: Django :: 5.2',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'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 :: 3.13',
],
)
2 changes: 1 addition & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class HostsTestCase(TestCase):

def setUp(self):
super(HostsTestCase, self).setUp()
super().setUp()
# Every test needs access to the request factory.
self.factory = RequestFactory()
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@

SECRET_KEY = 'something-something'

USE_TZ = True
USE_TZ = True
Loading