Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: replace flake8 with ruff #1189

Merged
merged 8 commits into from
Apr 15, 2024
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
10 changes: 10 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# When making commits that are strictly formatting/style changes, add the
# commit hash here, so git blame can ignore the change.
#
# For more details, see:
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-blameignoreRevsFile

0dcb6dd5973796cf12be34fdfd9fa761a6ba22d9 # isort
ef09dbe9a03ebf4f649fd8830224a6c93ab422e7 # pep-naming
e1dad3a0ca41d3f312f5be423711f577fd804f2f # bugbear
399a7d64ddc2c2c857670c69890c24de8ba98610 # pyupgrade
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ jobs:
with:
cmd: install

- name: Run Flake8 on src
- name: Run ruff on src
run: |
poetry run flake8 --config src/.flake8 src
poetry run ruff check src

- name: Run DB migration for test
run: |
Expand Down
77 changes: 27 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 38 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,52 @@ Pillow = "10.3.0"
[tool.poetry.group.dev.dependencies]
cssselect = "1.2.0"
django-debug-toolbar = "4.3.0"
flake8 = "7.0.0"
pytest = "8.1.1"
pytest-cov = "5.0.0"
pytest-django = "4.8.0"
pytest-mock = "3.14.0"
pytest-xdist = "3.5.0"
ruff = "0.3.5"
Werkzeug = "3.0.2"


[tool.ruff]
exclude = [
".git",
"__pycache__",
"migrations"
]
line-length = 120

[tool.ruff.lint]
ignore = [
"E251",
]
select = [
"E", # pycodestyle error
"W", # pycodestyle warning
"F", # Pyflakes
"I001", # isort
"N", # pep8-naming
"B", # bugbear
"UP", # pyupgrade
]

[tool.ruff.lint.isort]
known-first-party = [
"attendee",
"ccip",
"core",
"events",
"postgres",
"proposals",
"pycontw2016",
"reviews",
"sponsors",
"users"
]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 0 additions & 4 deletions src/.flake8

This file was deleted.

1 change: 0 additions & 1 deletion src/attendee/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from attendee.api.views import AttendeeAPIView


urlpatterns = [
path('verify/', AttendeeAPIView.as_view()),
]
6 changes: 3 additions & 3 deletions src/attendee/api/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.conf import settings
from registry.helper import reg
from rest_framework import views, status
from rest_framework.response import Response
from rest_framework import status, views
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from core.authentication import TokenAuthentication
from attendee.models import Attendee
from core.authentication import TokenAuthentication


class AttendeeAPIView(views.APIView):
Expand Down
1 change: 1 addition & 0 deletions src/attendee/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from django.conf import settings
from registry.helper import reg

from attendee.models import Attendee
from core.models import Token

Expand Down
23 changes: 12 additions & 11 deletions src/ccip/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import operator
from datetime import timezone, timedelta
from datetime import timedelta, timezone

from django.http import JsonResponse
from django.templatetags.static import static
from django.utils import translation
from django.utils.encoding import force_str
from django.utils.translation import pgettext_lazy
from django.views.generic import View, TemplateView
from django.views.generic import TemplateView, View

from core.utils import TemplateExistanceStatusResponse
from core.views import IndexView
from events.models import (
CustomEvent, KeynoteEvent,
ProposedTalkEvent, ProposedTutorialEvent,
CustomEvent,
KeynoteEvent,
ProposedTalkEvent,
ProposedTutorialEvent,
SponsoredEvent,
)
from proposals.models import PrimarySpeaker
Expand Down Expand Up @@ -43,8 +45,8 @@ def _iter_translations(value):

def _transform_translatable(key, value):
data = {'id': key}
for code, value in _iter_translations(value):
data[code] = {'name': value}
for code, val in _iter_translations(value):
data[code] = {'name': val}
return data


Expand Down Expand Up @@ -75,8 +77,7 @@ def __bool__(self):

@property
def speakers(self):
for s in self._speakers:
yield s
yield from self._speakers


def _get_empty_event_info(event):
Expand Down Expand Up @@ -167,15 +168,15 @@ def _transform_session(request, event, type_key, info_getter):
for speaker in event_info.speakers
]

