Skip to content

Commit 36cf100

Browse files
authored
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
1 parent e8f36b0 commit 36cf100

File tree

12 files changed

+16
-23
lines changed

12 files changed

+16
-23
lines changed

Diff for: .pre-commit-config.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ default_language_version:
22
python: python3.11
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v4.5.0
66
hooks:
77
- id: check-merge-conflict
88
- id: check-json
@@ -15,12 +15,9 @@ repos:
1515
- --autofix
1616
- id: trailing-whitespace
1717
exclude: README.md
18-
- repo: https://github.com/psf/black
19-
rev: 23.7.0
20-
hooks:
21-
- id: black
2218
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.0.283
19+
rev: v0.1.2
2420
hooks:
2521
- id: ruff
2622
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
23+
- id: ruff-format

Diff for: .ruff.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ignore = [
1313
"B017", # pytest.raises(Exception) should be considered evil
1414
"B028", # warnings.warn called without an explicit stacklevel keyword argument
1515
"B904", # check for raise statements in exception handlers that lack a from clause
16+
"W191", # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
1617
]
1718

1819
exclude = [
@@ -29,5 +30,4 @@ target-version = "py38"
2930
[isort]
3031
known-first-party = ["graphene", "graphene-django"]
3132
known-local-folder = ["cookbook"]
32-
force-wrap-aliases = true
3333
combine-as-imports = true

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tests:
1414

1515
.PHONY: format ## Format code
1616
format:
17-
black graphene_django examples setup.py
17+
ruff format graphene_django examples setup.py
1818

1919
.PHONY: lint ## Lint code
2020
lint:

Diff for: graphene_django/fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def connection_resolver(
194194
enforce_first_or_last,
195195
root,
196196
info,
197-
**args
197+
**args,
198198
):
199199
first = args.get("first")
200200
last = args.get("last")

Diff for: graphene_django/filter/fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(
3636
extra_filter_meta=None,
3737
filterset_class=None,
3838
*args,
39-
**kwargs
39+
**kwargs,
4040
):
4141
self._fields = fields
4242
self._provided_filterset_class = filterset_class

Diff for: graphene_django/filter/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def replace_csv_filters(filterset_class):
145145
label=filter_field.label,
146146
method=filter_field.method,
147147
exclude=filter_field.exclude,
148-
**filter_field.extra
148+
**filter_field.extra,
149149
)
150150
elif filter_type == "range":
151151
filterset_class.base_filters[name] = RangeFilter(
@@ -154,5 +154,5 @@ def replace_csv_filters(filterset_class):
154154
label=filter_field.label,
155155
method=filter_field.method,
156156
exclude=filter_field.exclude,
157-
**filter_field.extra
157+
**filter_field.extra,
158158
)

Diff for: graphene_django/forms/mutation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ def fields_for_form(form, only_fields, exclude_fields):
2323
for name, field in form.fields.items():
2424
is_not_in_only = only_fields and name not in only_fields
2525
is_excluded = (
26-
name
27-
in exclude_fields # or
26+
name in exclude_fields # or
2827
# name in already_created_fields
2928
)
3029

Diff for: graphene_django/rest_framework/mutation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init_subclass_with_meta__(
8181
convert_choices_to_enum=True,
8282
_meta=None,
8383
optional_fields=(),
84-
**options
84+
**options,
8585
):
8686
if not serializer_class:
8787
raise Exception("serializer_class is required for the SerializerMutation")

Diff for: graphene_django/rest_framework/tests/test_mutation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class Meta:
275275
result = MyMethodMutation.mutate_and_get_payload(
276276
None,
277277
mock_info(),
278-
**{"cool_name": "Narf", "last_edited": datetime.date(2020, 1, 4)}
278+
**{"cool_name": "Narf", "last_edited": datetime.date(2020, 1, 4)},
279279
)
280280

281281
assert result.errors is None

Diff for: graphene_django/types.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,8 @@ def validate_fields(type_, model, fields, only_fields, exclude_fields):
102102
if name in all_field_names:
103103
# Field is a custom field
104104
warnings.warn(
105-
(
106-
'Excluding the custom field "{field_name}" on DjangoObjectType "{type_}" has no effect. '
107-
'Either remove the custom field or remove the field from the "exclude" list.'
108-
).format(field_name=name, type_=type_)
105+
f'Excluding the custom field "{name}" on DjangoObjectType "{type_}" has no effect. '
106+
'Either remove the custom field or remove the field from the "exclude" list.'
109107
)
110108
else:
111109
if not hasattr(model, name):

Diff for: graphene_django/utils/testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def graphql_query(
6363
graphql_url,
6464
json.dumps(body),
6565
content_type="application/json",
66-
**header_params
66+
**header_params,
6767
)
6868
else:
6969
resp = client.post(

Diff for: setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727

2828
dev_requires = [
29-
"black==23.7.0",
30-
"ruff==0.0.283",
29+
"ruff==0.1.2",
3130
"pre-commit",
3231
] + tests_require
3332

0 commit comments

Comments
 (0)