Skip to content

Commit 7e23a86

Browse files
martin056RadoRado
authored andcommitted
Apply black and isort
1 parent 4a5b89a commit 7e23a86

Some content is hidden

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

79 files changed

+622
-964
lines changed

.github/workflows/django.yml

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ jobs:
1111
run: docker-compose run django isort styleguide_example/ --check
1212
- name: Run black
1313
run: docker-compose run django black styleguide_example/ --check
14-
- name: Run Flake8
15-
run: docker-compose run django flake8
16-
- name: Type check
17-
run: docker-compose run django mypy --config mypy.ini --cache-dir=/dev/null styleguide_example/
1814
- name: Run migrations
1915
run: docker-compose run django python manage.py migrate
2016
- name: Run tests

config/asgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.django.base')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.django.base")
1515

1616
application = get_asgi_application()

config/django/base.py

+74-77
Original file line numberDiff line numberDiff line change
@@ -12,110 +12,110 @@
1212

1313
import os
1414

15-
from config.env import env, BASE_DIR
15+
from config.env import BASE_DIR, env
1616

1717
env.read_env(os.path.join(BASE_DIR, ".env"))
1818

1919
# Quick-start development settings - unsuitable for production
2020
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = '=ug_ucl@yi6^mrcjyz%(u0%&g2adt#bz3@yos%#@*t#t!ypx=a'
23+
SECRET_KEY = "=ug_ucl@yi6^mrcjyz%(u0%&g2adt#bz3@yos%#@*t#t!ypx=a"
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

28-
ALLOWED_HOSTS = ['*']
28+
ALLOWED_HOSTS = ["*"]
2929

3030

3131
# Application definition
3232

3333
LOCAL_APPS = [
34-
'styleguide_example.core.apps.CoreConfig',
35-
'styleguide_example.common.apps.CommonConfig',
36-
'styleguide_example.tasks.apps.TasksConfig',
37-
'styleguide_example.api.apps.ApiConfig',
38-
'styleguide_example.users.apps.UsersConfig',
39-
'styleguide_example.errors.apps.ErrorsConfig',
40-
'styleguide_example.testing_examples.apps.TestingExamplesConfig',
41-
'styleguide_example.integrations.apps.IntegrationsConfig',
42-
'styleguide_example.files.apps.FilesConfig',
43-
'styleguide_example.emails.apps.EmailsConfig',
34+
"styleguide_example.core.apps.CoreConfig",
35+
"styleguide_example.common.apps.CommonConfig",
36+
"styleguide_example.tasks.apps.TasksConfig",
37+
"styleguide_example.api.apps.ApiConfig",
38+
"styleguide_example.users.apps.UsersConfig",
39+
"styleguide_example.errors.apps.ErrorsConfig",
40+
"styleguide_example.testing_examples.apps.TestingExamplesConfig",
41+
"styleguide_example.integrations.apps.IntegrationsConfig",
42+
"styleguide_example.files.apps.FilesConfig",
43+
"styleguide_example.emails.apps.EmailsConfig",
4444
]
4545

4646
THIRD_PARTY_APPS = [
47-
'rest_framework',
48-
'django_celery_results',
49-
'django_celery_beat',
50-
'django_filters',
51-
'corsheaders',
52-
'django_extensions',
53-
'rest_framework_jwt',
47+
"rest_framework",
48+
"django_celery_results",
49+
"django_celery_beat",
50+
"django_filters",
51+
"corsheaders",
52+
"django_extensions",
53+
"rest_framework_jwt",
5454
]
5555

5656
INSTALLED_APPS = [
57-
'django.contrib.admin',
58-
'django.contrib.auth',
59-
'django.contrib.contenttypes',
60-
'django.contrib.sessions',
61-
'django.contrib.messages',
57+
"django.contrib.admin",
58+
"django.contrib.auth",
59+
"django.contrib.contenttypes",
60+
"django.contrib.sessions",
61+
"django.contrib.messages",
6262
# http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
63-
'whitenoise.runserver_nostatic',
64-
'django.contrib.staticfiles',
63+
"whitenoise.runserver_nostatic",
64+
"django.contrib.staticfiles",
6565
*THIRD_PARTY_APPS,
6666
*LOCAL_APPS,
6767
]
6868

