Skip to content

Commit

Permalink
Run black formatting (#668)
Browse files Browse the repository at this point in the history
* Run black format

* Update makefile

* Add black to travis build
  • Loading branch information
jkimbo committed Jun 11, 2019
1 parent 2199e92 commit 4275aba
Show file tree
Hide file tree
Showing 42 changed files with 265 additions and 381 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ matrix:
env: DJANGO=master

- python: 3.7
env: TOXENV=flake8
env: TOXENV=black,flake8

allow_failures:
- env: DJANGO=master
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tests:
py.test graphene_django --cov=graphene_django -vv

format:
black graphene_django
black --exclude "/migrations/" graphene_django examples

lint:
flake8 graphene_django
flake8 graphene_django examples
4 changes: 2 additions & 2 deletions examples/cookbook-plain/cookbook/ingredients/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@admin.register(Ingredient)
class IngredientAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'category')
list_editable = ('name', 'category')
list_display = ("id", "name", "category")
list_editable = ("name", "category")


admin.site.register(Category)
6 changes: 3 additions & 3 deletions examples/cookbook-plain/cookbook/ingredients/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class IngredientsConfig(AppConfig):
name = 'cookbook.ingredients'
label = 'ingredients'
verbose_name = 'Ingredients'
name = "cookbook.ingredients"
label = "ingredients"
verbose_name = "Ingredients"
7 changes: 5 additions & 2 deletions examples/cookbook-plain/cookbook/ingredients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

class Category(models.Model):
class Meta:
verbose_name_plural = 'Categories'
verbose_name_plural = "Categories"

name = models.CharField(max_length=100)

def __str__(self):
Expand All @@ -13,7 +14,9 @@ def __str__(self):
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField(null=True, blank=True)
category = models.ForeignKey(Category, related_name='ingredients', on_delete=models.CASCADE)
category = models.ForeignKey(
Category, related_name="ingredients", on_delete=models.CASCADE
)

def __str__(self):
return self.name
12 changes: 5 additions & 7 deletions examples/cookbook-plain/cookbook/ingredients/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ class Meta:


class Query(object):
category = graphene.Field(CategoryType,
id=graphene.Int(),
name=graphene.String())
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String())
all_categories = graphene.List(CategoryType)

ingredient = graphene.Field(IngredientType,
id=graphene.Int(),
name=graphene.String())
ingredient = graphene.Field(
IngredientType, id=graphene.Int(), name=graphene.String()
)
all_ingredients = graphene.List(IngredientType)

def resolve_all_categories(self, context):
return Category.objects.all()

def resolve_all_ingredients(self, context):
# We can easily optimize query count in the resolve method
return Ingredient.objects.select_related('category').all()
return Ingredient.objects.select_related("category").all()

def resolve_category(self, context, id=None, name=None):
if id is not None:
Expand Down
1 change: 0 additions & 1 deletion examples/cookbook-plain/cookbook/ingredients/tests.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

# Create your tests here.
1 change: 0 additions & 1 deletion examples/cookbook-plain/cookbook/ingredients/views.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

# Create your views here.
6 changes: 3 additions & 3 deletions examples/cookbook-plain/cookbook/recipes/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class RecipesConfig(AppConfig):
name = 'cookbook.recipes'
label = 'recipes'
verbose_name = 'Recipes'
name = "cookbook.recipes"
label = "recipes"
verbose_name = "Recipes"
22 changes: 14 additions & 8 deletions examples/cookbook-plain/cookbook/recipes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
class Recipe(models.Model):
title = models.CharField(max_length=100)
instructions = models.TextField()

def __str__(self):
return self.title


class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe, related_name='amounts', on_delete=models.CASCADE)
ingredient = models.ForeignKey(Ingredient, related_name='used_by', on_delete=models.CASCADE)
recipe = models.ForeignKey(Recipe, related_name="amounts", on_delete=models.CASCADE)
ingredient = models.ForeignKey(
Ingredient, related_name="used_by", on_delete=models.CASCADE
)
amount = models.FloatField()
unit = models.CharField(max_length=20, choices=(
('unit', 'Units'),
('kg', 'Kilograms'),
('l', 'Litres'),
('st', 'Shots'),
))
unit = models.CharField(
max_length=20,
choices=(
("unit", "Units"),
("kg", "Kilograms"),
("l", "Litres"),
("st", "Shots"),
),
)
9 changes: 3 additions & 6 deletions examples/cookbook-plain/cookbook/recipes/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ class Meta:


