Skip to content

Commit

Permalink
Upgrade ruff and replace black with ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
jsma committed Nov 11, 2023
1 parent 9349e2a commit 8ae8f80
Show file tree
Hide file tree
Showing 63 changed files with 55 additions and 137 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
paths:
- .venv
- run: pipenv run ruff check .
- run: pipenv run black --target-version py38 --check --diff .
- run: pipenv run semgrep --config .semgrep.yml --error .
- run: git ls-files '*.html' | xargs pipenv run djhtml --check
- run: pipenv run curlylint --parse-only wagtail
Expand Down
10 changes: 2 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ default_language_version:
node: system
python: python3
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3
args: ['--target-version', 'py38']

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.290'
rev: 'v0.1.5'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
help:
@echo "clean-pyc - remove Python file artifacts"
@echo "develop - install development dependencies"
@echo "lint - check style with black, ruff, sort python with ruff, indent html, and lint frontend css/js"
@echo "lint - check style with ruff, sort python with ruff, indent html, and lint frontend css/js"
@echo "format - enforce a consistent code style across the codebase, sort python files with ruff and fix frontend css/js"
@echo "test - run tests"
@echo "coverage - check code coverage"
Expand All @@ -18,7 +18,6 @@ develop: clean-pyc
npm install --no-save && npm run build

lint-server:
black --target-version py38 --check --diff .
ruff check .
curlylint --parse-only wagtail
git ls-files '*.html' | xargs djhtml --check
Expand All @@ -35,8 +34,8 @@ lint-docs:
lint: lint-server lint-client lint-docs

format-server:
black --target-version py38 .
ruff check . --fix
ruff format .
git ls-files '*.html' | xargs djhtml

format-client:
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-translator-credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_language_name(locale_string):
]
language_names.sort()

for (language_name, locale) in language_names:
for language_name, locale in language_names:
print(f"{language_name} - {locale}") # noqa: T201
print("-----") # noqa: T201
for author in sorted(authors_by_locale[locale]):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@
"django-pattern-library>=0.7",
# For coverage and PEP8 linting
"coverage>=3.7.0",
"black==22.3.0",
"doc8==0.8.1",
"ruff==0.0.290",
"ruff==0.1.5",
# For enforcing string formatting mechanism in source files
"semgrep==1.40.0",
# For templates linting
Expand Down
1 change: 0 additions & 1 deletion wagtail/actions/copy_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def _copy_page(
)
# Save copied child objects and run process_child_object on them if we need to
for (child_relation, old_pk), child_object in child_object_map.items():

