Replace flake8 and isort with ruff
This commit is contained in:
parent
019e0cf431
commit
29bd939ae4
10 changed files with 26 additions and 43 deletions
|
@ -88,15 +88,10 @@ black:
|
||||||
script:
|
script:
|
||||||
- black --check .
|
- black --check .
|
||||||
|
|
||||||
isort:
|
ruff:
|
||||||
extends: .python_test_template
|
extends: .python_test_template
|
||||||
script:
|
script:
|
||||||
- isort --check .
|
- ruff check .
|
||||||
|
|
||||||
flake8:
|
|
||||||
extends: .python_test_template
|
|
||||||
script:
|
|
||||||
- flake8
|
|
||||||
|
|
||||||
mypy:
|
mypy:
|
||||||
extends: .python_test_template
|
extends: .python_test_template
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
-r requirements.txt
|
-r requirements.txt
|
||||||
|
|
||||||
honcho==1.1.0
|
honcho==1.1.0
|
||||||
flake8==5.0.4
|
|
||||||
isort==5.12.0
|
|
||||||
black==23.3.0
|
black==23.3.0
|
||||||
django-browser-reload==1.8.0
|
django-browser-reload==1.8.0
|
||||||
django-debug-toolbar
|
django-debug-toolbar
|
||||||
|
@ -10,11 +8,6 @@ types-requests==2.31.0.1
|
||||||
mypy==1.3.0
|
mypy==1.3.0
|
||||||
wagtail-factories==4.0.0
|
wagtail-factories==4.0.0
|
||||||
coverage==7.2.1
|
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
|
djlint==1.31.0
|
||||||
types-pyyaml==6.0.12.9
|
types-pyyaml==6.0.12.9
|
||||||
|
ruff==0.0.278
|
||||||
|
|
5
justfile
5
justfile
|
@ -32,17 +32,16 @@ coverage:
|
||||||
coverage html
|
coverage html
|
||||||
|
|
||||||
format:
|
format:
|
||||||
|
ruff check . --fix
|
||||||
black .
|
black .
|
||||||
isort .
|
|
||||||
djlint website/ --reformat
|
djlint website/ --reformat
|
||||||
npm run format
|
npm run format
|
||||||
|
|
||||||
lint: lint_python lint_node
|
lint: lint_python lint_node
|
||||||
|
|
||||||
lint_python:
|
lint_python:
|
||||||
|
ruff check .
|
||||||
black --check .
|
black --check .
|
||||||
isort --check .
|
|
||||||
flake8
|
|
||||||
mypy . --show-error-codes
|
mypy . --show-error-codes
|
||||||
djlint website/ --lint --check
|
djlint website/ --lint --check
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,6 @@ custom_blocks="cache"
|
||||||
[tool.djlint.per-file-ignores]
|
[tool.djlint.per-file-ignores]
|
||||||
"_snippet_link.html" = "H025"
|
"_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]
|
[tool.mypy]
|
||||||
no_implicit_optional = true
|
no_implicit_optional = true
|
||||||
warn_unused_ignores = true
|
warn_unused_ignores = true
|
||||||
|
@ -42,3 +34,10 @@ exclude_lines = [
|
||||||
omit = [
|
omit = [
|
||||||
"*/migrations/*",
|
"*/migrations/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
select = ["E", "F", "I", "W", "N", "B", "A", "C4", "T20", "DJ"]
|
||||||
|
ignore = ["E501", "DJ008"]
|
||||||
|
|
||||||
|
[tool.ruff.per-file-ignores]
|
||||||
|
"*/migrations/*" = ["N806"]
|
||||||
|
|
|
@ -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
|
|
|
@ -3,9 +3,8 @@ from typing import Any, Optional, Type
|
||||||
|
|
||||||
from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter
|
from django.contrib.humanize.templatetags.humanize import NaturalTimeFormatter
|
||||||
from django.contrib.syndication.views import Feed
|
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 Page as PaginatorPage
|
||||||
from django.core.paginator import Paginator
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.http.response import Http404, HttpResponse, HttpResponseBadRequest
|
from django.http.response import Http404, HttpResponse, HttpResponseBadRequest
|
||||||
|
@ -48,7 +47,7 @@ class BasePage(Page):
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
@classproperty
|
@classproperty
|
||||||
def body_class(cls) -> str:
|
def body_class(cls) -> str: # noqa: N805
|
||||||
return "page-" + slugify(cls.__name__)
|
return "page-" + slugify(cls.__name__)
|
||||||
|
|
||||||
def get_parent_pages(self) -> PageQuerySet:
|
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)
|
paginator = Paginator(self.get_listing_pages(), per_page=self.PAGE_SIZE)
|
||||||
try:
|
try:
|
||||||
return paginator.page(self.serializer.validated_data["page"])
|
return paginator.page(self.serializer.validated_data["page"])
|
||||||
except EmptyPage:
|
except EmptyPage as e:
|
||||||
raise Http404
|
raise Http404 from e
|
||||||
|
|
||||||
def get_context(self, request: HttpRequest) -> dict:
|
def get_context(self, request: HttpRequest) -> dict:
|
||||||
context = super().get_context(request)
|
context = super().get_context(request)
|
||||||
|
|
|
@ -19,7 +19,7 @@ def get_linguist_colours() -> dict[str, str]:
|
||||||
linguist_data = yaml.safe_load(response.text)
|
linguist_data = yaml.safe_load(response.text)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
language.lower(): l["color"]
|
language.lower(): data["color"]
|
||||||
for language, l in linguist_data.items()
|
for language, data in linguist_data.items()
|
||||||
if l.get("color")
|
if data.get("color")
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ class UnsplashPhotoCreateView(CreateView):
|
||||||
"""
|
"""
|
||||||
Modify form class to validate unsplash id and save data to model1
|
Modify form class to validate unsplash id and save data to model1
|
||||||
"""
|
"""
|
||||||
EditHandlerForm: Type[
|
EditHandlerForm: Type[ # noqa: N806
|
||||||
WagtailAdminModelForm
|
WagtailAdminModelForm
|
||||||
] = self.edit_handler.get_form_class()
|
] = self.edit_handler.get_form_class()
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class UnsplashPhotoCreateView(CreateView):
|
||||||
cleaned_data["unsplash_id"]
|
cleaned_data["unsplash_id"]
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise ValidationError(str(e))
|
raise ValidationError(str(e)) from e
|
||||||
|
|
||||||
def save(self, commit: bool = True) -> UnsplashPhoto:
|
def save(self, commit: bool = True) -> UnsplashPhoto:
|
||||||
self.instance.data = self._unsplash_photo_data
|
self.instance.data = self._unsplash_photo_data
|
||||||
|
|
|
@ -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
|
# 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()
|
results.object_list = results.object_list.get_queryset().specific()
|
||||||
|
|
||||||
except EmptyPage:
|
except EmptyPage as e:
|
||||||
raise Http404
|
raise Http404 from e
|
||||||
|
|
||||||
context["results"] = results
|
context["results"] = results
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ from website.utils.queue import enqueue_or_sync
|
||||||
def refresh_cache(page_id: int) -> None:
|
def refresh_cache(page_id: int) -> None:
|
||||||
page = SpotifyPlaylistPage.objects.get(id=page_id)
|
page = SpotifyPlaylistPage.objects.get(id=page_id)
|
||||||
cache.delete(page.playlist_cache_key)
|
cache.delete(page.playlist_cache_key)
|
||||||
page.playlist_data # Prime cache
|
|
||||||
|
# Prime cache
|
||||||
|
page.playlist_data # noqa: B018
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
Loading…
Reference in a new issue