Skip to content

Commit

Permalink
Add pre-commit and run it
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvipanda committed Jul 26, 2024
1 parent 71575d0 commit 7670a1f
Show file tree
Hide file tree
Showing 25 changed files with 390 additions and 253 deletions.
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
# Ignore style and complexity
# E: style errors
# W: style warnings
# C: complexity
# F841: local variable assigned but never used
ignore = E, C, W, F841
builtins = c, get_config
exclude =
.cache,
.github,
docs,
__init__.py
77 changes: 77 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# pre-commit is a tool to perform a predefined set of tasks manually and/or
# automatically before git commits are made.
#
# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level
#
# Common tasks
#
# - Run on all files: pre-commit run --all-files
# - Register git hooks: pre-commit install --install-hooks
#
repos:
# Autoformat: Python code, syntax patterns are modernized
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py37-plus

# Autoformat: Python code
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

# Autoformat: Python code
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black

# Autoformat: markdown, yaml
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
# Don't run prettier on our jinja2 template files. We run djlint instead
exclude: "kubespawner/templates/.*\\.html"

# Misc...
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
# ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available
hooks:
# Autoformat: Makes sure files end in a newline and only a newline.
- id: end-of-file-fixer

# Autoformat: Sorts entries in requirements.txt.
- id: requirements-txt-fixer

# Lint: Check for files with names that would conflict on a
# case-insensitive filesystem like MacOS HFS+ or Windows FAT.
- id: check-case-conflict

# Lint: Checks that non-binary executables have a proper shebang.
- id: check-executables-have-shebangs

# Lint: Python code
- repo: https://github.com/PyCQA/flake8
rev: "7.0.0"
hooks:
- id: flake8

# Lint our jinja2 templates
- repo: https://github.com/Riverside-Healthcare/djLint
rev: v1.34.1
hooks:
- id: djlint-jinja
files: "kubespawner/templates/.*\\.html"
types_or:
- html
args:
- --reformat

# pre-commit.ci config reference: https://pre-commit.ci/#configuration
ci:
autoupdate_schedule: monthly
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# unnamed-competitive-tester
# unnamed-competitive-tester
60 changes: 29 additions & 31 deletions comptest/comptest/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",

'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.github'
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.github",
]

MIDDLEWARE = [
Expand All @@ -53,7 +52,6 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",

"allauth.account.middleware.AccountMiddleware",
]

Expand Down Expand Up @@ -132,45 +130,44 @@

AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',

"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by email
'allauth.account.auth_backends.AuthenticationBackend',
"allauth.account.auth_backends.AuthenticationBackend",
]

LOGGING = {
'version': 1,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
"version": 1,
"filters": {
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue",
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
"handlers": {
"console": {
"level": "DEBUG",
"filters": ["require_debug_true"],
"class": "logging.StreamHandler",
}
},
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
'handlers': ['console'],
"loggers": {
"django.db.backends": {
"level": "DEBUG",
"handlers": ["console"],
}
}
},
}

# Provider specific settings
SOCIALACCOUNT_PROVIDERS = {
'github': {
"github": {
# For each OAuth based provider, either add a ``SocialApp``
# (``socialaccount`` app) containing the required client
# credentials, or list them here:
'APP': {
'client_id': 'Ov23liodL5AiNt5kfB8d',
'secret': 'bfab0d49f138df0d017d2bcc0f9bbb1b199b7e62',
"APP": {
"client_id": "Ov23liodL5AiNt5kfB8d",
"secret": "bfab0d49f138df0d017d2bcc0f9bbb1b199b7e62",
},
"VERIFIED_EMAIL": True
"VERIFIED_EMAIL": True,
}
}

Expand All @@ -185,8 +182,9 @@


import os

out_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "uploads/"))
if not out_dir.endswith("/"):
if not out_dir.endswith("/"):
out_dir += "/"
os.makedirs(out_dir, exist_ok=True)

Expand All @@ -196,8 +194,8 @@
# FIXME: Move this somewhere else or make this configurable
# This *must* be bind mountable into the docker container
output_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "outputs/"))
if not output_dir.endswith("/"):
if not output_dir.endswith("/"):
output_dir += "/"
os.makedirs(output_dir, exist_ok=True)

UNNAMED_THINGY_EVALUATOR_OUTPUTS_TEMPDIR = output_dir
UNNAMED_THINGY_EVALUATOR_OUTPUTS_TEMPDIR = output_dir
5 changes: 2 additions & 3 deletions comptest/comptest/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.contrib import admin
from django.urls import path, include

from django.urls import include, path

urlpatterns = [
path("", include("web.urls")),
path("admin/", admin.site.urls),
path('accounts/', include('allauth.urls')),
path("accounts/", include("allauth.urls")),
]
7 changes: 4 additions & 3 deletions comptest/web/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin
from .models import Submission, Evaluation
from allauth.account.decorators import secure_admin_login
from django.contrib import admin

from .models import Evaluation, Submission

admin.site.register([Submission, Evaluation])

admin.site.login = secure_admin_login(admin.site.login)
admin.site.login = secure_admin_login(admin.site.login)
3 changes: 2 additions & 1 deletion comptest/web/apps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.apps import AppConfig
from allauth.socialaccount.signals import pre_social_login
from django.apps import AppConfig


def login_signal(request, sociallogin, **kwargs):
print(request)
print(sociallogin)


class WebConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "web"
Expand Down
Loading

0 comments on commit 7670a1f

Please sign in to comment.