Skip to content

Commit 1e91d0a

Browse files
committed
Switch to using ruff
1 parent 25b9b59 commit 1e91d0a

File tree

15 files changed

+55
-61
lines changed

15 files changed

+55
-61
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
ci:
22
autofix_prs: false
33

4-
default_language_version:
5-
python: python3.8
64
repos:
75
- repo: https://github.com/pre-commit/pre-commit-hooks
86
rev: v4.4.0
@@ -18,22 +16,15 @@ repos:
1816
- id: end-of-file-fixer
1917
- id: trailing-whitespace
2018
- repo: https://github.com/psf/black
21-
rev: 22.12.0
19+
rev: 23.3.0
2220
hooks:
2321
- id: black
24-
- repo: https://github.com/pycqa/isort
25-
# isort config is in pyproject.toml
26-
rev: 5.11.5
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
# Ruff version.
24+
rev: v0.0.270
2725
hooks:
28-
- id: isort
29-
- repo: https://github.com/pycqa/flake8
30-
# flake8 config is in setup.cfg
31-
rev: 6.0.0
32-
hooks:
33-
- id: flake8
34-
additional_dependencies:
35-
- flake8-bugbear
36-
- flake8-comprehensions
26+
- id: ruff
27+
args: [--fix, --exit-non-zero-on-fix]
3728
- repo: https://github.com/mgedmin/check-manifest
3829
rev: "0.49"
3930
hooks:
@@ -43,4 +34,4 @@ repos:
4334
rev: v1.12.1
4435
hooks:
4536
- id: blacken-docs
46-
additional_dependencies: [black==22.8.0]
37+
additional_dependencies: [black==23.3.0]

manage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32
import os
43
import sys
54

pyproject.toml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
[tool.black]
22
target-version = ["py38"]
33

