Skip to content

Commit e66e3bf

Browse files
authored
Merge pull request #90 from DemocracyClub/upgrades202408
test on current python/django versions, linter config
2 parents 95bb42d + 784345b commit e66e3bf

13 files changed

Lines changed: 42 additions & 50 deletions

File tree

.circleci/config.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
version: 2.1
22

33
executors:
4-
py38:
5-
docker:
6-
- image: cimg/python:3.8
7-
py39:
8-
docker:
9-
- image: cimg/python:3.9
104
py310:
115
docker:
126
- image: cimg/python:3.10
7+
py312:
8+
docker:
9+
- image: cimg/python:3.12
1310

1411
jobs:
1512
run_tests:
@@ -39,21 +36,17 @@ jobs:
3936
command: |
4037
python manage.py check
4138
- run:
42-
name: Black
39+
name: Djhtml
4340
command: |
44-
black . --check
45-
- run:
46-
name: Curly Lint
47-
command: |
48-
curlylint .
41+
git ls-files '*.html' | xargs djhtml --check
4942
- run:
5043
name: Ruff lint
5144
command: |
5245
ruff check .
5346
- run:
5447
name: Ruff Format
5548
command: |
56-
ruff format .
49+
ruff format . --check
5750
- run: mkdir -p test-results
5851
- run:
5952
name: Pytest
@@ -69,6 +62,6 @@ workflows:
6962

7063
matrix:
7164
parameters:
72-
python_version: [ py38, py39, py310 ]
73-
django_version: [ ">=3.2,<4.0", ">=4.0,<4.1", ">=4.1,<4.2" ]
65+
python_version: [ py310, py312 ]
66+
django_version: [ ">=4.2,<4.3", ">=5.1,<5.2" ]
7467

.pre-commit-config.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
repos:
2-
- repo: https://github.com/ambv/black
3-
rev: 21.7b0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# keep in step with verison in pyproject.toml
4+
rev: v0.6.1
45
hooks:
5-
- id: black
6+
- id: ruff
7+
args: [--fix, --exit-non-zero-on-fix]
8+
- id: ruff-format
69
- repo: https://github.com/rtts/djhtml
710
rev: v1.4.9
811
hooks:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Install the dev dependencies:
8383

8484
pip install -e .[dev]
8585

86-
This project uses [pre-commit](https://pre-commit.com/#quick-start) to run `black` and `djhtml` before each commit. To enable this, after installing the dev dependencies run:
86+
This project uses [pre-commit](https://pre-commit.com/#quick-start) to run `ruff` and `djhtml` before each commit. To enable this, after installing the dev dependencies run:
8787

8888
`pre-commit install`
8989

dc_utils/filter_widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
except ImportError:
66
raise ImportError("Filter widgets requires Django-Filter to be installed")
77

8-
from django.utils.safestring import mark_safe
98
from django.db.models import BLANK_CHOICE_DASH
109
from django.utils.encoding import force_str
10+
from django.utils.safestring import mark_safe
1111

1212
__all__ = ("DSLinkWidget",)
1313

dc_utils/forms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
from django import forms
44
from django.core.exceptions import ValidationError
5-
6-
from . import widgets
7-
85
from django.utils.translation import gettext_lazy as _
96
from localflavor.gb.forms import GBPostcodeField
107

8+
from . import widgets
9+
1110

1211
class RadioSelectCluster(forms.RadioSelect):
1312
pass

dc_utils/storages.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from urllib.parse import urlsplit, urlunsplit, unquote
1+
from urllib.parse import unquote, urlsplit, urlunsplit
22

33
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
44
from pipeline.storage import PipelineMixin
@@ -20,10 +20,13 @@ def stored_name(self, name):
2020
clean_name = parsed_name.path.strip()
2121
hash_key = self.hash_key(clean_name)
2222
cache_name = self.hashed_files.get(hash_key)
23-
if cache_name is None:
24-
# This bit below is changed from the parent class
25-
if not self.manifest_strict:
26-
return name
23+
24+
# ---
25+
# This bit is changed from the parent class
26+
if cache_name is None and not self.manifest_strict:
27+
return name
28+
# ---
29+
2730
unparsed_name = list(parsed_name)
2831
unparsed_name[2] = cache_name
2932
# Special casing for a @font-face hack, like url(myfont.eot?#iefix")

dc_utils/templatetags/dc_forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def add_input_classes(field):
2626
def dc_form(element):
2727
if not isinstance(element, forms.BaseForm):
2828
# if called without a form object, return without rendering
29-
return
29+
return None
3030
markup_classes = {"label": "", "value": "", "single_value": ""}
3131
return render(element, markup_classes)
3232

dc_utils/tests/test_dc_forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_render_called_when_element_is_a_form(self, mocker):
1717
mocker.patch("dc_utils.templatetags.dc_forms.render", mock_render)
1818
form = forms.Form()
1919
assert dc_form(element=form) == "rendered_form"
20-
mock_render.called_once_with(
20+
mock_render.assert_called_once_with(
2121
form, {"label": "", "value": "", "single_value": ""}
2222
)
2323

@@ -35,6 +35,6 @@ class Meta:
3535
mocker.patch("dc_utils.templatetags.dc_forms.render", mock_render)
3636

3737
assert dc_form(element=form) == "rendered_form"
38-
mock_render.called_once_with(
38+
mock_render.assert_called_once_with(
3939
form, {"label": "", "value": "", "single_value": ""}
4040
)

dc_utils/tests/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dc_utils.tests.helpers import validate_html_str, validate_html
1+
from dc_utils.tests.helpers import validate_html, validate_html_str
22

33

44
def test_validate_html_str():

dc_utils/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django import http
22
from django.conf import settings
3-
from django.urls import re_path
43
from django.template import TemplateDoesNotExist, loader
4+
from django.urls import re_path
55
from django.views.decorators.csrf import requires_csrf_token
66
from django.views.defaults import ERROR_500_TEMPLATE_NAME, page_not_found
77
from django.views.generic import TemplateView

0 commit comments

Comments
 (0)