class Query(object):
recipe = graphene.Field(RecipeType,
id=graphene.Int(),
title=graphene.String())
recipe = graphene.Field(RecipeType, id=graphene.Int(), title=graphene.String())
all_recipes = graphene.List(RecipeType)

recipeingredient = graphene.Field(RecipeIngredientType,
id=graphene.Int())
recipeingredient = graphene.Field(RecipeIngredientType, id=graphene.Int())
all_recipeingredients = graphene.List(RecipeIngredientType)

def resolve_recipe(self, context, id=None, title=None):
Expand All @@ -43,5 +40,5 @@ def resolve_all_recipes(self, context):
return Recipe.objects.all()

def resolve_all_recipeingredients(self, context):
related = ['recipe', 'ingredient']
related = ["recipe", "ingredient"]
return RecipeIngredient.objects.select_related(*related).all()
1 change: 0 additions & 1 deletion examples/cookbook-plain/cookbook/recipes/tests.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

# Create your tests here.
1 change: 0 additions & 1 deletion examples/cookbook-plain/cookbook/recipes/views.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

# Create your views here.
10 changes: 6 additions & 4 deletions examples/cookbook-plain/cookbook/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from graphene_django.debug import DjangoDebug


class Query(cookbook.ingredients.schema.Query,
cookbook.recipes.schema.Query,
graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name='_debug')
class Query(
cookbook.ingredients.schema.Query,
cookbook.recipes.schema.Query,
graphene.ObjectType,
):
debug = graphene.Field(DjangoDebug, name="_debug")


schema = graphene.Schema(query=Query)
95 changes: 43 additions & 52 deletions examples/cookbook-plain/cookbook/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_$=$%eqxk$8ss4n7mtgarw^5$8^d5+c83!vwatr@i_81myb=e4'
SECRET_KEY = "_$=$%eqxk$8ss4n7mtgarw^5$8^d5+c83!vwatr@i_81myb=e4"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -32,64 +32,61 @@
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graphene_django',

'cookbook.ingredients.apps.IngredientsConfig',
'cookbook.recipes.apps.RecipesConfig',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"graphene_django",
"cookbook.ingredients.apps.IngredientsConfig",
"cookbook.recipes.apps.RecipesConfig",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

GRAPHENE = {
'SCHEMA': 'cookbook.schema.schema',
'SCHEMA_INDENT': 2,
'MIDDLEWARE': (
'graphene_django.debug.DjangoDebugMiddleware',
)
"SCHEMA": "cookbook.schema.schema",
"SCHEMA_INDENT": 2,
"MIDDLEWARE": ("graphene_django.debug.DjangoDebugMiddleware",),
}

ROOT_URLCONF = 'cookbook.urls'
ROOT_URLCONF = "cookbook.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
},
}
]

WSGI_APPLICATION = 'cookbook.wsgi.application'
WSGI_APPLICATION = "cookbook.wsgi.application"


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

Expand All @@ -99,26 +96,20 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -130,4 +121,4 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"
4 changes: 2 additions & 2 deletions examples/cookbook-plain/cookbook/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@


urlpatterns = [
path('admin/', admin.site.urls),
path('graphql/', GraphQLView.as_view(graphiql=True)),
path("admin/", admin.site.urls),
path("graphql/", GraphQLView.as_view(graphiql=True)),
]
4 changes: 2 additions & 2 deletions examples/cookbook/cookbook/ingredients/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@admin.register(Ingredient)
class IngredientAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'category')
list_editable = ('name', 'category')
list_display = ("id", "name", "category")
list_editable = ("name", "category")


admin.site.register(Category)
6 changes: 3 additions & 3 deletions examples/cookbook/cookbook/ingredients/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class IngredientsConfig(AppConfig):
name = 'cookbook.ingredients'
label = 'ingredients'
verbose_name = 'Ingredients'
name = "cookbook.ingredients"
label = "ingredients"
verbose_name = "Ingredients"
2 changes: 1 addition & 1 deletion examples/cookbook/cookbook/ingredients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __str__(self):
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField(null=True, blank=True)
category = models.ForeignKey(Category, related_name='ingredients')
category = models.ForeignKey(Category, related_name="ingredients")

def __str__(self):
return self.name
Loading

0 comments on commit 4275aba

Please sign in to comment.