LOCAL_TIMEZONE = timezone(offset=timedelta(hours=8))
local_timezone = timezone(offset=timedelta(hours=8))
# Explicitly show the local timezone used by OPass(CCIP)
# to avoid iOS device showing UTC+0 time without changing it to local time
# https://github.com/CCIP-App/CCIP-iOS/issues/54
session = {
'id': f'{type_key}-{event_info.pk}',
'type': type_key,
'start': event.begin_time.value.astimezone(LOCAL_TIMEZONE).isoformat() if event.begin_time else None,
'end': event.end_time.value.astimezone(LOCAL_TIMEZONE).isoformat() if event.end_time else None,
'start': event.begin_time.value.astimezone(local_timezone).isoformat() if event.begin_time else None,
'end': event.end_time.value.astimezone(local_timezone).isoformat() if event.end_time else None,
'slide': event_info.slide_link,
'speakers': [speaker['id'] for speaker in speakers],
'tags': [tag['id'] for tag in tags],
Expand Down
5 changes: 2 additions & 3 deletions src/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import collections
import six

import pytest

import six
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.test.html import parse_html
from django.conf import settings
from rest_framework.test import APIClient

from proposals.models import TalkProposal
Expand Down
5 changes: 2 additions & 3 deletions src/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.contrib import admin
from django.conf import settings
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from registry.models import Entry
from registry.admin import EntryAdmin
from registry.models import Entry


class CurrentConferenceFilter(admin.filters.SimpleListFilter):
Expand Down
2 changes: 1 addition & 1 deletion src/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def _build_google_form_url(uid):
return 'https://docs.google.com/forms/d/e/{uid}/viewform'.format(uid=uid)
return f'https://docs.google.com/forms/d/e/{uid}/viewform'


def script_prefix(request):
Expand Down
4 changes: 2 additions & 2 deletions src/core/difftools.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def dump_equal(a, b, loa, lob, hia, hib):

def dump_delete(a, b, loa, lob, hia, hib):
for line in a[loa:hia]:
yield mark_safe('<del>{}</del>'.format(conditional_escape(line)))
yield mark_safe(f'<del>{conditional_escape(line)}</del>')


def dump_insert(a, b, loa, lob, hia, hib):
for line in b[lob:hib]:
yield mark_safe('<ins>{}</ins>'.format(conditional_escape(line)))
yield mark_safe(f'<ins>{conditional_escape(line)}</ins>')


BLOCK_HANDLERS = {
Expand Down
3 changes: 1 addition & 2 deletions src/core/middlewares.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import re

from django.conf import settings
from django.urls import get_script_prefix
from django.http import HttpResponseRedirect

from django.urls import get_script_prefix

# Matches things like
# /en
Expand Down
8 changes: 4 additions & 4 deletions src/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from django.utils.translation import gettext_lazy as _

from .choices import (
ATTEND_IN_PERSON,
CATEGORY_CHOICES,
LANGUAGE_CHOICES,
LIVE_STREAM_POLICY_CHOICES,
LIVING_IN_TAIWAN_CHOICES,
PYTHON_LVL_CHOICES,
RECORDING_POLICY_CHOICES,
LIVING_IN_TAIWAN_CHOICES,
LIVE_STREAM_POLICY_CHOICES,
REFERRING_POLICY_CHOICES,
ATTEND_IN_PERSON,
)
from .validators import EAWMaxLengthValidator

Expand Down Expand Up @@ -224,7 +224,7 @@ class Meta:
def save(self, *args, **kwargs):
if not self.key:
self.key = self.generate_key()
return super(Token, self).save(*args, **kwargs)
return super().save(*args, **kwargs)

@classmethod
def generate_key(cls):
Expand Down
3 changes: 1 addition & 2 deletions src/core/templatetags/i18n_plus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.urls import get_script_prefix
from django.template import Library

from django.urls import get_script_prefix

register = Library()

Expand Down
1 change: 0 additions & 1 deletion src/core/templatetags/pycontw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.template import Library


register = Library()


Expand Down
1 change: 0 additions & 1 deletion src/core/tests/test_middlewares.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from django.test import override_settings


Expand Down
Loading
Loading