6969
MIDDLEWARE = [
70-
'django.middleware.security.SecurityMiddleware',
71-
'corsheaders.middleware.CorsMiddleware',
72-
'whitenoise.middleware.WhiteNoiseMiddleware',
73-
'django.contrib.sessions.middleware.SessionMiddleware',
74-
'django.middleware.common.CommonMiddleware',
75-
'django.middleware.csrf.CsrfViewMiddleware',
76-
'django.contrib.auth.middleware.AuthenticationMiddleware',
77-
'django.contrib.messages.middleware.MessageMiddleware',
78-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
70+
"django.middleware.security.SecurityMiddleware",
71+
"corsheaders.middleware.CorsMiddleware",
72+
"whitenoise.middleware.WhiteNoiseMiddleware",
73+
"django.contrib.sessions.middleware.SessionMiddleware",
74+
"django.middleware.common.CommonMiddleware",
75+
"django.middleware.csrf.CsrfViewMiddleware",
76+
"django.contrib.auth.middleware.AuthenticationMiddleware",
77+
"django.contrib.messages.middleware.MessageMiddleware",
78+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
7979
]
8080

81-
ROOT_URLCONF = 'config.urls'
81+
ROOT_URLCONF = "config.urls"
8282

8383
TEMPLATES = [
8484
{
85-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
86-
'DIRS': [],
87-
'APP_DIRS': True,
88-
'OPTIONS': {
89-
'context_processors': [
90-
'django.template.context_processors.debug',
91-
'django.template.context_processors.request',
92-
'django.contrib.auth.context_processors.auth',
93-
'django.contrib.messages.context_processors.messages',
85+
"BACKEND": "django.template.backends.django.DjangoTemplates",
86+
"DIRS": [],
87+
"APP_DIRS": True,
88+
"OPTIONS": {
89+
"context_processors": [
90+
"django.template.context_processors.debug",
91+
"django.template.context_processors.request",
92+
"django.contrib.auth.context_processors.auth",
93+
"django.contrib.messages.context_processors.messages",
9494
],
9595
},
9696
},
9797
]
9898

99-
WSGI_APPLICATION = 'config.wsgi.application'
99+
WSGI_APPLICATION = "config.wsgi.application"
100100

101101

102102
# Database
103103
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
104104

105105
DATABASES = {
106-
'default': env.db('DATABASE_URL', default='postgres:///styleguide_example'),
106+
"default": env.db("DATABASE_URL", default="postgres:///styleguide_example"),
107107
}
108-
DATABASES['default']['ATOMIC_REQUESTS'] = True
108+
DATABASES["default"]["ATOMIC_REQUESTS"] = True
109109

110-
if os.environ.get('GITHUB_WORKFLOW'):
110+
if os.environ.get("GITHUB_WORKFLOW"):
111111
DATABASES = {
112-
'default': {
113-
'ENGINE': 'django.db.backends.postgresql',
114-
'NAME': 'github_actions',
115-
'USER': 'postgres',
116-
'PASSWORD': 'postgres',
117-
'HOST': '127.0.0.1',
118-
'PORT': '5432',
112+
"default": {
113+
"ENGINE": "django.db.backends.postgresql",
114+
"NAME": "github_actions",
115+
"USER": "postgres",
116+
"PASSWORD": "postgres",
117+
"HOST": "127.0.0.1",
118+
"PORT": "5432",
119119
}
120120
}
121121

@@ -125,28 +125,28 @@
125125

126126
AUTH_PASSWORD_VALIDATORS = [
127127
{
128-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
128+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
129129
},
130130
{
131-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
131+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
132132
},
133133
{
134-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
134+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
135135
},
136136
{
137-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
137+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
138138
},
139139
]
140140

141-
AUTH_USER_MODEL = 'users.BaseUser'
141+
AUTH_USER_MODEL = "users.BaseUser"
142142

143143

144144
# Internationalization
145145
# https://docs.djangoproject.com/en/3.0/topics/i18n/
146146

147-
LANGUAGE_CODE = 'en-us'
147+
LANGUAGE_CODE = "en-us"
148148

149-
TIME_ZONE = 'UTC'
149+
TIME_ZONE = "UTC"
150150

151151
USE_I18N = True
152152

@@ -158,28 +158,25 @@
158158
# Static files (CSS, JavaScript, Images)
159159
# https://docs.djangoproject.com/en/3.0/howto/static-files/
160160

161-
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
162-
STATIC_URL = '/static/'
163-
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
161+
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
162+
STATIC_URL = "/static/"
163+
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
164164

165165
REST_FRAMEWORK = {
166-
'EXCEPTION_HANDLER': 'styleguide_example.api.exception_handlers.drf_default_with_modifications_exception_handler',
166+
"EXCEPTION_HANDLER": "styleguide_example.api.exception_handlers.drf_default_with_modifications_exception_handler",
167167
# 'EXCEPTION_HANDLER': 'styleguide_example.api.exception_handlers.hacksoft_proposed_exception_handler',
168-
'DEFAULT_FILTER_BACKENDS': (
169-
'django_filters.rest_framework.DjangoFilterBackend',
170-
),
171-
'DEFAULT_AUTHENTICATION_CLASSES': []
168+
"DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",),
169+
"DEFAULT_AUTHENTICATION_CLASSES": [],
172170
}
173171

174172
APP_DOMAIN = env("APP_DOMAIN", default="http://localhost:8000")
175173

176174
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
177175

176+
from config.settings.celery import * # noqa
178177
from config.settings.cors import * # noqa
178+
from config.settings.email_sending import * # noqa
179+
from config.settings.files_and_storages import * # noqa
179180
from config.settings.jwt import * # noqa
180-
from config.settings.sessions import * # noqa
181-
from config.settings.celery import * # noqa
182181
from config.settings.sentry import * # noqa
183-
184-
from config.settings.files_and_storages import * # noqa
185-
from config.settings.email_sending import * # noqa
182+
from config.settings.sessions import * # noqa

config/django/production.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
from .base import * # noqa
2-
31
from config.env import env
42

5-
DEBUG = env.bool('DJANGO_DEBUG', default=False)
3+
from .base import * # noqa
4+
5+
DEBUG = env.bool("DJANGO_DEBUG", default=False)
66

7-
SECRET_KEY = env('SECRET_KEY')
7+
SECRET_KEY = env("SECRET_KEY")
88

9-
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[])
9+
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[])
1010

