From ef9688ba42ce16a92e9ffc37f0556d2e55b845db Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 09:46:26 +0000 Subject: [PATCH 01/28] DPAT-2026 Establish project structure and basic tech --- .gitignore | 2 + cpanel/__init__.py | 0 cpanel/asgi.py | 16 +++ cpanel/core/__init__.py | 0 cpanel/core/apps.py | 6 + cpanel/core/common/__init__.py | 0 cpanel/core/migrations/__init__.py | 0 cpanel/core/models/__init__.py | 0 cpanel/domains/apps.py | 0 cpanel/domains/data-products/__init__.py | 0 cpanel/interfaces/api/__init__.py | 0 cpanel/interfaces/apps.py | 0 cpanel/interfaces/web/__init__.py | 0 cpanel/middlewares/__init__.py | 0 cpanel/settings/__init__.py | 1 + cpanel/settings/common.py | 140 +++++++++++++++++++++++ cpanel/urls.py | 22 ++++ cpanel/wsgi.py | 16 +++ manage.py | 22 ++++ requirements.txt | 4 + tests/__init__.py | 0 21 files changed, 229 insertions(+) create mode 100644 cpanel/__init__.py create mode 100644 cpanel/asgi.py create mode 100644 cpanel/core/__init__.py create mode 100644 cpanel/core/apps.py create mode 100644 cpanel/core/common/__init__.py create mode 100644 cpanel/core/migrations/__init__.py create mode 100644 cpanel/core/models/__init__.py create mode 100644 cpanel/domains/apps.py create mode 100644 cpanel/domains/data-products/__init__.py create mode 100644 cpanel/interfaces/api/__init__.py create mode 100644 cpanel/interfaces/apps.py create mode 100644 cpanel/interfaces/web/__init__.py create mode 100644 cpanel/middlewares/__init__.py create mode 100644 cpanel/settings/__init__.py create mode 100644 cpanel/settings/common.py create mode 100644 cpanel/urls.py create mode 100644 cpanel/wsgi.py create mode 100755 manage.py create mode 100644 requirements.txt create mode 100644 tests/__init__.py diff --git a/.gitignore b/.gitignore index 3d4ec2e0..83f98af5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ env/ terraform.tfstate super-linter.log .mypy_cache/ +.idea/ + diff --git a/cpanel/__init__.py b/cpanel/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/asgi.py b/cpanel/asgi.py new file mode 100644 index 00000000..391cbc72 --- /dev/null +++ b/cpanel/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for cpanel project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') + +application = get_asgi_application() diff --git a/cpanel/core/__init__.py b/cpanel/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/core/apps.py b/cpanel/core/apps.py new file mode 100644 index 00000000..1b63faae --- /dev/null +++ b/cpanel/core/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class CliConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'cpanel.core' diff --git a/cpanel/core/common/__init__.py b/cpanel/core/common/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/core/migrations/__init__.py b/cpanel/core/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/core/models/__init__.py b/cpanel/core/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/domains/apps.py b/cpanel/domains/apps.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/domains/data-products/__init__.py b/cpanel/domains/data-products/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/interfaces/api/__init__.py b/cpanel/interfaces/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/interfaces/apps.py b/cpanel/interfaces/apps.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/interfaces/web/__init__.py b/cpanel/interfaces/web/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/middlewares/__init__.py b/cpanel/middlewares/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cpanel/settings/__init__.py b/cpanel/settings/__init__.py new file mode 100644 index 00000000..b253d9a5 --- /dev/null +++ b/cpanel/settings/__init__.py @@ -0,0 +1 @@ +from cpanel.settings.common import * diff --git a/cpanel/settings/common.py b/cpanel/settings/common.py new file mode 100644 index 00000000..cb6adb18 --- /dev/null +++ b/cpanel/settings/common.py @@ -0,0 +1,140 @@ +""" +Django settings for cpanel project. + +Generated by 'django-admin startproject' using Django 4.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path +import os + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +PROJECT_NAME = "cpanel" + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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', +] + +ROOT_URLCONF = 'cpanel.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'cpanel.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +# -- Database +DB_HOST = os.environ.get("DB_HOST", "127.0.0.1") +ENABLE_DB_SSL = ( + str( + os.environ.get("ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"]) + ).lower() + == "true" +) +DATABASES = { + "default": { + "ENGINE": "django_prometheus.db.backends.postgresql", + "NAME": os.environ.get("DB_NAME", PROJECT_NAME), + "USER": os.environ.get("DB_USER", ""), + "PASSWORD": os.environ.get("DB_PASSWORD", ""), + "HOST": DB_HOST, + "PORT": os.environ.get("DB_PORT", "5432"), + } +} + +if ENABLE_DB_SSL: + DATABASES["default"]["OPTIONS"] = {"sslmode": "require"} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +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', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/cpanel/urls.py b/cpanel/urls.py new file mode 100644 index 00000000..78935dbe --- /dev/null +++ b/cpanel/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for cpanel project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/cpanel/wsgi.py b/cpanel/wsgi.py new file mode 100644 index 00000000..7d1c1bda --- /dev/null +++ b/cpanel/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for cpanel project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 00000000..b1b274f4 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + )(exc) + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..c2e3dfec --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +asgiref==3.7.2 +Django==4.2.7 +psycopg2==2.9.9 +sqlparse==0.4.4 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b From c652f8784179b629becb4fc40e06cf1f2c4884e5 Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 10:21:11 +0000 Subject: [PATCH 02/28] DPAT-2026 added a dummy file to show the cli folder --- cpanel/interfaces/cli/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 cpanel/interfaces/cli/__init__.py diff --git a/cpanel/interfaces/cli/__init__.py b/cpanel/interfaces/cli/__init__.py new file mode 100644 index 00000000..e69de29b From 13460ad1ba1669be5e09b9c94eff93fe589ea278 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Tue, 7 Nov 2023 14:00:15 +0000 Subject: [PATCH 03/28] Add PostgreSQL Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 3 ++- .../src/postgresql/devcontainer-feature.json | 6 ++++++ .devcontainer/features/src/postgresql/install.sh | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/features/src/postgresql/devcontainer-feature.json create mode 100644 .devcontainer/features/src/postgresql/install.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9245d758..0f8fd1ed 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,8 @@ }, "ghcr.io/devcontainers/features/python:1": { "version": "3.11" - } + }, + "./features/src/postgresql": {} }, "postCreateCommand": "bash scripts/devcontainer/post-create.sh", "customizations": { diff --git a/.devcontainer/features/src/postgresql/devcontainer-feature.json b/.devcontainer/features/src/postgresql/devcontainer-feature.json new file mode 100644 index 00000000..7d17edcc --- /dev/null +++ b/.devcontainer/features/src/postgresql/devcontainer-feature.json @@ -0,0 +1,6 @@ +{ + "id": "postgresql", + "version": "1.0.0", + "name": "postgresql", + "description": "PostgreSQL" +} \ No newline at end of file diff --git a/.devcontainer/features/src/postgresql/install.sh b/.devcontainer/features/src/postgresql/install.sh new file mode 100644 index 00000000..1be9638a --- /dev/null +++ b/.devcontainer/features/src/postgresql/install.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list + +wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + +apt-get update + +apt-get -y install \ + postgresql-common \ + postgresql-client-common \ + postgresql-15 \ + postgresql-client-15 From ab2d3534d4703cdb4eff3deddb40052833fc1af0 Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 14:07:57 +0000 Subject: [PATCH 04/28] DPAT-2026 try to fix the superlint warnings --- cpanel/asgi.py | 2 +- cpanel/settings/common.py | 65 +++++++++++++++++++-------------------- cpanel/urls.py | 2 +- cpanel/wsgi.py | 2 +- manage.py | 4 +-- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/cpanel/asgi.py b/cpanel/asgi.py index 391cbc72..645baaa9 100644 --- a/cpanel/asgi.py +++ b/cpanel/asgi.py @@ -11,6 +11,6 @@ from django.core.asgi import get_asgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") application = get_asgi_application() diff --git a/cpanel/settings/common.py b/cpanel/settings/common.py index cb6adb18..7cc2bbb0 100644 --- a/cpanel/settings/common.py +++ b/cpanel/settings/common.py @@ -9,9 +9,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.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 @@ -22,7 +21,7 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn' +SECRET_KEY = "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -33,37 +32,37 @@ # Application definition INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", ] 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", ] ROOT_URLCONF = 'cpanel.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", ], }, }, @@ -103,16 +102,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", }, { - '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", }, ] @@ -120,9 +119,9 @@ # Internationalization # https://docs.djangoproject.com/en/4.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = "en-us" -TIME_ZONE = 'UTC' +TIME_ZONE = "UTC" USE_I18N = True @@ -132,9 +131,9 @@ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = 'static/' +STATIC_URL = "static/" # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/cpanel/urls.py b/cpanel/urls.py index 78935dbe..428dbfb3 100644 --- a/cpanel/urls.py +++ b/cpanel/urls.py @@ -18,5 +18,5 @@ from django.urls import path urlpatterns = [ - path('admin/', admin.site.urls), + path("admin/", admin.site.urls), ] diff --git a/cpanel/wsgi.py b/cpanel/wsgi.py index 7d1c1bda..9cf8b147 100644 --- a/cpanel/wsgi.py +++ b/cpanel/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") application = get_wsgi_application() diff --git a/manage.py b/manage.py index b1b274f4..c5c29991 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cpanel.settings') + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -18,5 +18,5 @@ def main(): execute_from_command_line(sys.argv) -if __name__ == '__main__': +if __name__ == "__main__": main() From 1b36da62cddea5dc8538d8b9f7fb67932a21d3da Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 14:35:14 +0000 Subject: [PATCH 05/28] DPAT-2026 renamed some folders --- {cpanel => controlpanel}/__init__.py | 0 {cpanel => controlpanel}/asgi.py | 4 ++-- {cpanel => controlpanel}/core/__init__.py | 0 {cpanel => controlpanel}/core/apps.py | 2 +- {cpanel => controlpanel}/core/common/__init__.py | 0 {cpanel => controlpanel}/core/migrations/__init__.py | 0 {cpanel => controlpanel}/core/models/__init__.py | 0 {cpanel => controlpanel}/domains/apps.py | 0 .../domains/data-products/__init__.py | 0 {cpanel => controlpanel}/interfaces/api/__init__.py | 0 {cpanel => controlpanel}/interfaces/apps.py | 0 {cpanel => controlpanel}/interfaces/cli/__init__.py | 0 {cpanel => controlpanel}/interfaces/web/__init__.py | 0 .../middlewares => controlpanel/middleware}/__init__.py | 0 controlpanel/settings/__init__.py | 1 + {cpanel => controlpanel}/settings/common.py | 8 ++++---- {cpanel => controlpanel}/urls.py | 2 +- {cpanel => controlpanel}/wsgi.py | 4 ++-- cpanel/settings/__init__.py | 1 - manage.py | 2 +- 20 files changed, 12 insertions(+), 12 deletions(-) rename {cpanel => controlpanel}/__init__.py (100%) rename {cpanel => controlpanel}/asgi.py (72%) rename {cpanel => controlpanel}/core/__init__.py (100%) rename {cpanel => controlpanel}/core/apps.py (79%) rename {cpanel => controlpanel}/core/common/__init__.py (100%) rename {cpanel => controlpanel}/core/migrations/__init__.py (100%) rename {cpanel => controlpanel}/core/models/__init__.py (100%) rename {cpanel => controlpanel}/domains/apps.py (100%) rename {cpanel => controlpanel}/domains/data-products/__init__.py (100%) rename {cpanel => controlpanel}/interfaces/api/__init__.py (100%) rename {cpanel => controlpanel}/interfaces/apps.py (100%) rename {cpanel => controlpanel}/interfaces/cli/__init__.py (100%) rename {cpanel => controlpanel}/interfaces/web/__init__.py (100%) rename {cpanel/middlewares => controlpanel/middleware}/__init__.py (100%) create mode 100644 controlpanel/settings/__init__.py rename {cpanel => controlpanel}/settings/common.py (95%) rename {cpanel => controlpanel}/urls.py (94%) rename {cpanel => controlpanel}/wsgi.py (72%) delete mode 100644 cpanel/settings/__init__.py diff --git a/cpanel/__init__.py b/controlpanel/__init__.py similarity index 100% rename from cpanel/__init__.py rename to controlpanel/__init__.py diff --git a/cpanel/asgi.py b/controlpanel/asgi.py similarity index 72% rename from cpanel/asgi.py rename to controlpanel/asgi.py index 645baaa9..a5e6f332 100644 --- a/cpanel/asgi.py +++ b/controlpanel/asgi.py @@ -1,5 +1,5 @@ """ -ASGI config for cpanel project. +ASGI config for controlpanel project. It exposes the ASGI callable as a module-level variable named ``application``. @@ -11,6 +11,6 @@ from django.core.asgi import get_asgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings") application = get_asgi_application() diff --git a/cpanel/core/__init__.py b/controlpanel/core/__init__.py similarity index 100% rename from cpanel/core/__init__.py rename to controlpanel/core/__init__.py diff --git a/cpanel/core/apps.py b/controlpanel/core/apps.py similarity index 79% rename from cpanel/core/apps.py rename to controlpanel/core/apps.py index 1b63faae..236ca101 100644 --- a/cpanel/core/apps.py +++ b/controlpanel/core/apps.py @@ -3,4 +3,4 @@ class CliConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'cpanel.core' + name = 'controlpanel.core' diff --git a/cpanel/core/common/__init__.py b/controlpanel/core/common/__init__.py similarity index 100% rename from cpanel/core/common/__init__.py rename to controlpanel/core/common/__init__.py diff --git a/cpanel/core/migrations/__init__.py b/controlpanel/core/migrations/__init__.py similarity index 100% rename from cpanel/core/migrations/__init__.py rename to controlpanel/core/migrations/__init__.py diff --git a/cpanel/core/models/__init__.py b/controlpanel/core/models/__init__.py similarity index 100% rename from cpanel/core/models/__init__.py rename to controlpanel/core/models/__init__.py diff --git a/cpanel/domains/apps.py b/controlpanel/domains/apps.py similarity index 100% rename from cpanel/domains/apps.py rename to controlpanel/domains/apps.py diff --git a/cpanel/domains/data-products/__init__.py b/controlpanel/domains/data-products/__init__.py similarity index 100% rename from cpanel/domains/data-products/__init__.py rename to controlpanel/domains/data-products/__init__.py diff --git a/cpanel/interfaces/api/__init__.py b/controlpanel/interfaces/api/__init__.py similarity index 100% rename from cpanel/interfaces/api/__init__.py rename to controlpanel/interfaces/api/__init__.py diff --git a/cpanel/interfaces/apps.py b/controlpanel/interfaces/apps.py similarity index 100% rename from cpanel/interfaces/apps.py rename to controlpanel/interfaces/apps.py diff --git a/cpanel/interfaces/cli/__init__.py b/controlpanel/interfaces/cli/__init__.py similarity index 100% rename from cpanel/interfaces/cli/__init__.py rename to controlpanel/interfaces/cli/__init__.py diff --git a/cpanel/interfaces/web/__init__.py b/controlpanel/interfaces/web/__init__.py similarity index 100% rename from cpanel/interfaces/web/__init__.py rename to controlpanel/interfaces/web/__init__.py diff --git a/cpanel/middlewares/__init__.py b/controlpanel/middleware/__init__.py similarity index 100% rename from cpanel/middlewares/__init__.py rename to controlpanel/middleware/__init__.py diff --git a/controlpanel/settings/__init__.py b/controlpanel/settings/__init__.py new file mode 100644 index 00000000..230182a2 --- /dev/null +++ b/controlpanel/settings/__init__.py @@ -0,0 +1 @@ +from controlpanel.settings.common import * diff --git a/cpanel/settings/common.py b/controlpanel/settings/common.py similarity index 95% rename from cpanel/settings/common.py rename to controlpanel/settings/common.py index 7cc2bbb0..a9bd76c9 100644 --- a/cpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -1,5 +1,5 @@ """ -Django settings for cpanel project. +Django settings for controlpanel project. Generated by 'django-admin startproject' using Django 4.2.7. @@ -15,7 +15,7 @@ # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -PROJECT_NAME = "cpanel" +PROJECT_NAME = "controlpanel" # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ @@ -50,7 +50,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'cpanel.urls' +ROOT_URLCONF = 'controlpanel.urls' TEMPLATES = [ { @@ -68,7 +68,7 @@ }, ] -WSGI_APPLICATION = 'cpanel.wsgi.application' +WSGI_APPLICATION = 'controlpanel.wsgi.application' # Database diff --git a/cpanel/urls.py b/controlpanel/urls.py similarity index 94% rename from cpanel/urls.py rename to controlpanel/urls.py index 428dbfb3..bcfa4bd0 100644 --- a/cpanel/urls.py +++ b/controlpanel/urls.py @@ -1,5 +1,5 @@ """ -URL configuration for cpanel project. +URL configuration for controlpanel project. The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/4.2/topics/http/urls/ diff --git a/cpanel/wsgi.py b/controlpanel/wsgi.py similarity index 72% rename from cpanel/wsgi.py rename to controlpanel/wsgi.py index 9cf8b147..a2aabccf 100644 --- a/cpanel/wsgi.py +++ b/controlpanel/wsgi.py @@ -1,5 +1,5 @@ """ -WSGI config for cpanel project. +WSGI config for controlpanel project. It exposes the WSGI callable as a module-level variable named ``application``. @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings") application = get_wsgi_application() diff --git a/cpanel/settings/__init__.py b/cpanel/settings/__init__.py deleted file mode 100644 index b253d9a5..00000000 --- a/cpanel/settings/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from cpanel.settings.common import * diff --git a/manage.py b/manage.py index c5c29991..ea8c51a8 100755 --- a/manage.py +++ b/manage.py @@ -6,7 +6,7 @@ def main(): """Run administrative tasks.""" - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cpanel.settings") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings") try: from django.core.management import execute_from_command_line except ImportError as exc: From da4e94383932696c9645edd5cbfc21c542f830a4 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Tue, 7 Nov 2023 15:16:20 +0000 Subject: [PATCH 06/28] Add Docker Compose Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 1 + contrib/docker-compose-postgres.yml | 13 +++++++++++++ scripts/devcontainer/post-create.sh | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 contrib/docker-compose-postgres.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0f8fd1ed..9c2f4051 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,6 +8,7 @@ "ghcr.io/devcontainers/features/python:1": { "version": "3.11" }, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "./features/src/postgresql": {} }, "postCreateCommand": "bash scripts/devcontainer/post-create.sh", diff --git a/contrib/docker-compose-postgres.yml b/contrib/docker-compose-postgres.yml new file mode 100644 index 00000000..04495b8c --- /dev/null +++ b/contrib/docker-compose-postgres.yml @@ -0,0 +1,13 @@ +--- +version: '3.8' + +services: + postgres: + image: public.ecr.aws/docker/library/postgres:15.4 + restart: always + environment: + POSTGRES_USER: controlpanel + POSTGRES_PASSWORD: controlpanel + POSTGRES_DB: controlpanel + ports: + - "5432:5432" diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index 5bfb1afe..9e63f38d 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -5,3 +5,6 @@ npm install --global npm@latest # Upgrade Pip pip install --upgrade pip + +# Start Postgres +docker-compose --file contrib/docker-compose-postgres.yml up --detach \ No newline at end of file From e201cc64dc0093fe422e4b3af2f95c94fc975385 Mon Sep 17 00:00:00 2001 From: Gary H <26419401+Gary-H9@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:28:10 +0000 Subject: [PATCH 07/28] Update post-create docker compose --- scripts/devcontainer/post-create.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index 9e63f38d..713179dd 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -7,4 +7,4 @@ npm install --global npm@latest pip install --upgrade pip # Start Postgres -docker-compose --file contrib/docker-compose-postgres.yml up --detach \ No newline at end of file +docker compose --file contrib/docker-compose-postgres.yml up --detach From ee1f09f289f165c24ee2e8a90409ed9fbb109cda Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:24:37 +0000 Subject: [PATCH 08/28] Fix lint errors, add dev dependencies --- .flake8 | 3 +++ .gitignore | 3 ++- controlpanel/core/apps.py | 4 +-- .../__init__.py | 0 controlpanel/settings/__init__.py | 2 +- controlpanel/settings/common.py | 27 +++++++++++-------- manage.py | 1 + mypy.ini | 6 +++++ pyproject.toml | 2 ++ requirements.dev.txt | 5 ++++ requirements.txt | 1 + 11 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 .flake8 rename controlpanel/domains/{data-products => data_products}/__init__.py (100%) create mode 100644 mypy.ini create mode 100644 pyproject.toml create mode 100644 requirements.dev.txt diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..52a935d3 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +exclude = + venv diff --git a/.gitignore b/.gitignore index 83f98af5..2ec8abea 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ terraform.tfstate super-linter.log .mypy_cache/ .idea/ - +__pycache__ +*.egg-info/ diff --git a/controlpanel/core/apps.py b/controlpanel/core/apps.py index 236ca101..4444e2a3 100644 --- a/controlpanel/core/apps.py +++ b/controlpanel/core/apps.py @@ -2,5 +2,5 @@ class CliConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'controlpanel.core' + default_auto_field = "django.db.models.BigAutoField" + name = "controlpanel.core" diff --git a/controlpanel/domains/data-products/__init__.py b/controlpanel/domains/data_products/__init__.py similarity index 100% rename from controlpanel/domains/data-products/__init__.py rename to controlpanel/domains/data_products/__init__.py diff --git a/controlpanel/settings/__init__.py b/controlpanel/settings/__init__.py index 230182a2..24917e37 100644 --- a/controlpanel/settings/__init__.py +++ b/controlpanel/settings/__init__.py @@ -1 +1 @@ -from controlpanel.settings.common import * +from controlpanel.settings.common import * # noqa diff --git a/controlpanel/settings/common.py b/controlpanel/settings/common.py index a9bd76c9..3814aeb8 100644 --- a/controlpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -21,12 +21,14 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" +SECRET_KEY = ( + "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS: list = [] # Application definition @@ -50,7 +52,7 @@ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -ROOT_URLCONF = 'controlpanel.urls' +ROOT_URLCONF = "controlpanel.urls" TEMPLATES = [ { @@ -68,7 +70,8 @@ }, ] -WSGI_APPLICATION = 'controlpanel.wsgi.application' + +WSGI_APPLICATION = "controlpanel.wsgi.application" # Database @@ -78,13 +81,15 @@ DB_HOST = os.environ.get("DB_HOST", "127.0.0.1") ENABLE_DB_SSL = ( str( - os.environ.get("ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"]) + os.environ.get( + "ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"] + ) ).lower() == "true" ) -DATABASES = { +DATABASES: dict = { "default": { - "ENGINE": "django_prometheus.db.backends.postgresql", + "ENGINE": "django.db.backends.postgresql", "NAME": os.environ.get("DB_NAME", PROJECT_NAME), "USER": os.environ.get("DB_USER", ""), "PASSWORD": os.environ.get("DB_PASSWORD", ""), @@ -102,16 +107,16 @@ AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", # noqa }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", # noqa }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", # noqa }, ] diff --git a/manage.py b/manage.py index ea8c51a8..a20ba8f7 100755 --- a/manage.py +++ b/manage.py @@ -6,6 +6,7 @@ def main(): """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "controlpanel.settings") try: from django.core.management import execute_from_command_line diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..9c0280ec --- /dev/null +++ b/mypy.ini @@ -0,0 +1,6 @@ +[mypy] +plugins = + mypy_django_plugin.main + +[mypy.plugins.django-stubs] +django_settings_module = "controlpanel.settings" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..a8f43fef --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 79 diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 00000000..59592ddf --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,5 @@ +isort==5.12.0 +django-stubs[compatible-mypy]==4.2.6 +mypy==1.6.1 +flake8==6.1.0 +black==23.10.1 diff --git a/requirements.txt b/requirements.txt index c2e3dfec..bce49157 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ asgiref==3.7.2 Django==4.2.7 psycopg2==2.9.9 sqlparse==0.4.4 +django-prometheus==2.3.1 From 21bb8ea87712f66f286a7f12867ff2067cc0d6e2 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Tue, 7 Nov 2023 17:16:34 +0000 Subject: [PATCH 09/28] Add pre-commit config and add some basic running documentation --- .pre-commit-config.yaml | 39 +++++++++++++++++++++++++++++ README.md | 26 +++++++++++++++++++ controlpanel/settings/common.py | 1 + pyproject.toml | 1 + requirements.dev.txt | 8 +++--- requirements.txt | 4 +-- scripts/devcontainer/post-create.sh | 10 ++++++-- 7 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..3f56ba89 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,39 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - name: End of File Fixer + id: end-of-file-fixer + - name: Trailing Whitespace Fixer + id: trailing-whitespace + - name: Check yaml + id: check-yaml + - name: requirements.txt fixer + id: requirements-txt-fixer + + - repo: https://github.com/psf/black + rev: 23.10.1 + hooks: + - id: black + name: black formatting + + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + name: flake8 lint + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.6.1 + hooks: + - id: mypy + name: mypy + additional_dependencies: + - django-stubs + - psycopg2-binary + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort (python) diff --git a/README.md b/README.md index 76332574..a3c142e7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,29 @@ # Data Platform Control Panel +## Running + +The quickest way to get the project running is to use the dev container that has been configured to install all +dependencies required to run the project locally. To use the dev container, see the [Data Platform docs.](https://technical-documentation.data-platform.service.justice.gov.uk/documentation/platform/infrastructure/developing.html#developing-the-data-platform) + +Alternatively you can install the project locally by installing python 3.11, creating a venv, and installing the +project dependencies with + +```commandline +pip install -r requirements.dev.txt +``` + +You will also need to have Postgresql installed and running on your machine. + +### Pre-commit + +To avoid pushing code and seeing the github actions fail due to linting errors, when installing the project for the +first time you should install the pre-commit hooks with: + +``` +pre-commit install +``` + +This will run black, mypy, flake8 and isort before a commit to check for failures and stage any required changes. + + [![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Fdata-platform-control-panel&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g8/kM2mfqMPVH6mf35t6G/ZgcJ/836Gdug4FjgO67UFn70+FDmjcw9xZaiegWX29lLLmE3QV4Glg8x7WbFfHlFIebS/ANj2oDgX+CXwA9AMubmPNvuqX1SnqKGAT0BFoVE9UL1RH7nSCUjYAL6rntBdg2Q3AgcAo4HDgXeBAoC+wrZQyWS3AWcDSUsomtSswEtgXaAGWlVI2q32BI0spj9XpPww4EVic88vaC7iq5Hz1BvVf6v3qe+rb6ji1p3pWrmtQG9VD1Jn5br+Knmm70T9MfUh9JaPQZu7uLsR9gEsJb3QF9gOagO7AuUTom1LpCcAkoCcwQj0VmJregzaipA4GphNe7w/MBearB7QLYCmlGdiWSm4CfplTHwBDgPHAFmB+Ah8N9AE6EGkxHLhaHU2kRhXc+cByYCqROs05NQq4oR7Lnm5xE9AL+GYC2gZ0Jmjk8VLKO+pE4HvAyYRnOwOH5N7NhMd/WKf3beApYBWwAdgHuCLn+tatbRtgJv1awhtd838LEeq30/A7wN+AwcBt+bwpD9AdOAkYVkpZXtVdSnlc7QI8BlwOXFmZ3oXkdxfidwmPrQXeA+4GuuT08QSdALxC3OYNhBe/TtzON4EziZB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HPVqdXOCe1rtrg5W7zNI+m712Ir+cer4POiqfHeJSVe1Raemwnm7xD3mD1E/Z3wIjcsTdlZnqO8bFeNB9c30zgVG2euYa69QJ+9G90lG+99bfdIoo5PU4w362xHePxl1slMab6tV72KUxDvzlAMT8G0ZohXq39VX1bNzzxij9K1Qb9lhdGe931B/kR6/zCwY9YvuytCsMlj+gbr5SemhqkyuzE8xau4MP865JvWNuj0b1YuqDkgvH2GkURfakly01Cg7Cw0+qyXxkjojq9Lw+vT2AUY+DlF/otYq1Ixc35re2V7R8aTRg2KUv7+ou3x/14PsUBn3NG51S0XpG0Z9PcOPKWSS0SKNUo9Rv2Mmt/G5WpPF6pHGra7Jv410OVsdaz217AbkAPX3ubkm240belCuudT4Rp5p/DyC2lf9mfq1iq5eFe8/lu+K0YrVp0uret4nAkwlB6vzjI/1PxrlrTp/oNHbzTJI92T1qAT+BfW49MhMg6JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/data-platform-control-panel) diff --git a/controlpanel/settings/common.py b/controlpanel/settings/common.py index 3814aeb8..15a32f5b 100644 --- a/controlpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -25,6 +25,7 @@ "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" ) + # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True diff --git a/pyproject.toml b/pyproject.toml index a8f43fef..3c550e98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,3 @@ [tool.black] line-length = 79 +target-version = ["py311"] diff --git a/requirements.dev.txt b/requirements.dev.txt index 59592ddf..c2497ddf 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,5 +1,7 @@ -isort==5.12.0 +-r ./requirements.txt +black==23.10.1 django-stubs[compatible-mypy]==4.2.6 -mypy==1.6.1 flake8==6.1.0 -black==23.10.1 +isort==5.12.0 +mypy==1.6.1 +pre-commit==3.5.0 diff --git a/requirements.txt b/requirements.txt index bce49157..e6c23bef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ asgiref==3.7.2 Django==4.2.7 -psycopg2==2.9.9 -sqlparse==0.4.4 django-prometheus==2.3.1 +psycopg2-binary==2.9.9 +sqlparse==0.4.4 diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index 713179dd..9b48ad36 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -3,8 +3,14 @@ # Upgrade NPM npm install --global npm@latest +# Start Postgres +docker compose --file contrib/docker-compose-postgres.yml up --detach + # Upgrade Pip pip install --upgrade pip -# Start Postgres -docker compose --file contrib/docker-compose-postgres.yml up --detach +# Install dependencies +pip install -r requirements.dev.txt + +# Install precommit hooks +pre-commit install From 0875a6eb07329b136a2f6f5e2347d14055ad8ffc Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 18:21:45 +0000 Subject: [PATCH 10/28] DPAT-2026 try to fix the rest of superlint warnings --- .../features/src/postgresql/devcontainer-feature.json | 2 +- .devcontainer/features/src/postgresql/install.sh | 2 +- README.md | 4 ++-- controlpanel/settings/common.py | 8 ++------ manage.py | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.devcontainer/features/src/postgresql/devcontainer-feature.json b/.devcontainer/features/src/postgresql/devcontainer-feature.json index 7d17edcc..4f9e7b7e 100644 --- a/.devcontainer/features/src/postgresql/devcontainer-feature.json +++ b/.devcontainer/features/src/postgresql/devcontainer-feature.json @@ -3,4 +3,4 @@ "version": "1.0.0", "name": "postgresql", "description": "PostgreSQL" -} \ No newline at end of file +} diff --git a/.devcontainer/features/src/postgresql/install.sh b/.devcontainer/features/src/postgresql/install.sh index 1be9638a..b23597ac 100644 --- a/.devcontainer/features/src/postgresql/install.sh +++ b/.devcontainer/features/src/postgresql/install.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list +echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" >/etc/apt/sources.list.d/pgdg.list wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - diff --git a/README.md b/README.md index a3c142e7..a334c757 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ You will also need to have Postgresql installed and running on your machine. ### Pre-commit -To avoid pushing code and seeing the github actions fail due to linting errors, when installing the project for the +To avoid pushing code and seeing the Github actions fail due to linting errors, when installing the project for the first time you should install the pre-commit hooks with: -``` +```commandline pre-commit install ``` diff --git a/controlpanel/settings/common.py b/controlpanel/settings/common.py index 15a32f5b..ca9ca063 100644 --- a/controlpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -21,9 +21,7 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = ( - "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" -) +SECRET_KEY = "django-insecure-!-2v1ja--!*$lz3q6ox+(_d_cc68d5s#72ia-*_&!dom3#$zjn" # SECURITY WARNING: don't run with debug turned on in production! @@ -82,9 +80,7 @@ DB_HOST = os.environ.get("DB_HOST", "127.0.0.1") ENABLE_DB_SSL = ( str( - os.environ.get( - "ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"] - ) + os.environ.get("ENABLE_DB_SSL", DB_HOST not in ["127.0.0.1", "localhost"]) ).lower() == "true" ) diff --git a/manage.py b/manage.py index a20ba8f7..7f134720 100755 --- a/manage.py +++ b/manage.py @@ -15,7 +15,7 @@ def main(): "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" - )(exc) + ) from exc execute_from_command_line(sys.argv) From fccf6a9be7c20f792c23cf00bc393d9d8856921b Mon Sep 17 00:00:00 2001 From: ymao2 Date: Tue, 7 Nov 2023 18:27:24 +0000 Subject: [PATCH 11/28] DPAT-2026 last one from superlinter (hopefully) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a334c757..9d14911f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ You will also need to have Postgresql installed and running on your machine. ### Pre-commit -To avoid pushing code and seeing the Github actions fail due to linting errors, when installing the project for the +To avoid pushing code and seeing the GitHub actions fail due to linting errors, when installing the project for the first time you should install the pre-commit hooks with: ```commandline From 52e3ea870ecbedd6a569db51809d301c41d10f29 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:24:19 +0000 Subject: [PATCH 12/28] Bump line length to match Black, add yamllint to pre-commit --- .flake8 | 2 ++ .pre-commit-config.yaml | 10 ++++++++-- pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.flake8 b/.flake8 index 52a935d3..ceeb99e9 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,5 @@ [flake8] +max-line-length = 88 +extend-ignore = E203, E704 exclude = venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f56ba89..55776018 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +--- repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 @@ -29,11 +30,16 @@ repos: - id: mypy name: mypy additional_dependencies: - - django-stubs - - psycopg2-binary + - django-stubs + - psycopg2-binary - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: - id: isort name: isort (python) + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.32.0 + hooks: + - id: yamllint diff --git a/pyproject.toml b/pyproject.toml index 3c550e98..fbbfffe3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [tool.black] -line-length = 79 +line-length = 88 target-version = ["py311"] From f21558aa7ea9de3458eccb0c10d5c1b512c60d04 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:36:30 +0000 Subject: [PATCH 13/28] Remove django_prometheus from deps --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e6c23bef..165b81bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ asgiref==3.7.2 Django==4.2.7 -django-prometheus==2.3.1 psycopg2-binary==2.9.9 sqlparse==0.4.4 From 40af1a0871029140110f992eef5df08c5e227722 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Nov 2023 10:00:32 +0000 Subject: [PATCH 14/28] Reformat readme --- README.md | 5 ++--- controlpanel/settings/common.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d14911f..85b96c62 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Data Platform Control Panel +[![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Fdata-platform-control-panel&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g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Tp/oNHbzTJI92T1qAT+BfW49MhMg6JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/data-platform-control-panel) + ## Running The quickest way to get the project running is to use the dev container that has been configured to install all @@ -24,6 +26,3 @@ pre-commit install ``` This will run black, mypy, flake8 and isort before a commit to check for failures and stage any required changes. - - -[![repo standards badge](https://img.shields.io/endpoint?labelColor=231f20&color=005ea5&style=for-the-badge&label=MoJ%20Compliant&url=https%3A%2F%2Foperations-engineering-reports.cloud-platform.service.justice.gov.uk%2Fapi%2Fv1%2Fcompliant_public_repositories%2Fendpoint%2Fdata-platform-control-panel&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAHJElEQVRYhe2YeYyW1RWHnzuMCzCIglBQlhSV2gICKlHiUhVBEAsxGqmVxCUUIV1i61YxadEoal1SWttUaKJNWrQUsRRc6tLGNlCXWGyoUkCJ4uCCSCOiwlTm6R/nfPjyMeDY8lfjSSZz3/fee87vnnPu75z3g8/kM2mfqMPVH6mf35t6G/ZgcJ/836Gdug4FjgO67UFn70+FDmjcw9xZaiegWX29lLLmE3QV4Glg8x7WbFfHlFIebS/ANj2oDgX+CXwA9AMubmPNvuqX1SnqKGAT0BFoVE9UL1RH7nSCUjYAL6rntBdg2Q3AgcAo4HDgXeBAoC+wrZQyWS3AWcDSUsomtSswEtgXaAGWlVI2q32BI0spj9XpPww4EVic88vaC7iq5Hz1BvVf6v3qe+rb6ji1p3pWrmtQG9VD1Jn5br+Knmm70T9MfUh9JaPQZu7uLsR9gEsJb3QF9gOagO7AuUTom1LpCcAkoCcwQj0VmJregzaipA4GphNe7w/MBearB7QLYCmlGdiWSm4CfplTHwBDgPHAFmB+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UWEl0NyWNvZxGTs89z6ZnatIIrCdqcCtRJmcCPwCeSN3N1Iu6T4VaFhm9n+riypouBnepLsk9p6p35fzwvDSX5eVQvaDOzjnqzTl+1KC53+XzLINHd65O6lD1DnWbepPBhQ3q2jQyW+2oDkkAtdt5udpb7W+Q/OFGA7ol1zxu1tc8zNHqXercfDfQIOZm9fR815Cpt5PnVqsr1F51wI9QnzU63xZ1o/rdPPmt6enV6sXqHPVqdXOCe1rtrg5W7zNI+m712Ir+cer4POiqfHeJSVe1Raemwnm7xD3mD1E/Z3wIjcsTdlZnqO8bFeNB9c30zgVG2euYa69QJ+9G90lG+99bfdIoo5PU4w362xHePxl1slMab6tV72KUxDvzlAMT8G0ZohXq39VX1bNzzxij9K1Qb9lhdGe931B/kR6/zCwY9YvuytCsMlj+gbr5SemhqkyuzE8xau4MP865JvWNuj0b1YuqDkgvH2GkURfakly01Cg7Cw0+qyXxkjojq9Lw+vT2AUY+DlF/otYq1Ixc35re2V7R8aTRg2KUv7+ou3x/14PsUBn3NG51S0XpG0Z9PcOPKWSS0SKNUo9Rv2Mmt/G5WpPF6pHGra7Jv410OVsdaz217AbkAPX3ubkm240belCuudT4Rp5p/DyC2lf9mfq1iq5eFe8/lu+K0YrVp0uret4nAkwlB6vzjI/1PxrlrTp/oNHbzTJI92T1qAT+BfW49MhMg6JUp7ehY5a6Tl2jjmVvitF9fxo5Yq8CaAfAkzLMnySt6uz/1k6bPx59CpCNxGfoSKA30IPoH7cQXdArwCOllFX/i53P5P9a/gNkKpsCMFRuFAAAAABJRU5ErkJggg==)](https://operations-engineering-reports.cloud-platform.service.justice.gov.uk/public-report/data-platform-control-panel) diff --git a/controlpanel/settings/common.py b/controlpanel/settings/common.py index ca9ca063..26154235 100644 --- a/controlpanel/settings/common.py +++ b/controlpanel/settings/common.py @@ -107,13 +107,13 @@ "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", # noqa }, { - "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", # noqa + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", # noqa + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", # noqa + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] From 176d4e3ea31774d4cfded7121ce823795ad88e5b Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:09:27 +0000 Subject: [PATCH 15/28] Add runArgs to devcontainer.json and fix directory in post-create.sh Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 1 + scripts/devcontainer/post-create.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9c2f4051..9df9c0ff 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,6 +12,7 @@ "./features/src/postgresql": {} }, "postCreateCommand": "bash scripts/devcontainer/post-create.sh", + "runArgs": ["--name=data-platform-control-panel-devcontainer"], "customizations": { "vscode": { "extensions": [ diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index 9b48ad36..f7c2d82c 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Fix directory +git config --global --add safe.directory /workspaces/data-platform-control-panel + # Upgrade NPM npm install --global npm@latest From 1699327821f7326be243f434a936c09ad2fcbace Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:15:57 +0000 Subject: [PATCH 16/28] Remove git and pre-commit Signed-off-by: Jacob Woffenden --- scripts/devcontainer/post-create.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index f7c2d82c..c16dcdd6 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Fix directory -git config --global --add safe.directory /workspaces/data-platform-control-panel +# git config --global --add safe.directory /workspaces/data-platform-control-panel # Upgrade NPM npm install --global npm@latest @@ -16,4 +16,4 @@ pip install --upgrade pip pip install -r requirements.dev.txt # Install precommit hooks -pre-commit install +# pre-commit install From c30d0f928bb8b1b6e6d7683f9036b094490594f9 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:27:20 +0000 Subject: [PATCH 17/28] test pre-commit Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 2 +- scripts/devcontainer/post-create.sh | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9df9c0ff..9b9bcfdc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,7 +11,7 @@ "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "./features/src/postgresql": {} }, - "postCreateCommand": "bash scripts/devcontainer/post-create.sh", + "postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && bash scripts/devcontainer/post-create.sh", "runArgs": ["--name=data-platform-control-panel-devcontainer"], "customizations": { "vscode": { diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index c16dcdd6..9b48ad36 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# Fix directory -# git config --global --add safe.directory /workspaces/data-platform-control-panel - # Upgrade NPM npm install --global npm@latest @@ -16,4 +13,4 @@ pip install --upgrade pip pip install -r requirements.dev.txt # Install precommit hooks -# pre-commit install +pre-commit install From ddffa6d460c16c7cfe1331908e50bb929eacaec3 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:30:21 +0000 Subject: [PATCH 18/28] Remove git and pre-commit Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 2 +- scripts/devcontainer/post-create.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b9bcfdc..9df9c0ff 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -11,7 +11,7 @@ "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "./features/src/postgresql": {} }, - "postCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && bash scripts/devcontainer/post-create.sh", + "postCreateCommand": "bash scripts/devcontainer/post-create.sh", "runArgs": ["--name=data-platform-control-panel-devcontainer"], "customizations": { "vscode": { diff --git a/scripts/devcontainer/post-create.sh b/scripts/devcontainer/post-create.sh index 9b48ad36..916f612e 100644 --- a/scripts/devcontainer/post-create.sh +++ b/scripts/devcontainer/post-create.sh @@ -11,6 +11,3 @@ pip install --upgrade pip # Install dependencies pip install -r requirements.dev.txt - -# Install precommit hooks -pre-commit install From e11aa50220d4bf9a7479d6eb5646a5a6db27e63b Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:38:20 +0000 Subject: [PATCH 19/28] Add postStartCommand for pre-commit Signed-off-by: Jacob Woffenden --- .devcontainer/devcontainer.json | 1 + scripts/devcontainer/post-start.sh | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 scripts/devcontainer/post-start.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9df9c0ff..bd6d479c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,6 +12,7 @@ "./features/src/postgresql": {} }, "postCreateCommand": "bash scripts/devcontainer/post-create.sh", + "postStartCommand": "bash scripts/devcontainer/post-start.sh", "runArgs": ["--name=data-platform-control-panel-devcontainer"], "customizations": { "vscode": { diff --git a/scripts/devcontainer/post-start.sh b/scripts/devcontainer/post-start.sh new file mode 100644 index 00000000..f0289d19 --- /dev/null +++ b/scripts/devcontainer/post-start.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Run pre-commit +pre-commit install From 2170f7290b2e4568b5a1e362fe5cc3f89955ac43 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:42:04 +0000 Subject: [PATCH 20/28] Add hello world Signed-off-by: Jacob Woffenden --- manage.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manage.py b/manage.py index 7f134720..27d47234 100755 --- a/manage.py +++ b/manage.py @@ -21,3 +21,5 @@ def main(): if __name__ == "__main__": main() + +print("hello world") From a55bfec7a9995f3190db79a2d07dc7d6892d8dac Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:52:07 +0000 Subject: [PATCH 21/28] Add Super-Linter Python settings Signed-off-by: Jacob Woffenden --- .github/super-linter.env | 3 +++ manage.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/super-linter.env b/.github/super-linter.env index 18f2eac4..8c6d297d 100644 --- a/.github/super-linter.env +++ b/.github/super-linter.env @@ -1 +1,4 @@ VALIDATE_ALL_CODEBASE="false" +PYTHON_BLACK_CONFIG_FILE="pyproject.toml" +PYTHON_FLAKE8_CONFIG_FILE=".flake8" +PYTHON_MYPY_CONFIG_FILE="mypy.ini" diff --git a/manage.py b/manage.py index 27d47234..7f134720 100755 --- a/manage.py +++ b/manage.py @@ -21,5 +21,3 @@ def main(): if __name__ == "__main__": main() - -print("hello world") From f4b63d4a5bf1f2036b8ccb31355f00c536f9333c Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 12:58:52 +0000 Subject: [PATCH 22/28] Add LINTER_RULES_PATH Signed-off-by: Jacob Woffenden --- .github/super-linter.env | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/super-linter.env b/.github/super-linter.env index 8c6d297d..9928ba9b 100644 --- a/.github/super-linter.env +++ b/.github/super-linter.env @@ -1,4 +1,5 @@ VALIDATE_ALL_CODEBASE="false" +LINTER_RULES_PATH="/" PYTHON_BLACK_CONFIG_FILE="pyproject.toml" PYTHON_FLAKE8_CONFIG_FILE=".flake8" PYTHON_MYPY_CONFIG_FILE="mypy.ini" From 3e949e7ca8e9dc329b751b00ff02f93eaed06e5f Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 13:09:13 +0000 Subject: [PATCH 23/28] Push workarounds Signed-off-by: Jacob Woffenden --- .github/linters/.flake8 | 5 +++++ .github/linters/.mypy.ini | 6 ++++++ .github/linters/pyproject.toml | 3 +++ .github/super-linter.env | 3 +-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .github/linters/.flake8 create mode 100644 .github/linters/.mypy.ini create mode 100644 .github/linters/pyproject.toml diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 new file mode 100644 index 00000000..ceeb99e9 --- /dev/null +++ b/.github/linters/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203, E704 +exclude = + venv diff --git a/.github/linters/.mypy.ini b/.github/linters/.mypy.ini new file mode 100644 index 00000000..9c0280ec --- /dev/null +++ b/.github/linters/.mypy.ini @@ -0,0 +1,6 @@ +[mypy] +plugins = + mypy_django_plugin.main + +[mypy.plugins.django-stubs] +django_settings_module = "controlpanel.settings" diff --git a/.github/linters/pyproject.toml b/.github/linters/pyproject.toml new file mode 100644 index 00000000..fbbfffe3 --- /dev/null +++ b/.github/linters/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +line-length = 88 +target-version = ["py311"] diff --git a/.github/super-linter.env b/.github/super-linter.env index 9928ba9b..dacd3173 100644 --- a/.github/super-linter.env +++ b/.github/super-linter.env @@ -1,5 +1,4 @@ VALIDATE_ALL_CODEBASE="false" -LINTER_RULES_PATH="/" PYTHON_BLACK_CONFIG_FILE="pyproject.toml" PYTHON_FLAKE8_CONFIG_FILE=".flake8" -PYTHON_MYPY_CONFIG_FILE="mypy.ini" +PYTHON_MYPY_CONFIG_FILE=".mypy.ini" From 2d86d8154640c6c3e4668dd09e012c92ff068cf3 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:07:11 +0000 Subject: [PATCH 24/28] Pass env vars direct to github action --- .github/workflows/super-linter.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 1bc93675..75bcaaed 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -33,7 +33,13 @@ jobs: - name: Super-Linter id: super_linter + # yamllint disable-line rule:line-length uses: super-linter/super-linter/slim@35c3fa445cc217dfcc7b53eeb4e7aa95fcdd02fc # v5.6.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} DEFAULT_BRANCH: main + VALIDATE_ALL_CODEBASE: false + LINTER_RULES_PATH: / + PYTHON_BLACK_CONFIG_FILE: pyproject.toml + PYTHON_FLAKE8_CONFIG_FILE: .flake8 + PYTHON_MYPY_CONFIG_FILE: mypy.ini From 02d5ba78ad0d8813f6409306c9b4e6f0bfed1518 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:31:25 +0000 Subject: [PATCH 25/28] Ignore missing import errors in mypy --- mypy.ini | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mypy.ini b/mypy.ini index 9c0280ec..976ba029 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,6 +1,2 @@ [mypy] -plugins = - mypy_django_plugin.main - -[mypy.plugins.django-stubs] -django_settings_module = "controlpanel.settings" +ignore_missing_imports = True From 563daddc7eae32e2d15c89873755d5d248a46245 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 15:38:01 +0000 Subject: [PATCH 26/28] Remove Super-Linter hackery Signed-off-by: Jacob Woffenden --- .github/linters/.flake8 | 5 ----- .github/linters/.mypy.ini | 6 ------ .github/linters/pyproject.toml | 3 --- scripts/super-linter/run-local.sh | 31 ------------------------------- 4 files changed, 45 deletions(-) delete mode 100644 .github/linters/.flake8 delete mode 100644 .github/linters/.mypy.ini delete mode 100644 .github/linters/pyproject.toml delete mode 100644 scripts/super-linter/run-local.sh diff --git a/.github/linters/.flake8 b/.github/linters/.flake8 deleted file mode 100644 index ceeb99e9..00000000 --- a/.github/linters/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -max-line-length = 88 -extend-ignore = E203, E704 -exclude = - venv diff --git a/.github/linters/.mypy.ini b/.github/linters/.mypy.ini deleted file mode 100644 index 9c0280ec..00000000 --- a/.github/linters/.mypy.ini +++ /dev/null @@ -1,6 +0,0 @@ -[mypy] -plugins = - mypy_django_plugin.main - -[mypy.plugins.django-stubs] -django_settings_module = "controlpanel.settings" diff --git a/.github/linters/pyproject.toml b/.github/linters/pyproject.toml deleted file mode 100644 index fbbfffe3..00000000 --- a/.github/linters/pyproject.toml +++ /dev/null @@ -1,3 +0,0 @@ -[tool.black] -line-length = 88 -target-version = ["py311"] diff --git a/scripts/super-linter/run-local.sh b/scripts/super-linter/run-local.sh deleted file mode 100644 index f3b508ae..00000000 --- a/scripts/super-linter/run-local.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -MODE="${1:-local}" - -case "${MODE}" in -local) - echo "Running Super-Linter in RUN_LOCAL mode" - docker run --rm \ - --env RUN_LOCAL="true" \ - --env CREATE_LOG_FILE="true" \ - --env LOG_FILE_NAME="/tmp/log/super-linter.log" \ - --env-file ".github/super-linter.env" \ - --volume "${PWD}":/tmp/log \ - --volume "${PWD}":/tmp/lint \ - ghcr.io/super-linter/super-linter:slim-v5 - ;; -interactive) - echo "Running Super-Linter in INTERACTIVE mode" - docker run --rm -it \ - --env-file ".github/super-linter.env" \ - --entrypoint /bin/bash \ - --volume "${PWD}":/tmp/lint \ - --workdir /tmp/lint \ - ghcr.io/super-linter/super-linter:slim-v5 - ;; -*) - echo "Invalid mode: ${MODE}" - echo "Usage: ${0} [local|interactive]" - exit 1 - ;; -esac From 8bd6e2b46cb03496074e5bc4dfae403eedfd6a51 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 15:39:54 +0000 Subject: [PATCH 27/28] Removed Super-Linter env Signed-off-by: Jacob Woffenden --- .github/super-linter.env | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .github/super-linter.env diff --git a/.github/super-linter.env b/.github/super-linter.env deleted file mode 100644 index dacd3173..00000000 --- a/.github/super-linter.env +++ /dev/null @@ -1,4 +0,0 @@ -VALIDATE_ALL_CODEBASE="false" -PYTHON_BLACK_CONFIG_FILE="pyproject.toml" -PYTHON_FLAKE8_CONFIG_FILE=".flake8" -PYTHON_MYPY_CONFIG_FILE=".mypy.ini" From b35809a56fc0d082b08cede156c5f9a3199735d5 Mon Sep 17 00:00:00 2001 From: Jacob Woffenden Date: Wed, 8 Nov 2023 15:44:03 +0000 Subject: [PATCH 28/28] Removed var loading step Signed-off-by: Jacob Woffenden --- .github/workflows/super-linter.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 75bcaaed..1d066bc1 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -27,10 +27,6 @@ jobs: with: fetch-depth: 0 - - name: Load Super-Linter Variables - id: load_super_linter_variables - run: cat .github/super-linter.env >>"${GITHUB_ENV}" - - name: Super-Linter id: super_linter # yamllint disable-line rule:line-length