From 36cf100e8bd0dbb9cf0f1aa252377acc21c54679 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Wed, 25 Oct 2023 16:33:00 +0800 Subject: [PATCH] Use ruff format to replace black (#1473) * Use ruff format to replace black * Adjust ruff config to be compatible with ruff-format https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules * Format * Replace black with ruff format in Makefile --- .pre-commit-config.yaml | 9 +++------ .ruff.toml | 2 +- Makefile | 2 +- graphene_django/fields.py | 2 +- graphene_django/filter/fields.py | 2 +- graphene_django/filter/utils.py | 4 ++-- graphene_django/forms/mutation.py | 3 +-- graphene_django/rest_framework/mutation.py | 2 +- graphene_django/rest_framework/tests/test_mutation.py | 2 +- graphene_django/types.py | 6 ++---- graphene_django/utils/testing.py | 2 +- setup.py | 3 +-- 12 files changed, 16 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5174be3..653849c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_language_version: python: python3.11 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: check-json @@ -15,12 +15,9 @@ repos: - --autofix - id: trailing-whitespace exclude: README.md -- repo: https://github.com/psf/black - rev: 23.7.0 - hooks: - - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.283 + rev: v0.1.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] + - id: ruff-format diff --git a/.ruff.toml b/.ruff.toml index b24997c..bcb85c3 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -13,6 +13,7 @@ ignore = [ "B017", # pytest.raises(Exception) should be considered evil "B028", # warnings.warn called without an explicit stacklevel keyword argument "B904", # check for raise statements in exception handlers that lack a from clause + "W191", # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules ] exclude = [ @@ -29,5 +30,4 @@ target-version = "py38" [isort] known-first-party = ["graphene", "graphene-django"] known-local-folder = ["cookbook"] -force-wrap-aliases = true combine-as-imports = true diff --git a/Makefile b/Makefile index 31e5c93..633c83f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ tests: .PHONY: format ## Format code format: - black graphene_django examples setup.py + ruff format graphene_django examples setup.py .PHONY: lint ## Lint code lint: diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 3537da3..35bd3f0 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -194,7 +194,7 @@ class DjangoConnectionField(ConnectionField): enforce_first_or_last, root, info, - **args + **args, ): first = args.get("first") last = args.get("last") diff --git a/graphene_django/filter/fields.py b/graphene_django/filter/fields.py index f6ad911..2380632 100644 --- a/graphene_django/filter/fields.py +++ b/graphene_django/filter/fields.py @@ -36,7 +36,7 @@ class DjangoFilterConnectionField(DjangoConnectionField): extra_filter_meta=None, filterset_class=None, *args, - **kwargs + **kwargs, ): self._fields = fields self._provided_filterset_class = filterset_class diff --git a/graphene_django/filter/utils.py b/graphene_django/filter/utils.py index 339bd48..9ffcc5c 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -145,7 +145,7 @@ def replace_csv_filters(filterset_class): label=filter_field.label, method=filter_field.method, exclude=filter_field.exclude, - **filter_field.extra + **filter_field.extra, ) elif filter_type == "range": filterset_class.base_filters[name] = RangeFilter( @@ -154,5 +154,5 @@ def replace_csv_filters(filterset_class): label=filter_field.label, method=filter_field.method, exclude=filter_field.exclude, - **filter_field.extra + **filter_field.extra, ) diff --git a/graphene_django/forms/mutation.py b/graphene_django/forms/mutation.py index 40d1d3c..30b9af4 100644 --- a/graphene_django/forms/mutation.py +++ b/graphene_django/forms/mutation.py @@ -23,8 +23,7 @@ def fields_for_form(form, only_fields, exclude_fields): for name, field in form.fields.items(): is_not_in_only = only_fields and name not in only_fields is_excluded = ( - name - in exclude_fields # or + name in exclude_fields # or # name in already_created_fields ) diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 47e7186..f1f1267 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -81,7 +81,7 @@ class SerializerMutation(ClientIDMutation): convert_choices_to_enum=True, _meta=None, optional_fields=(), - **options + **options, ): if not serializer_class: raise Exception("serializer_class is required for the SerializerMutation") diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 58bc4ce..17546c6 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -275,7 +275,7 @@ def test_perform_mutate_success(): result = MyMethodMutation.mutate_and_get_payload( None, mock_info(), - **{"cool_name": "Narf", "last_edited": datetime.date(2020, 1, 4)} + **{"cool_name": "Narf", "last_edited": datetime.date(2020, 1, 4)}, ) assert result.errors is None diff --git a/graphene_django/types.py b/graphene_django/types.py index 163fe3f..02b7693 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -102,10 +102,8 @@ def validate_fields(type_, model, fields, only_fields, exclude_fields): if name in all_field_names: # Field is a custom field warnings.warn( - ( - 'Excluding the custom field "{field_name}" on DjangoObjectType "{type_}" has no effect. ' - 'Either remove the custom field or remove the field from the "exclude" list.' - ).format(field_name=name, type_=type_) + f'Excluding the custom field "{name}" on DjangoObjectType "{type_}" has no effect. ' + 'Either remove the custom field or remove the field from the "exclude" list.' ) else: if not hasattr(model, name): diff --git a/graphene_django/utils/testing.py b/graphene_django/utils/testing.py index 6cd0e3b..2ca1de9 100644 --- a/graphene_django/utils/testing.py +++ b/graphene_django/utils/testing.py @@ -63,7 +63,7 @@ def graphql_query( graphql_url, json.dumps(body), content_type="application/json", - **header_params + **header_params, ) else: resp = client.post( diff --git a/setup.py b/setup.py index 51ed637..7e35a14 100644 --- a/setup.py +++ b/setup.py @@ -26,8 +26,7 @@ tests_require = [ dev_requires = [ - "black==23.7.0", - "ruff==0.0.283", + "ruff==0.1.2", "pre-commit", ] + tests_require