Skip to content

Commit

Permalink
Add pyproject.toml and run black on backend folder
Browse files Browse the repository at this point in the history
  • Loading branch information
FPiety0521 authored and FPiety0521 committed Feb 3, 2020
1 parent 0e6736d commit 3b62a83
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 251 deletions.
62 changes: 62 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
amqp = "==2.5.2"
backcall = "==0.1.0"
billiard = "==3.6.2.0"
brotlipy = "==0.7.0"
celery = {extras = ["redis"],version = "==4.4.0"}
certifi = "==2019.11.28"
cffi = "==1.13.2"
decorator = "==4.4.1"
defusedxml = "==0.6.0"
diff-match-patch = "==20181111"
dj-database-url = "==0.5.0"
django-import-export = "==2.0.1"
django-js-reverse = "==0.9.1"
django-log-request-id = "==1.4.1"
django-model-utils = "==4.0.0"
django-webpack-loader = "==0.6.0"
django = "==2.2.9"
et-xmlfile = "==1.0.1"
gunicorn = "==20.0.4"
ipython-genutils = "==0.2.0"
ipython = "==7.12.0"
jdcal = "==1.4.1"
jedi = "==0.16.0"
kombu = "==4.6.7"
markuppy = "==1.14"
odfpy = "==1.4.1"
openpyxl = "==3.0.3"
parso = "==0.6.0"
pexpect = "==4.8.0"
pickleshare = "==0.7.5"
prompt-toolkit = "==3.0.3"
psutil = "==5.6.7"
psycopg2 = "==2.8.4"
ptyprocess = "==0.6.0"
pycparser = "==2.19"
pygments = "==2.5.2"
python-decouple = "==3.3"
pytz = "==2019.3"
pyyaml = "==5.3"
redis = "==3.4.1"
sentry-sdk = "==0.14.1"
six = "==1.14.0"
sqlparse = "==0.3.0"
tablib = "==0.14.0"
traitlets = "==4.3.3"
urllib3 = "==1.25.8"
vine = "==1.3.0"
wcwidth = "==0.1.8"
whitenoise = "==5.0.1"
xlrd = "==1.2.0"
xlwt = "==1.3.0"

[requires]
python_version = "3.8"
8 changes: 2 additions & 6 deletions backend/common/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@


def sentry_dsn(request):
return {
'SENTRY_DSN': settings.SENTRY_DSN
}
return {"SENTRY_DSN": settings.SENTRY_DSN}


def commit_sha(request):
return {
'COMMIT_SHA': settings.COMMIT_SHA
}
return {"COMMIT_SHA": settings.COMMIT_SHA}
4 changes: 2 additions & 2 deletions backend/common/management/commands/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def restart_celery():
for proc in psutil.process_iter():
if proc.username() != getpass.getuser(): # skip processes not owned by user
continue
if proc.name() != 'celery':
if proc.name() != "celery":
continue
# SIGTERM should only be sent to parent process, never to children processes
# see: https://github.com/celery/celery/issues/2700#issuecomment-259716123
Expand All @@ -28,5 +28,5 @@ def restart_celery():

