Skip to content

Commit 4517e32

Browse files
authored
πŸ‘· Add pre-commit (#1336)
* πŸ”§ Add pre-commit config Similar to graphene and graphene-sqlalchemy * ⬆ Bump black * πŸ‘· Lint on CI * ⬆ Bump flake8-black * πŸ”§ Keep excluding migrations * ⬆ Bump flake8 * πŸ”§ Remove black and flake8 from tox config * ⬆ Update pre-commit versions * Upgrade syntax to python 3.7+ * Format with pre-commit dedent docs/schema.py to allow formatting * Fix tests on python 3.7
1 parent f24cbd5 commit 4517e32

Some content is hidden

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

59 files changed

+779
-244
lines changed

β€Ž.github/ISSUE_TEMPLATE/bug_report.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ a github repo, https://repl.it or similar (you can use this template as a starti
2727

2828

2929
* **Please tell us about your environment:**
30-
31-
- Version:
32-
- Platform:
30+
31+
- Version:
32+
- Platform:
3333

3434
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

β€Ž.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
run: |
1717
python -m pip install --upgrade pip
1818
pip install tox
19-
- name: Run lint πŸ’…
19+
- name: Run pre-commit πŸ’…
2020
run: tox
2121
env:
22-
TOXENV: flake8
22+
TOXENV: pre-commit

β€Ž.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default_language_version:
2+
python: python3.9
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.0
6+
hooks:
7+
- id: check-merge-conflict
8+
- id: check-json
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
exclude: ^docs/.*$
13+
- id: pretty-format-json
14+
args:
15+
- --autofix
16+
- id: trailing-whitespace
17+
exclude: README.md
18+
- repo: https://github.com/asottile/pyupgrade
19+
rev: v2.37.3
20+
hooks:
21+
- id: pyupgrade
22+
args: [--py37-plus]
23+
- repo: https://github.com/psf/black
24+
rev: 22.6.0
25+
hooks:
26+
- id: black
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 5.0.4
29+
hooks:
30+
- id: flake8

β€ŽCONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ Then to produce a HTML version of the documentation:
5959

6060
```sh
6161
make html
62-
```
62+
```

β€ŽMANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ recursive-include graphene_django/templates *
33
recursive-include graphene_django/static *
44

55
include examples/cookbook/cookbook/ingredients/fixtures/ingredients.json
6-
include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json
6+
include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json

β€ŽMakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ tests:
1313

1414
.PHONY: format ## Format code
1515
format:
16-
black --exclude "/migrations/" graphene_django examples setup.py
16+
black graphene_django examples setup.py
1717

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

β€Ždocs/schema.py

+38-41
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,57 @@
1-
import graphene
1+
import graphene
22

3-
from graphene_django.types import DjangoObjectType
3+
from graphene_django.types import DjangoObjectType
44

5-
from cookbook.ingredients.models import Category, Ingredient
5+
from cookbook.ingredients.models import Category, Ingredient
66

77

8-
class CategoryType(DjangoObjectType):
9-
class Meta:
10-
model = Category
11-
fields = '__all__'
8+
class CategoryType(DjangoObjectType):
9+
class Meta:
10+
model = Category
11+
fields = "__all__"
1212

1313

14-
class IngredientType(DjangoObjectType):
15-
class Meta:
16-
model = Ingredient
17-
fields = '__all__'
14+
class IngredientType(DjangoObjectType):
15+
class Meta:
16+
model = Ingredient
17+
fields = "__all__"
1818

1919

20-
class Query(object):
21-
category = graphene.Field(CategoryType,
22-
id=graphene.Int(),
23-
name=graphene.String())
24-
all_categories = graphene.List(CategoryType)
20+
class Query:
21+
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String())
22+
all_categories = graphene.List(CategoryType)
2523

24+
ingredient = graphene.Field(
25+
IngredientType, id=graphene.Int(), name=graphene.String()
26+
)
27+
all_ingredients = graphene.List(IngredientType)
2628

27-
ingredient = graphene.Field(IngredientType,
28-
id=graphene.Int(),
29-
name=graphene.String())
30-
all_ingredients = graphene.List(IngredientType)
29+
def resolve_all_categories(self, info, **kwargs):
30+
return Category.objects.all()
3131

32-
def resolve_all_categories(self, info, **kwargs):
33-
return Category.objects.all()
32+
def resolve_all_ingredients(self, info, **kwargs):
33+
return Ingredient.objects.all()
3434

35-
def resolve_all_ingredients(self, info, **kwargs):
36-
return Ingredient.objects.all()
35+
def resolve_category(self, info, **kwargs):
36+
id = kwargs.get("id")
37+
name = kwargs.get("name")
3738

38-
def resolve_category(self, info, **kwargs):
39-
id = kwargs.get('id')
40-
name = kwargs.get('name')
39+
if id is not None:
40+
return Category.objects.get(pk=id)
4141

42-
if id is not None:
43-
return Category.objects.get(pk=id)
42+
if name is not None:
43+
return Category.objects.get(name=name)
4444

45-
if name is not None:
46-
return Category.objects.get(name=name)
45+
return None
4746

48-
return None
47+
def resolve_ingredient(self, info, **kwargs):
48+
id = kwargs.get("id")
49+
name = kwargs.get("name")
4950

50-
def resolve_ingredient(self, info, **kwargs):
51-
id = kwargs.get('id')
52-
name = kwargs.get('name')
51+
if id is not None:
52+
return Ingredient.objects.get(pk=id)
5353

54-
if id is not None:
55-
return Ingredient.objects.get(pk=id)
54+
if name is not None:
55+
return Ingredient.objects.get(name=name)
5656

57-
if name is not None:
58-
return Ingredient.objects.get(name=name)
59-
60-
return None
57+
return None

β€Ždocs/tutorial-plain.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ Make sure the app name in ``cookbook.ingredients.apps.IngredientsConfig`` is set
8585
# cookbook/ingredients/apps.py
8686
8787
from django.apps import AppConfig
88-
89-
88+
89+
9090
class IngredientsConfig(AppConfig):
9191
default_auto_field = 'django.db.models.BigAutoField'
9292
name = 'cookbook.ingredients'
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
[{"model": "ingredients.category", "pk": 1, "fields": {"name": "Dairy"}}, {"model": "ingredients.category", "pk": 2, "fields": {"name": "Meat"}}, {"model": "ingredients.ingredient", "pk": 1, "fields": {"name": "Eggs", "notes": "Good old eggs", "category": 1}}, {"model": "ingredients.ingredient", "pk": 2, "fields": {"name": "Milk", "notes": "Comes from a cow", "category": 1}}, {"model": "ingredients.ingredient", "pk": 3, "fields": {"name": "Beef", "notes": "Much like milk, this comes from a cow", "category": 2}}, {"model": "ingredients.ingredient", "pk": 4, "fields": {"name": "Chicken", "notes": "Definitely doesn't come from a cow", "category": 2}}]
1+
[
2+
{
3+
"fields": {
4+
"name": "Dairy"
5+
},
6+
"model": "ingredients.category",
7+
"pk": 1
8+
},
9+
{
10+
"fields": {
11+
"name": "Meat"
12+
},
13+
"model": "ingredients.category",
14+
"pk": 2
15+
},
16+
{
17+
"fields": {
18+
"category": 1,
19+
"name": "Eggs",
20+
"notes": "Good old eggs"
21+
},
22+
"model": "ingredients.ingredient",
23+
"pk": 1
24+
},
25+
{
26+
"fields": {
27+
"category": 1,
28+
"name": "Milk",
29+
"notes": "Comes from a cow"
30+
},
31+
"model": "ingredients.ingredient",
32+
"pk": 2
33+
},
34+
{
35+
"fields": {
36+
"category": 2,
37+
"name": "Beef",
38+
"notes": "Much like milk, this comes from a cow"
39+
},
40+
"model": "ingredients.ingredient",
41+
"pk": 3
42+
},
43+
{
44+
"fields": {
45+
"category": 2,
46+
"name": "Chicken",
47+
"notes": "Definitely doesn't come from a cow"
48+
},
49+
"model": "ingredients.ingredient",
50+
"pk": 4
51+
}
52+
]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.9 on 2015-12-04 18:15
3-
from __future__ import unicode_literals
42

53
import django.db.models.deletion
64
from django.db import migrations, models
@@ -10,24 +8,46 @@ class Migration(migrations.Migration):
108

119
initial = True
1210

13-
dependencies = [
14-
]
11+
dependencies = []
1512

1613
operations = [
1714
migrations.CreateModel(
18-
name='Category',
15+
name="Category",
1916
fields=[
20-
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21-
('name', models.CharField(max_length=100)),
17+
(
18+
"id",
19+
models.AutoField(
20+
auto_created=True,
21+
primary_key=True,
22+
serialize=False,
23+
verbose_name="ID",
24+
),
25+
),
26+
("name", models.CharField(max_length=100)),
2227
],
2328
),
2429
migrations.CreateModel(
25-
name='Ingredient',
30+
name="Ingredient",
2631
fields=[
27-
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
28-
('name', models.CharField(max_length=100)),
29-
('notes', models.TextField()),
30-
('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='ingredients.Category')),
32+
(
33+
"id",
34+
models.AutoField(
35+
auto_created=True,
36+
primary_key=True,
37+
serialize=False,
38+
verbose_name="ID",
39+
),
40+
),
41+
("name", models.CharField(max_length=100)),
42+
("notes", models.TextField()),
43+
(
44+
"category",
45+
models.ForeignKey(
46+
on_delete=django.db.models.deletion.CASCADE,
47+
related_name="ingredients",
48+
to="ingredients.Category",
49+
),
50+
),
3151
],
3252
),
3353
]
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.9 on 2016-11-04 00:50
3-
from __future__ import unicode_literals
42

53
from django.db import migrations, models
64

75

86
class Migration(migrations.Migration):
97

108
dependencies = [
11-
('ingredients', '0001_initial'),
9+
("ingredients", "0001_initial"),
1210
]
1311

1412
operations = [
1513
migrations.AlterField(
16-
model_name='ingredient',
17-
name='notes',
14+
model_name="ingredient",
15+
name="notes",
1816
field=models.TextField(blank=True, null=True),
1917
),
2018
]

β€Žexamples/cookbook-plain/cookbook/ingredients/migrations/0003_auto_20181018_1746.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
class Migration(migrations.Migration):
77

88
dependencies = [
9-
('ingredients', '0002_auto_20161104_0050'),
9+
("ingredients", "0002_auto_20161104_0050"),
1010
]
1111

1212
operations = [
1313
migrations.AlterModelOptions(
14-
name='category',
15-
options={'verbose_name_plural': 'Categories'},
14+
name="category",
15+
options={"verbose_name_plural": "Categories"},
1616
),
1717
]

β€Žexamples/cookbook-plain/cookbook/ingredients/schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Meta:
1616
fields = "__all__"
1717

1818

19-
class Query(object):
19+
class Query:
2020
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String())
2121
all_categories = graphene.List(CategoryType)
2222

0 commit comments

Comments
Β (0)