Skip to content

Commit 9a773b9

Browse files
authored
Use ruff in pre-commit (#1441)
* Use ruff in pre-commit * Add pyupgrade * Add isort * Add bugbear * Fix B015 Pointless comparison * Fix B026 * B018 false positive * Remove flake8 and isort config from setup.cfg * Remove black and flake8 from dev dependencies * Update black * Show list of fixes applied with autofix on * Fix typo * Add C4 flake8-comprehensions * Add ruff to dev dependencies * Fix up
1 parent 45a732f commit 9a773b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+218
-246
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ repos:
1515
- --autofix
1616
- id: trailing-whitespace
1717
exclude: README.md
18-
- repo: https://github.com/asottile/pyupgrade
19-
rev: v3.3.2
20-
hooks:
21-
- id: pyupgrade
22-
args: [--py38-plus]
2318
- repo: https://github.com/psf/black
24-
rev: 23.3.0
19+
rev: 23.7.0
2520
hooks:
2621
- id: black
27-
- repo: https://github.com/PyCQA/flake8
28-
rev: 6.0.0
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: v0.0.282
2924
hooks:
30-
- id: flake8
25+
- id: ruff
26+
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

.ruff.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
select = [
2+
"E", # pycodestyle
3+
"W", # pycodestyle
4+
"F", # pyflake
5+
"I", # isort
6+
"B", # flake8-bugbear
7+
"C4", # flake8-comprehensions
8+
"UP", # pyupgrade
9+
]
10+
11+
ignore = [
12+
"E501", # line-too-long
13+
"B017", # pytest.raises(Exception) should be considered evil
14+
"B028", # warnings.warn called without an explicit stacklevel keyword argument
15+
"B904", # check for raise statements in exception handlers that lack a from clause
16+
]
17+
18+
exclude = [
19+
"**/docs",
20+
]
21+
22+
target-version = "py38"
23+
24+
[per-file-ignores]
25+
# Ignore unused imports (F401) in these files
26+
"__init__.py" = ["F401"]
27+
"graphene_django/compat.py" = ["F401"]
28+
29+
[isort]
30+
known-first-party = ["graphene", "graphene-django"]
31+
known-local-folder = ["cookbook"]
32+
force-wrap-aliases = true
33+
combine-as-imports = true

examples/cookbook-plain/cookbook/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import cookbook.ingredients.schema
2-
import cookbook.recipes.schema
31
import graphene
4-
52
from graphene_django.debug import DjangoDebug
63

4+
import cookbook.ingredients.schema
5+
import cookbook.recipes.schema
6+
77

88
class Query(
99
cookbook.ingredients.schema.Query,

examples/cookbook-plain/cookbook/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from django.urls import path
21
from django.contrib import admin
2+
from django.urls import path
33

44
from graphene_django.views import GraphQLView
55

6-
76
urlpatterns = [
87
path("admin/", admin.site.urls),
98
path("graphql/", GraphQLView.as_view(graphiql=True)),

examples/cookbook/cookbook/ingredients/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from cookbook.ingredients.models import Category, Ingredient
21
from graphene import Node
32
from graphene_django.filter import DjangoFilterConnectionField
43
from graphene_django.types import DjangoObjectType
54

5+
from cookbook.ingredients.models import Category, Ingredient
6+
67

78
# Graphene will automatically map the Category model's fields onto the CategoryNode.
89
# This is configured in the CategoryNode's Meta class (as you can see below)

examples/cookbook/cookbook/recipes/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
class Recipe(models.Model):
77
title = models.CharField(max_length=100)
88
instructions = models.TextField()
9-
__unicode__ = lambda self: self.title
9+
10+
def __unicode__(self):
11+
return self.title
1012

1113

1214
class RecipeIngredient(models.Model):

examples/cookbook/cookbook/recipes/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from cookbook.recipes.models import Recipe, RecipeIngredient
21
from graphene import Node
32
from graphene_django.filter import DjangoFilterConnectionField
43
from graphene_django.types import DjangoObjectType
54

5+
from cookbook.recipes.models import Recipe, RecipeIngredient
6+
67

78
class RecipeNode(DjangoObjectType):
89
class Meta:

examples/cookbook/cookbook/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import cookbook.ingredients.schema
2-
import cookbook.recipes.schema
31
import graphene
4-
52
from graphene_django.debug import DjangoDebug
63

4+
import cookbook.ingredients.schema
5+
import cookbook.recipes.schema
6+
77

88
class Query(
99
cookbook.ingredients.schema.Query,

examples/cookbook/cookbook/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from graphene_django.views import GraphQLView
55

6-
76
urlpatterns = [
87
url(r"^admin/", admin.site.urls),
98
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),

examples/django_test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import sys
21
import os
2+
import sys
33

44
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
55
sys.path.insert(0, ROOT_PATH + "/examples/")

0 commit comments

Comments
 (0)