class Command(BaseCommand):
def handle(self, *args, **kwargs):
print('Starting celery worker with autoreload')
print("Starting celery worker with autoreload")
run_with_reloader(restart_celery)
23 changes: 12 additions & 11 deletions backend/common/management/commands/has_missing_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ class Command(BaseCommand):
(not necessaily applied though)
Based on: https://gist.github.com/nealtodd/a8f87b0d95e73eb482c5
"""

help = "Detect if any apps have missing migration files"

def add_arguments(self, parser):
parser.add_argument(
'--ignore',
action='store',
nargs='+',
dest='ignore',
"--ignore",
action="store",
nargs="+",
dest="ignore",
default=[],
help="Comma separated list of apps to ignore missing migration files. "
"Useful for specifying third-party ones here.")
"Useful for specifying third-party ones here.",
)

def handle(self, *args, **options):
changed = set()
Expand All @@ -39,17 +41,16 @@ def handle(self, *args, **options):
sys.exit("Unable to check migrations: cannot connect to database\n")

autodetector = MigrationAutodetector(
executor.loader.project_state(),
ProjectState.from_apps(apps),
executor.loader.project_state(), ProjectState.from_apps(apps),
)
changed.update(autodetector.changes(graph=executor.loader.graph).keys())

changed -= set(options['ignore'])
changed -= set(options["ignore"])

if changed:
sys.exit(
"Apps with model changes but no corresponding migration file: %(changed)s\n" % {
'changed': list(changed)
})
"Apps with model changes but no corresponding migration file: %(changed)s\n"
% {"changed": list(changed)}
)
else:
sys.stdout.write("All migration files present\n")
4 changes: 2 additions & 2 deletions backend/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class IndexedTimeStampedModel(models.Model):
created = AutoCreatedField(_('created'), db_index=True)
modified = AutoLastModifiedField(_('modified'), db_index=True)
created = AutoCreatedField(_("created"), db_index=True)
modified = AutoLastModifiedField(_("modified"), db_index=True)

class Meta:
abstract = True
7 changes: 2 additions & 5 deletions backend/common/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@


class TestCaseUtils(TestCase):

def setUp(self):
self._user_password = '123456'
self.user = mommy.prepare('users.User', email='[email protected]')
self._user_password = "123456"
self.user = mommy.prepare("users.User", email="[email protected]")
self.user.set_password(self._user_password)
self.user.save()

Expand Down Expand Up @@ -53,14 +52,12 @@ def assertResponse404(self, response):


class TestGetRequiresAuthenticatedUser:

def test_get_requires_authenticated_user(self):
response = self.client.get(self.view_url)
self.assertResponse403(response)


class TestAuthGetRequestSuccess:

def test_auth_get_success(self):
response = self.auth_client.get(self.view_url)
self.assertResponse200(response)
2 changes: 1 addition & 1 deletion backend/exampleapp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@


class ExampleappConfig(AppConfig):
name = 'exampleapp'
name = "exampleapp"
18 changes: 11 additions & 7 deletions backend/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@


if __name__ == "__main__":
settings_module = config('DJANGO_SETTINGS_MODULE', default=None)
settings_module = config("DJANGO_SETTINGS_MODULE", default=None)

if sys.argv[1] == 'test':
if sys.argv[1] == "test":
if settings_module:
print("Ignoring config('DJANGO_SETTINGS_MODULE') because it's test. "
"Using '{{project_name}}.settings.test'")
print(
"Ignoring config('DJANGO_SETTINGS_MODULE') because it's test. "
"Using '{{project_name}}.settings.test'"
)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings.test")
else:
if settings_module is None:
print("Error: no DJANGO_SETTINGS_MODULE found. Will NOT start devserver. "
"Remember to create .env file at project root. "
"Check README for more info.")
print(
"Error: no DJANGO_SETTINGS_MODULE found. Will NOT start devserver. "
"Remember to create .env file at project root. "
"Check README for more info."
)
sys.exit(1)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

Expand Down
5 changes: 3 additions & 2 deletions backend/project_name/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

from .celerybeat_schedule import CELERYBEAT_SCHEDULE


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings.local")

app = Celery('{{project_name}}_tasks')
app.config_from_object('django.conf:settings', namespace='CELERY')
app = Celery("{{project_name}}_tasks")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])
app.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE)
5 changes: 1 addition & 4 deletions backend/project_name/celerybeat_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@

CELERYBEAT_SCHEDULE = {
# Internal tasks
'clearsessions': {
'schedule': crontab(hour=3, minute=0),
'task': 'users.tasks.clearsessions'
},
"clearsessions": {"schedule": crontab(hour=3, minute=0), "task": "users.tasks.clearsessions"},
}
116 changes: 51 additions & 65 deletions backend/project_name/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,108 +17,94 @@ def base_dir_join(*args):

DEBUG = True

ADMINS = (
('Admin', '[email protected]'),
)
ADMINS = (("Admin", "[email protected]"),)

AUTH_USER_MODEL = 'users.User'
AUTH_USER_MODEL = "users.User"

ALLOWED_HOSTS = []

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

'django_js_reverse',
'webpack_loader',
'import_export',

'common',
'users',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_js_reverse",
"webpack_loader",
"import_export",
"common",
"users",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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",
"whitenoise.middleware.WhiteNoiseMiddleware",
"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",
]

ROOT_URLCONF = '{{project_name}}.urls'
ROOT_URLCONF = "{{project_name}}.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [base_dir_join('templates')],
'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',
'common.context_processors.sentry_dsn',
'common.context_processors.commit_sha',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [base_dir_join("templates")],
"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",
"common.context_processors.sentry_dsn",
"common.context_processors.commit_sha",
],
},
},
]

WSGI_APPLICATION = '{{project_name}}.wsgi.application'
WSGI_APPLICATION = "{{project_name}}.wsgi.application"

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",},
]

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

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATICFILES_DIRS = (
base_dir_join('../frontend'),
)
STATICFILES_DIRS = (base_dir_join("../frontend"),)

# Webpack
WEBPACK_LOADER = {
'DEFAULT': {
'CACHE': False, # on DEBUG should be False
'STATS_FILE': base_dir_join('../webpack-stats.json'),
'POLL_INTERVAL': 0.1,
'IGNORE': ['.+\.hot-update.js', '.+\.map']
"DEFAULT": {
"CACHE": False, # on DEBUG should be False
"STATS_FILE": base_dir_join("../webpack-stats.json"),
"POLL_INTERVAL": 0.1,
"IGNORE": [".+\.hot-update.js", ".+\.map"],
}
}

# Celery
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_ACKS_LATE = True

# Sentry
SENTRY_DSN = config('SENTRY_DSN', default='')
COMMIT_SHA = config('HEROKU_SLUG_COMMIT', default='')
SENTRY_DSN = config("SENTRY_DSN", default="")
COMMIT_SHA = config("HEROKU_SLUG_COMMIT", default="")
Loading

0 comments on commit 3b62a83

Please sign in to comment.