Replace flake8 and isort with ruff

This commit is contained in:
Jake Howard 2023-07-15 15:10:05 +01:00
parent 019e0cf431
commit 29bd939ae4
Signed by: jake
GPG Key ID: 57AFB45680EDD477
10 changed files with 26 additions and 43 deletions

View File

@ -88,15 +88,10 @@ black:
script:
- black --check .
isort:
ruff:
extends: .python_test_template
script:
- isort --check .
flake8:
extends: .python_test_template
script:
- flake8
- ruff check .
mypy:
extends: .python_test_template

View File

@ -1,8 +1,6 @@
-r requirements.txt
honcho==1.1.0
flake8==5.0.4
isort==5.12.0
black==23.3.0
django-browser-reload==1.8.0
django-debug-toolbar
@ -10,11 +8,6 @@ types-requests==2.31.0.1
mypy==1.3.0
wagtail-factories==4.0.0
coverage==7.2.1
flake8-bugbear==22.12.6
flake8-builtins==2.1.0
flake8-comprehensions==3.10.0
flake8-mutable==1.2.0
flake8-print==5.0.0
flake8-tuple==0.4.1
djlint==1.31.0
types-pyyaml==6.0.12.9
ruff==0.0.278

View File

@ -32,17 +32,16 @@ coverage:
coverage html
format:
ruff check . --fix
black .
isort .
djlint website/ --reformat
npm run format
lint: lint_python lint_node
lint_python:
ruff check .
black --check .
isort --check .
flake8
mypy . --show-error-codes
djlint website/ --lint --check

View File

@ -12,14 +12,6 @@ custom_blocks="cache"
[tool.djlint.per-file-ignores]
"_snippet_link.html" = "H025"
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
skip_glob = "env/*"
[tool.mypy]
no_implicit_optional = true
warn_unused_ignores = true
@ -42,3 +34,10 @@ exclude_lines = [
omit = [
"*/migrations/*",
]
[tool.ruff]
select = ["E", "F", "I", "W", "N", "B", "A", "C4", "T20", "DJ"]
ignore = ["E501", "DJ008"]
[tool.ruff.per-file-ignores]
"*/migrations/*" = ["N806"]

View File

@ -1,4 +0,0 @@
# flake8 doesn't support pyproject.toml yet https://github.com/PyCQA/flake8/issues/234
[flake8]
extend_ignore=E128,E501
extend_exclude=env

View File

@ -3,9 +3,8 @@ from typing import Any, Optional, Type
from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter
from django.contrib.syndication.views import Feed
from django.core.paginator import EmptyPage
from django.core.paginator import EmptyPage, Paginator
from django.core.paginator import Page as PaginatorPage
from django.core.paginator import Paginator
from django.db import models
from django.http.request import HttpRequest
from django.http.response import Http404, HttpResponse, HttpResponseBadRequest
@ -48,7 +47,7 @@ class BasePage(Page):
abstract = True
@classproperty
def body_class(cls) -> str:
def body_class(cls) -> str: # noqa: N805
return "page-" + slugify(cls.__name__)
def get_parent_pages(self) -> PageQuerySet:
@ -225,8 +224,8 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage):
paginator = Paginator(self.get_listing_pages(), per_page=self.PAGE_SIZE)
try:
return paginator.page(self.serializer.validated_data["page"])
except EmptyPage:
raise Http404
except EmptyPage as e:
raise Http404 from e
def get_context(self, request: HttpRequest) -> dict:
context = super().get_context(request)

View File

@ -19,7 +19,7 @@ def get_linguist_colours() -> dict[str, str]:
linguist_data = yaml.safe_load(response.text)
return {
language.lower(): l["color"]
for language, l in linguist_data.items()
if l.get("color")
language.lower(): data["color"]
for language, data in linguist_data.items()
if data.get("color")
}

View File

@ -19,7 +19,7 @@ class UnsplashPhotoCreateView(CreateView):
"""
Modify form class to validate unsplash id and save data to model1
"""
EditHandlerForm: Type[
EditHandlerForm: Type[ # noqa: N806
WagtailAdminModelForm
] = self.edit_handler.get_form_class()
@ -31,7 +31,7 @@ class UnsplashPhotoCreateView(CreateView):
cleaned_data["unsplash_id"]
)
except ValueError as e:
raise ValidationError(str(e))
raise ValidationError(str(e)) from e
def save(self, commit: bool = True) -> UnsplashPhoto:
self.instance.data = self._unsplash_photo_data

View File

@ -80,8 +80,8 @@ class SearchPage(RoutablePageMixin, BaseContentPage):
# HACK: Search results aren't a queryset, so we can't call `.specific` on it. This forces it to one as efficiently as possible
results.object_list = results.object_list.get_queryset().specific()
except EmptyPage:
raise Http404
except EmptyPage as e:
raise Http404 from e
context["results"] = results

View File

@ -8,7 +8,9 @@ from website.utils.queue import enqueue_or_sync
def refresh_cache(page_id: int) -> None:
page = SpotifyPlaylistPage.objects.get(id=page_id)
cache.delete(page.playlist_cache_key)
page.playlist_data # Prime cache
# Prime cache
page.playlist_data # noqa: B018
class Command(BaseCommand):