if self.process_child_object:
self.process_child_object(
specific_page, page_copy, child_relation, child_object
Expand Down
1 change: 0 additions & 1 deletion wagtail/actions/create_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def _create_alias(
reset_translation_key,
_mpnode_attrs,
):

specific_page = page.specific

# FIXME: Switch to the same fields that are excluded from copy
Expand Down
1 change: 0 additions & 1 deletion wagtail/actions/unpublish_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def execute(self, skip_permission_checks=False):
super().execute(skip_permission_checks)

if self.include_descendants:

for live_descendant_page in (
self.object.get_descendants()
.live()
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def reject_request(request):

def require_admin_access(view_func):
def decorated_view(request, *args, **kwargs):

user = request.user

if user.is_anonymous:
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/forms/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ def as_admin_panel(self):
def collection_member_permission_formset_factory(
model, permission_types, template, default_prefix=None
):

permission_queryset = Permission.objects.filter(
content_type__app_label=model._meta.app_label,
codename__in=[
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/forms/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(self, *args, **kwargs):
self.widget.free_tagging = self.free_tagging

def clean(self, value):

value = super().clean(value)

max_tag_length = self.tag_model.name.field.max_length
Expand Down
3 changes: 0 additions & 3 deletions wagtail/admin/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def send_notification(recipient_users, notification, extra_context):
connection = get_connection()

with OpenedConnection(connection) as open_connection:

# Send emails
sent_count = 0
for recipient in email_recipients:
Expand Down Expand Up @@ -229,12 +228,10 @@ def get_template_set(self, instance, **kwargs):
}

def send_emails(self, template_set, context, recipients, **kwargs):

connection = get_connection()
sent_count = 0
try:
with OpenedConnection(connection) as open_connection:

# Send emails
for recipient in recipients:
# update context with this recipient
Expand Down
4 changes: 1 addition & 3 deletions wagtail/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# management command.
class Admin(Model):
class Meta:
default_permissions = (
[]
) # don't create the default add / change / delete / view perms
default_permissions = [] # don't create the default add / change / delete / view perms
permissions = [
("access_admin", "Can access Wagtail admin"),
]
Expand Down
8 changes: 3 additions & 5 deletions wagtail/admin/panels/field_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ def format_value_for_display(self, value):
labels = dict(choices)
display_values = [
str(labels.get(v, v)) # Use raw value if no match found
for v in (
for v in
(
# Account for single AND multiple choice fields
tuple(value)
if isinstance(value, (list, tuple))
else (value,)
tuple(value) if isinstance(value, (list, tuple)) else (value,)
)
]
return ", ".join(display_values)
Expand Down Expand Up @@ -275,7 +274,6 @@ def get_context_data(self, parent_context=None):
return context

def get_editable_context_data(self):

widget_described_by_ids = []
help_text_id = "%s-helptext" % self.prefix
error_message_id = "%s-errors" % self.prefix
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/panels/title_field_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def clone_kwargs(self):
}

class BoundPanel(FieldPanel.BoundPanel):

apply_actions = [
"focus->w-sync#check",
"blur->w-sync#apply",
Expand Down
4 changes: 1 addition & 3 deletions wagtail/admin/templatetags/wagtailadmin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ def test_page_is_public(context, page):
"request"
].all_page_view_restriction_paths = PageViewRestriction.objects.select_related(
"page"
).values_list(
"page__path", flat=True
)
).values_list("page__path", flat=True)

is_private = any(
page.path.startswith(restricted_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class TestBulkActionDispatcher(WagtailTestUtils, TestCase):
def setUp(self):

# Login
self.user = self.login()

Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/tests/pages/test_edit_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ def hook_func(request, page):

def test_override_default_action_menu_item(self):
def hook_func(menu_items, request, context):
for (index, item) in enumerate(menu_items):
for index, item in enumerate(menu_items):
if item.name == "action-publish":
# move to top of list
menu_items.pop(index)
Expand Down
3 changes: 0 additions & 3 deletions wagtail/admin/tests/test_edit_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,6 @@ def test_form(self):
self.assertEqual(replies_formset.forms[0].for_user, self.commenting_user)

def test_comment_form_validation(self):

form = self.EventPageForm(
{
"comments-TOTAL_FORMS": 2,
Expand Down Expand Up @@ -1872,7 +1871,6 @@ def test_comment_resolve(self):
)

def test_comment_reply_form_validation(self):

form = self.EventPageForm(
{
"comments-TOTAL_FORMS": 1,
Expand Down Expand Up @@ -2378,7 +2376,6 @@ def test_targets_override_with_multiple_fields(self):
self.assertEqual(attrs["data-w-sync-target-value"], "#id_cost, #id_location")

def test_classname_override(self):

html = self.get_edit_handler_html(
ObjectList(
[TitleFieldPanel("title", classname="super-title"), FieldPanel("slug")]
Expand Down
2 changes: 0 additions & 2 deletions wagtail/admin/tests/test_reports_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def test_get_with_no_permissions(self):
self.assertRedirects(response, reverse("wagtailadmin_home"))

def test_csv_export(self):

self.page = Page.objects.first()
self.page.locked = True
self.page.locked_by = self.user
Expand Down Expand Up @@ -141,7 +140,6 @@ def test_csv_export(self):
)

def test_xlsx_export(self):

self.page = Page.objects.first()
self.page.locked = True
self.page.locked_by = self.user
Expand Down
3 changes: 0 additions & 3 deletions wagtail/admin/tests/test_views_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class TestGenericIndexView(WagtailTestUtils, TestCase):

fixtures = ["test.json"]

def get(self, params={}):
Expand All @@ -26,7 +25,6 @@ def test_non_integer_primary_key(self):


class TestGenericEditView(WagtailTestUtils, TestCase):

fixtures = ["test.json"]

def get(self, object_pk, params={}):
Expand Down Expand Up @@ -63,7 +61,6 @@ def test_using_quote_in_delete_url(self):


class TestGenericDeleteView(WagtailTestUtils, TestCase):

fixtures = ["test.json"]

def get(self, object_pk, params={}):
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/tests/ui/test_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_adapt_with_optional_parameters(self):
)

def test_adapt_with_deprecated_classnames(self):

with self.assertWarnsRegex(
RemovedInWagtail70Warning,
"The `classnames` kwarg for sidebar LinkMenuItem is deprecated - use `classname` instead.",
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/userbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AdminItem(BaseItem):
template = "wagtailadmin/userbar/item_admin.html"

def render(self, request):

# Don't render if user doesn't have permission to access the admin area
if not request.user.has_perm("wagtailadmin.access_admin"):
return ""
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/views/generic/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PermissionCheckedMixin:

def dispatch(self, request, *args, **kwargs):
if self.permission_policy is not None:

if self.permission_required is not None:
if not self.user_has_permission(self.permission_required):
raise PermissionDenied
Expand Down
1 change: 0 additions & 1 deletion wagtail/admin/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def get_context_data(self, parent_context):


class HomeView(WagtailAdminTemplateMixin, TemplateView):

template_name = "wagtailadmin/home.html"
page_title = gettext_lazy("Dashboard")

Expand Down
2 changes: 1 addition & 1 deletion wagtail/bin/wagtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def run(
checked_file_count = 0
changed_file_count = 0

for (dirpath, dirnames, filenames) in os.walk(root_path):
for dirpath, dirnames, filenames in os.walk(root_path):
dirpath_with_slash = os.path.abspath(dirpath) + os.sep
if any(
dirpath_with_slash.startswith(ignored_dir)
Expand Down
1 change: 0 additions & 1 deletion wagtail/blocks/field_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ def __init__(
validators=(),
**kwargs,
):

self._required = required
self._default = default
self.search_index = search_index
Expand Down
6 changes: 2 additions & 4 deletions wagtail/blocks/struct_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ def value_omitted_from_data(self, data, files, prefix):
)

def clean(self, value):
result = (
[]
) # build up a list of (name, value) tuples to be passed to the StructValue constructor
result = [] # build up a list of (name, value) tuples to be passed to the StructValue constructor
errors = {}
for name, val in value.items():
try:
Expand All @@ -180,7 +178,7 @@ def to_python(self, value):
child_block.to_python(value[name])
if name in value
else child_block.get_default()
)
),
# NB the result of get_default is NOT passed through to_python, as it's expected
# to be in the block's native type already
)
Expand Down
1 change: 0 additions & 1 deletion wagtail/contrib/forms/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ def test_post_valid_form(self):

class TestFormPageWithCustomFormBuilder(WagtailTestUtils, TestCase):
def setUp(self):

home_page = Page.objects.get(url_path="/home/")
form_page = home_page.add_child(
instance=FormPageWithCustomFormBuilder(
Expand Down
2 changes: 0 additions & 2 deletions wagtail/contrib/forms/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,6 @@ class TestDuplicateFormFieldLabels(WagtailTestUtils, TestCase):
fixtures = ["test.json"]

def setUp(self):

self.login(username="superuser", password="password")
# Find root page
self.root_page = Page.objects.get(id=2)
Expand Down Expand Up @@ -1759,7 +1758,6 @@ def test_rename_existing_field_and_add_new_field_with_clashing_clean_name(


class TestPreview(WagtailTestUtils, TestCase):

post_data = {
"title": "Form page!",
"content": "Some content",
Expand Down
2 changes: 0 additions & 2 deletions wagtail/contrib/frontend_cache/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ def _purge_content(self, paths):

class AzureFrontDoorBackend(AzureBaseBackend):
def __init__(self, params):

super().__init__(params)
try:
self._front_door_name = params.pop("FRONT_DOOR_NAME")
Expand Down Expand Up @@ -372,7 +371,6 @@ def _make_purge_call(self, client, paths):

class AzureCdnBackend(AzureBaseBackend):
def __init__(self, params):

super().__init__(params)
try:
self._cdn_profile_name = params.pop("CDN_PROFILE_NAME")
Expand Down
Loading

0 comments on commit 8ae8f80

Please sign in to comment.