1111
CORS_ALLOW_ALL_ORIGINS = False
12-
CORS_ORIGIN_WHITELIST = env.list('CORS_ORIGIN_WHITELIST', default=[])
12+
CORS_ORIGIN_WHITELIST = env.list("CORS_ORIGIN_WHITELIST", default=[])
1313

14-
SESSION_COOKIE_SECURE = env.bool('SESSION_COOKIE_SECURE', default=True)
14+
SESSION_COOKIE_SECURE = env.bool("SESSION_COOKIE_SECURE", default=True)
1515

1616
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
1717
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
1818
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
1919
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
2020
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
21-
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
22-
"SECURE_CONTENT_TYPE_NOSNIFF", default=True
23-
)
21+
SECURE_CONTENT_TYPE_NOSNIFF = env.bool("SECURE_CONTENT_TYPE_NOSNIFF", default=True)

config/django/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Based on https://www.hacksoft.io/blog/optimize-django-build-to-run-faster-on-github-actions
44

55
DEBUG = False
6-
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
6+
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
77

88
CELERY_BROKER_BACKEND = "memory"
99
CELERY_TASK_ALWAYS_EAGER = True

config/env.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from django.core.exceptions import ImproperlyConfigured
2-
31
import environ
2+
from django.core.exceptions import ImproperlyConfigured
43

54
env = environ.Env()
65

config/settings/celery.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# https://docs.celeryproject.org/en/stable/userguide/configuration.html
44