4-
[tool.isort]
5-
profile = "black"
6-
known_django = "django"
7-
known_wagtail = "wagtail"
8-
known_first_party = ['wagtail-headless-preview']
9-
sections = ['FUTURE', 'STDLIB', 'DJANGO', 'WAGTAIL', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER']
10-
skip=['migrations', '.git', '__pycache__', 'venv', '.venv', '.github', '.tox', 'build', 'dist']
11-
blocked_extensions=["rst", "html", "js", "svg", "txt", "css", "scss", "png", "sh"]
12-
lines_between_types = 1
13-
lines_after_imports = 2
4+
[tool.ruff]
5+
target-version = "py38"
6+
select = [
7+
"B", # flake8-bugbear
8+
"C4", # flake8-comprehensions
9+
"E", # pycodestyle errors
10+
"F", # pyflakes
11+
"I", # isort
12+
"S", # flake8-bandit
13+
"W", # pycodestyle warnings
14+
"UP", # pyupgrade
15+
]
16+
17+
[tool.ruff.isort]
18+
known-first-party = ["wagtail-headless-preview"]
19+
lines-between-types = 1
20+
lines-after-imports = 2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
author_email="[email protected]",
2121
url="https://github.com/torchbox/wagtail-headless-preview",
2222
project_urls={
23-
"Changelog": "https://github.com/torchbox/wagtail-headless-preview/blob/main/CHANGELOG.md", # noqa:B950
23+
"Changelog": "https://github.com/torchbox/wagtail-headless-preview/blob/main/CHANGELOG.md", # noqa:B950 E501
2424
},
2525
packages=find_packages(where="src"),
2626
package_dir={"": "src"},

src/wagtail_headless_preview/migrations/0001_initial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Generated by Django 2.1.5 on 2019-03-19 14:21
22

3-
from django.db import migrations, models
43
import django.db.models.deletion
54

5+
from django.db import migrations, models
6+
67

78
class Migration(migrations.Migration):
8-
99
initial = True
1010

1111
dependencies = [("contenttypes", "0002_remove_content_type_name")]

src/wagtail_headless_preview/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def create_page_preview(self):
8080
identifier = f"id={self.pk}"
8181

8282
token = self.get_preview_signer().sign(identifier)
83-
# Note: Using update_page_preview() instead of just create() to avoid unique constraint
84-
# failures if preview is clicked multiple times
83+
# Note: Using update_page_preview() instead of just create() to avoid
84+
# unique constraint failures if preview is clicked multiple times
8585
preview, _ = self.update_page_preview(token)
8686

8787
return preview
@@ -132,8 +132,9 @@ def serve(self, request):
132132
Mixin overriding the default serve method with a redirect.
133133
The URL of the requested page is kept the same, only the host is
134134
overridden.
135-
By default this uses the hosts defined in HEADLESS_PREVIEW_CLIENT_URLS.
136-
However, you can enforce a single host using the HEADLESS_SERVE_BASE_URL setting.
135+
By default, this uses the hosts defined in HEADLESS_PREVIEW_CLIENT_URLS.
136+
However, you can enforce a single host using the HEADLESS_SERVE_BASE_URL
137+
setting.
137138
"""
138139
if headless_preview_settings.SERVE_BASE_URL:
139140
base_url = headless_preview_settings.SERVE_BASE_URL

src/wagtail_headless_preview/settings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
The wagtail_headless_preview settings are namespaced in the WAGTAIL_HEADLESS_PREVIEW setting.
2+
The wagtail_headless_preview settings are namespaced in the
3+
WAGTAIL_HEADLESS_PREVIEW setting.
4+
35
For example your project's `settings.py` file might look like this:
46
WAGTAIL_HEADLESS_PREVIEW = {
57
"CLIENT_URLS": {"default": "https://headless.site"},
@@ -30,8 +32,8 @@
3032

3133
class WagtailHeadlessPreviewSettings:
3234
"""
33-
A settings object that allows the wagtail_headless_preview settings to be accessed as
34-
properties. For example:
35+
A settings object that allows the wagtail_headless_preview settings to be
36+
accessed as properties. For example:
3537
from wagtail_headless_previews.settings import headless_preview_settings
3638
print(headless_preview_settings.CLIENT_URLS)
3739
Note:

tests/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
77

8-
SECRET_KEY = "fake_secret_key_to_run_tests" # pragma: allowlist secret
8+
SECRET_KEY = "fake_secret_key_to_run_tests" # noqa: S105
99

1010
INSTALLED_APPS = [
1111
"tests.testapp",

tests/test_frontend.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
from django.test import TestCase, override_settings
33
from django.urls import reverse
44
from django.utils.http import urlencode
5-
65
from wagtail.models import Page
7-
8-
from tests.testapp.models import HeadlessPage, SimplePage
96
from wagtail_headless_preview.models import PagePreview
107
from wagtail_headless_preview.settings import headless_preview_settings
118

9+
from tests.testapp.models import HeadlessPage, SimplePage
10+
1211

1312
class TestFrontendViews(TestCase):
1413
fixtures = ["test.json"]
1514

1615
@classmethod
1716
def setUpTestData(cls):
1817
cls.admin_user = User.objects.create_superuser(
19-
username="admin", email="[email protected]", password="password"
18+
username="admin",
19+
20+
password="password", # noqa: S106
2021
)
2122

2223
cls.homepage = Page.objects.get(url_path="/home/").specific
@@ -30,7 +31,9 @@ def setUpTestData(cls):
3031
cls.page.save_revision()
3132

3233
def setUp(self):
33-
self.client.login(username=self.admin_user.username, password="password")
34+
self.client.login(
35+
username=self.admin_user.username, password="password" # noqa: S106
36+
)
3437

3538
def test_view(self):
3639
self.assertEqual(PagePreview.objects.count(), 0)
@@ -117,7 +120,9 @@ class TestHeadlessRedirectMixin(TestCase):
117120
@classmethod
118121
def setUpTestData(cls):
119122
cls.admin_user = User.objects.create_superuser(
120-
username="admin", email="[email protected]", password="password"
123+
username="admin",
124+
125+
password="password", # noqa: S106
121126
)
122127

123128
cls.homepage = Page.objects.get(url_path="/home/").specific

tests/test_settings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest.mock import patch
22

33
from django.test import TestCase, override_settings
4-
54
from wagtail_headless_preview.deprecation import pending_deprecation_warning
65
from wagtail_headless_preview.settings import (
76
DEFAULTS,
@@ -68,10 +67,10 @@ def test_warning_raised_on_deprecated_setting(self):
6867
)
6968

7069
def test_runtime_error_raised_on_removed_setting(self):
71-
7270
msg = (
7371
"The 'HEADLESS_PREVIEW_CLIENT_URLS' setting has been removed. "
74-
"Please refer to the wagtail_headless_preview documentation for available settings."
72+
"Please refer to the wagtail_headless_preview documentation for "
73+
"available settings."
7574
)
7675
with self.assertRaisesMessage(RuntimeError, msg):
7776
WagtailHeadlessPreviewSettings(

0 commit comments

Comments
 (0)