Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre commit for python linter and formatter #259

Merged
merged 25 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ stage
.gitignore
**/__pycache__/
mkdocs/
/.env
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by linter container
UID=<contents of shell command: "id -u">
GID=<contents of shell command: "id -g">
HOME=<contents of shell command: "echo ~">
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Identify what to put in the following fields:
og:url
g:type
og:title
og:description
og:image
og:description
og:image
og:type (optional)
og:local (option)
using the standards set forth in the instructions.
Expand Down
2 changes: 0 additions & 2 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ labels: ''
assignees: ''

---


6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/lighthouse--accessibility---forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ assignees: ''
### Overview
In order for your sites form(s) to be usable by visitors using screen readers all the form <input> elements need labels. There are specific details and exceptions, which can be found in the instructions below.

### Action Items
### Action Items
*If your site already has forms* review the instructions and document the changes needed to bring your form(s) into WCAG compliance, by commenting on this issue.
*If your site does not have forms* review the instructions and design new forms using the WCAG standards.
*If your site does not have forms* review the instructions and design new forms using the WCAG standards.

### Instructions
Deque University
Deque University
https://dequeuniversity.com/rules/axe/3.2/label
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The formatting of links can make them readable or unreadable by screen readers.

### Action Items
*If your site already has links* review the instructions and document the changes needed to bring your link(s) into WCAG compliance, by commenting on this issue.
*If your site does not have links yet* review the instructions and design all new links using the WCAG standards.
*If your site does not have links yet* review the instructions and design all new links using the WCAG standards.

### Instructions
Deque University
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ assignees: ''
---

### Overview
Links to cross-origin destinations are unsafe both from a security and performance perspective.
Links to cross-origin destinations are unsafe both from a security and performance perspective.

### Action Item
Run [Lighthouse](https://developers.google.com/web/tools/lighthouse/) and then follow the instructions in [cross-origin destinations are unsafe]
(https://developers.google.com/web/tools/lighthouse/audits/noopener) .
(https://developers.google.com/web/tools/lighthouse/audits/noopener) .

## Summary of instructions
When using *target=_blank* also adding *rel="noopener"* to the tag ensures that new page runs in a separate process.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/lighthouse--image-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees: ''
When you run the lighthouse review it may suggest some specific image optimizations such as choosing another image format and making those changes may or may not improve your sites actual performance.

### Action Items
Run lighthouse on a local version of the site and then apply suggested changes and retest locally before determining if you want to keep the changes.
Run lighthouse on a local version of the site and then apply suggested changes and retest locally before determining if you want to keep the changes.

### Instructions/Resources
Google's Tools for Web Developers: [Optimize Images](https://developers.google.com/web/tools/lighthouse/audits/optimize-images)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ assignees: ''

---

### Overview
### Overview
Describe the purpose for the proposal change

### Action items
- [ ] Indicate current state in a yaml snipit here:

- [ ] Indicate desired future state in a yaml snipit here:

- [ ] Perform test
- [ ] Perform test
- [ ] one project.md file
- [ ] updating logic of appropriate include file
- [ ] Get signoff
- [ ] update all project.md files with new or revised fields
- [ ] Update Template project.md wiki page
- [ ] Update Template project.md wiki page
- [ ] Submit pull request - indicating Issue #294 is affected (format changes log), and the text "fixes Issue #[number that you are creating now]

### Resources
Expand Down
7 changes: 3 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Fixes #

### Changes

-
-
-
-
-
-

<!-- Please ignore everything below until #78 closes. -->

Expand All @@ -24,4 +24,3 @@ Fixes #
<br>
</details>
-->

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ data/

**/super-linter.log
app/staticfiles

/.env
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
default_language_version:
# default language version for each language used in the repository
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
# See https://pre-commit.com/hooks.html for more hooks
- id: check-ast
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: name-tests-test
args: [ "--django" ]
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--settings-file", "app/setup.cfg"]
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: []
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
args: ["--config", "app/setup.cfg"]
additional_dependencies: [
"flake8-bugbear",
"flake8-comprehensions",
"flake8-mutable",
"flake8-print",
"flake8-simplify",
]
- repo: https://github.com/pycqa/pylint
rev: "v2.14.0-b1"
hooks:
- id: pylint
exclude: "[a-zA-Z]*/(migrations)/(.)*|(mkdocs)/(.)*"
args: [
"--load-plugins=pylint_django",
"--disable=C0114,C0115,C0116",
"--django-settings-module=config.settings",
"--rcfile=app/setup.cfg",
]
additional_dependencies: [
django,
djangorestframework,
pylint_django,
]
2 changes: 1 addition & 1 deletion app/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"@babel/env",
"@babel/preset-react"
]
}
}
2 changes: 1 addition & 1 deletion app/config/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

application = get_asgi_application()
92 changes: 48 additions & 44 deletions app/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -21,77 +21,79 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY", 'django-insecure-33vbl)@ay-yc6)h5jwqsphea(2#iq=1^h$9un7b-bh5h^gjvpv')
SECRET_KEY = os.environ.get(
"SECRET_KEY", "django-insecure-33vbl)@ay-yc6)h5jwqsphea(2#iq=1^h$9un7b-bh5h^gjvpv"
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get("DEBUG", "True") != "False"

ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "localhost").split(" ")


# Application definition

INSTALLED_APPS = [
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'server',
'frontend',
"rest_framework",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"server",
"frontend",
]

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

DEV_MIDDLEWARE = []

STAGE_MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
]

environ = os.environ.get("ENVIRON", 'dev')
environ = os.environ.get("ENVIRON", "dev")

if environ == 'dev':
if environ == "dev":
MIDDLEWARE = COMMON_MIDDLEWARE + DEV_MIDDLEWARE
elif environ == 'stage':
elif environ == "stage":
MIDDLEWARE = COMMON_MIDDLEWARE + STAGE_MIDDLEWARE

ROOT_URLCONF = 'config.urls'
ROOT_URLCONF = "config.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 = 'config.wsgi.application'
WSGI_APPLICATION = "config.wsgi.application"


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

DATABASES = {
'default': {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("SQL_DATABASE", BASE_DIR / "db.sqlite3"),
"USER": os.environ.get("SQL_USER", "user"),
Expand All @@ -107,26 +109,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa: E501 # pylint: disable=C0301
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


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

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

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -138,17 +140,19 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

SECURE_SSL_REDIRECT = os.environ.get("SECURE_SSL_REDIRECT", "False") == "True"
SESSION_COOKIE_SECURE = os.environ.get("SESSION_COOKIE_SECURE", "False") == "True"
CSRF_COOKIE_SECURE = os.environ.get("CSRF_COOKIE_SECURE", "False") == "True"
SECURE_HSTS_SECONDS = int(os.environ.get("SECURE_HSTS_SECONDS", "0"))
env = os.environ.get("SECURE_PROXY_SSL_HEADER", None)
SECURE_PROXY_SSL_HEADER = tuple(env).split(" ") if env else None
SECURE_PROXY_SSL_HEADER = (
tuple(env).split(" ") if env else None # pylint: disable=E1101
)
6 changes: 3 additions & 3 deletions app/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
# path('server/', include('server.urls')),
path('', include('frontend.urls'))
path("", include("frontend.urls")),
]
2 changes: 1 addition & 1 deletion app/config/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

application = get_wsgi_application()
3 changes: 0 additions & 3 deletions app/frontend/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
Loading