5-
CELERY_BROKER_URL = env('CELERY_BROKER_URL', default='amqp://guest:guest@localhost//')
6-
CELERY_RESULT_BACKEND = 'django-db'
5+
CELERY_BROKER_URL = env("CELERY_BROKER_URL", default="amqp://guest:guest@localhost//")
6+
CELERY_RESULT_BACKEND = "django-db"
77

8-
CELERY_TIMEZONE = 'UTC'
8+
CELERY_TIMEZONE = "UTC"
99

1010
CELERY_TASK_SOFT_TIME_LIMIT = 20 # seconds
1111
CELERT_TASK_TIME_LIMIT = 30 # seconds

config/settings/email_sending.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
from config.env import env, env_to_enum
2-
32
from styleguide_example.emails.enums import EmailSendingStrategy
43

54
# local | mailtrap
6-
EMAIL_SENDING_STRATEGY = env_to_enum(
7-
EmailSendingStrategy,
8-
env("EMAIL_SENDING_STRATEGY", default="local")
9-
)
5+
EMAIL_SENDING_STRATEGY = env_to_enum(EmailSendingStrategy, env("EMAIL_SENDING_STRATEGY", default="local"))
106

117
EMAIL_SENDING_FAILURE_TRIGGER = env.bool("EMAIL_SENDING_FAILURE_TRIGGER", default=False)
128
EMAIL_SENDING_FAILURE_RATE = env.float("EMAIL_SENDING_FAILURE_RATE", default=0.2)

config/settings/files_and_storages.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
import os
22

33
from config.env import BASE_DIR, env, env_to_enum
4+
from styleguide_example.files.enums import FileUploadStorage, FileUploadStrategy
45

5-
from styleguide_example.files.enums import FileUploadStrategy, FileUploadStorage
6-
7-
8-
FILE_UPLOAD_STRATEGY = env_to_enum(
9-
FileUploadStrategy,
10-
env("FILE_UPLOAD_STRATEGY", default="standard")
11-
)
12-
FILE_UPLOAD_STORAGE = env_to_enum(
13-
FileUploadStorage,
14-
env("FILE_UPLOAD_STORAGE", default="local")
15-
)
6+
FILE_UPLOAD_STRATEGY = env_to_enum(FileUploadStrategy, env("FILE_UPLOAD_STRATEGY", default="standard"))
7+
FILE_UPLOAD_STORAGE = env_to_enum(FileUploadStorage, env("FILE_UPLOAD_STORAGE", default="local"))
168

179
FILE_MAX_SIZE = env.int("FILE_MAX_SIZE", default=10485760) # 10 MiB
1810

@@ -24,7 +16,7 @@
2416
if FILE_UPLOAD_STORAGE == FileUploadStorage.S3:
2517
# Using django-storages
2618
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html
27-
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
19+
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
2820

2921
AWS_S3_ACCESS_KEY_ID = env("AWS_S3_ACCESS_KEY_ID")
3022
AWS_S3_SECRET_ACCESS_KEY = env("AWS_S3_SECRET_ACCESS_KEY")

config/settings/jwt.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
"JWT_RESPONSE_PAYLOAD_HANDLER": "styleguide_example.authentication.services.auth_jwt_response_payload_handler",
1818
"JWT_EXPIRATION_DELTA": datetime.timedelta(seconds=JWT_EXPIRATION_DELTA_SECONDS),
1919
"JWT_ALLOW_REFRESH": False,
20-
2120
"JWT_AUTH_COOKIE": JWT_AUTH_COOKIE,
2221
"JWT_AUTH_COOKIE_SECURE": True,
2322
"JWT_AUTH_COOKIE_SAMESITE": JWT_AUTH_COOKIE_SAMESITE,
24-
25-
"JWT_AUTH_HEADER_PREFIX": JWT_AUTH_HEADER_PREFIX
23+
"JWT_AUTH_HEADER_PREFIX": JWT_AUTH_HEADER_PREFIX,
2624
}

0 commit comments

Comments
 (0)