From a6a0d7772959e95ac9e69ee5aa5c83cd795088df Mon Sep 17 00:00:00 2001 From: Stefan Kairinos Date: Tue, 5 Mar 2024 15:02:08 +0000 Subject: [PATCH] simplify dev container setup (#312) * simplify dev container setup * synced with submodule configs * fix settings * add env vars when launching django server * add docstring mustache * "Configured submodule [skip ci]" * "Configured submodule [skip ci]" * "Configured submodule [skip ci]" * "Configured submodule [skip ci]" * Merge branch 'development' into mount_py_package --- .devcontainer.json | 49 +++++++ ...ode-snippets => codeforlife.code-snippets} | 62 +++++---- .vscode/extensions.json | 13 -- .../autoDocstring/docstring.mustache | 35 +++++ .vscode/launch.json | 57 ++++---- .vscode/settings.json | 122 +++++++++++------- .vscode/tasks.json | 71 +++++----- backend/Pipfile | 28 +++- backend/pyproject.toml | 1 + codeforlife.code-workspace | 22 ++++ 10 files changed, 302 insertions(+), 158 deletions(-) create mode 100644 .devcontainer.json rename .vscode/{workspace.code-snippets => codeforlife.code-snippets} (71%) delete mode 100644 .vscode/extensions.json create mode 100644 .vscode/extensions/autoDocstring/docstring.mustache create mode 100644 codeforlife.code-workspace diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 00000000..fc44d97f --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,49 @@ +{ + "customizations": { + "vscode": { + "extensions": [ + "visualstudioexptteam.vscodeintellicode", + "github.vscode-pull-request-github", + "redhat.vscode-yaml", + "davidanson.vscode-markdownlint", + "bierner.markdown-mermaid", + "streetsidesoftware.code-spell-checker", + "dbaeumer.vscode-eslint", + "ms-python.python", + "ms-python.debugpy", + "ms-python.pylint", + "ms-python.isort", + "ms-python.vscode-pylance", + "ms-python.mypy-type-checker", + "ms-python.black-formatter", + "qwtel.sqlite-viewer", + "njpwerner.autodocstring" + ] + } + }, + "dockerComposeFile": [ + "../docker-compose.yml" + ], + "features": { + "ghcr.io/devcontainers-contrib/features/pipenv:2": { + "version": "2023.11.15" + }, + "ghcr.io/devcontainers/features/node:1": { + "version": "18" + }, + "ghcr.io/devcontainers/features/python:1": { + "installTools": false, + "version": "3.8" + } + }, + "mounts": [ + "source=./codeforlife-package-javascript,target=/workspace/codeforlife-package-javascript,type=bind,consistency=cached", + "source=./codeforlife-package-python,target=/workspace/codeforlife-package-python,type=bind,consistency=cached" + ], + "name": "portal-react", + "postCreateCommand": "./setup", + "remoteUser": "root", + "service": "base-service", + "shutdownAction": "none", + "workspaceFolder": "/workspace/codeforlife-portal-react" +} \ No newline at end of file diff --git a/.vscode/workspace.code-snippets b/.vscode/codeforlife.code-snippets similarity index 71% rename from .vscode/workspace.code-snippets rename to .vscode/codeforlife.code-snippets index 3e6a570c..e45c7bb5 100644 --- a/.vscode/workspace.code-snippets +++ b/.vscode/codeforlife.code-snippets @@ -1,51 +1,49 @@ { - "module.docstring": { + "javascript.module.doccomment": { + "body": [ + "/**", + " * \u00a9 Ocado Group", + " * Created on $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR at $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND($CURRENT_TIMEZONE_OFFSET).", + " *", + " * ${1:__description__}", + " */" + ], "prefix": [ - "module.docstring", - "\"\"\"", - "'''" + "/" ], - "scope": "python", + "scope": "javascript,typescript,javascriptreact,typescriptreact" + }, + "python.module.docstring": { "body": [ "\"\"\"", - "© Ocado Group", - "Created on $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR at $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND($CURRENT_TIMEZONE_OFFSET)." + "\u00a9 Ocado Group", + "Created on $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR at $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND($CURRENT_TIMEZONE_OFFSET).", "", "${1:__description__}", "\"\"\"" - ] - }, - "module.doccomment": { + ], "prefix": [ - "module.doccomment", - "/" + "\"\"\"", + "'''" ], - "scope": "javascript,typescript,javascriptreact,typescriptreact", - "body": [ - "/**", - " * © Ocado Group", - " * Created on $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR at $CURRENT_HOUR:$CURRENT_MINUTE:$CURRENT_SECOND($CURRENT_TIMEZONE_OFFSET)." - " *", - " * ${1:__description__}", - " */" - ] + "scope": "python" }, - "pylint.disable-next": { + "python.mypy.ignore": { + "body": [ + "# type: ignore[${1:__code_name__}]" + ], "prefix": [ - "# pylint" + "# type" ], - "scope": "python", + "scope": "python" + }, + "python.pylint.disable-next": { "body": [ "# pylint: disable-next=${1:__code_name__}" - ] - }, - "mypy.ignore": { + ], "prefix": [ - "# type" + "# pylint" ], - "scope": "python", - "body": [ - "# type: ignore[${1:__code_name__}]" - ] + "scope": "python" } } \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index 7ef36c17..00000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "dbaeumer.vscode-eslint" - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [ - - ] -} \ No newline at end of file diff --git a/.vscode/extensions/autoDocstring/docstring.mustache b/.vscode/extensions/autoDocstring/docstring.mustache new file mode 100644 index 00000000..64a5b91a --- /dev/null +++ b/.vscode/extensions/autoDocstring/docstring.mustache @@ -0,0 +1,35 @@ +{{! Based off of: https://github.com/NilsJPWerner/autoDocstring/blob/master/src/docstring/templates/google-notypes.mustache }} +{{summaryPlaceholder}} + +{{extendedSummaryPlaceholder}} +{{#parametersExist}} + +Args: +{{#args}} + {{var}}: {{descriptionPlaceholder}} +{{/args}} +{{#kwargs}} + {{var}}: {{descriptionPlaceholder}} +{{/kwargs}} +{{/parametersExist}} +{{#exceptionsExist}} + +Raises: +{{#exceptions}} + {{type}}: {{descriptionPlaceholder}} +{{/exceptions}} +{{/exceptionsExist}} +{{#returnsExist}} + +Returns: +{{#returns}} + {{descriptionPlaceholder}} +{{/returns}} +{{/returnsExist}} +{{#yieldsExist}} + +Yields: +{{#yields}} + {{descriptionPlaceholder}} +{{/yields}} +{{/yieldsExist}} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a6ac46c..44da6867 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,41 +1,46 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", "configurations": [ { - "type": "chrome", + "console": "integratedTerminal", + "justMyCode": false, + "name": "Python: Current File", + "program": "${file}", "request": "launch", - "name": "React Dev Server", - "url": "http://localhost:3000", - "preLaunchTask": "start-react-dev-server" + "type": "debugpy" }, { - "name": "Django Server", - "type": "python", - "request": "launch", - "django": true, "justMyCode": false, - "program": "${workspaceFolder}/backend/manage.py", + "name": "Pytest", + "presentation": { + "hidden": true + }, + "request": "test", + "type": "debugpy" + }, + { + "name": "React Dev Server", + "preLaunchTask": "start-react-dev-server", + "request": "launch", + "type": "chrome", + "url": "http://localhost:3000" + }, + { "args": [ "runserver", "localhost:8000" ], - "preLaunchTask": "migrate-db", + "django": true, "env": { - "SERVICE_NAME": "portal", - "SERVICE_IS_ROOT": "1" - } - }, - { - "name": "Pytest", - "type": "python", - "request": "test", + "SERVICE_IS_ROOT": "1", + "SERVICE_NAME": "portal" + }, "justMyCode": false, - "presentation": { - "hidden": true - } + "name": "Django Server", + "preLaunchTask": "migrate-db", + "program": "${workspaceFolder}/backend/manage.py", + "request": "launch", + "type": "debugpy" } - ] + ], + "version": "0.2.0" } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 28889958..765e605f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,47 +1,79 @@ { - "editor.tabSize": 2, - "javascript.preferences.quoteStyle": "single", - "typescript.preferences.quoteStyle": "single", - "isort.path": [ - "backend/.venv/bin/python", - "-m", - "isort" - ], - "isort.args": [ - "--settings-file=backend/pyproject.toml" - ], - "black-formatter.path": [ - "backend/.venv/bin/python", - "-m", - "black" - ], - "black-formatter.args": [ - "--config=backend/pyproject.toml" - ], - "mypy-type-checker.cwd": "${workspaceFolder}/backend", - "mypy-type-checker.path": [ - ".venv/bin/python", - "-m", - "mypy" - ], - "mypy-type-checker.args": [ - "--config-file=pyproject.toml" - ], - "pylint.cwd": "${workspaceFolder}/backend", - "pylint.path": [ - ".venv/bin/python", - "-m", - "pylint" - ], - "pylint.args": [ - "--rcfile=pyproject.toml" - ], - "python.testing.cwd": "${workspaceFolder}/backend", - "python.testing.pytestArgs": [ - "-n=auto", - "-c=pyproject.toml", - "." - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true + "[md]": { + "editor.tabSize": 4 + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.tabSize": 4 + }, + "black-formatter.args": [ + "--config", + "pyproject.toml" + ], + "black-formatter.cwd": "${workspaceFolder}/backend", + "black-formatter.path": [ + ".venv/bin/python", + "-m", + "black" + ], + "cSpell.words": [ + "codeforlife", + "klass", + "ocado", + "kurono", + "pipenv" + ], + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "editor.formatOnSave": true, + "editor.rulers": [ + 80 + ], + "editor.tabSize": 2, + "files.exclude": { + "**/.hypothesis": true, + "**/.mypy_cache": true, + "**/.pytest_cache": true, + "**/__pycache__": true + }, + "isort.args": [ + "--settings-file=backend/pyproject.toml" + ], + "isort.path": [ + "backend/.venv/bin/python", + "-m", + "isort" + ], + "mypy-type-checker.args": [ + "--config-file=pyproject.toml" + ], + "mypy-type-checker.cwd": "${workspaceFolder}/backend", + "mypy-type-checker.path": [ + ".venv/bin/python", + "-m", + "mypy" + ], + "pylint.args": [ + "--rcfile=pyproject.toml" + ], + "pylint.cwd": "${workspaceFolder}/backend", + "pylint.path": [ + ".venv/bin/python", + "-m", + "pylint" + ], + "python.analysis.extraPaths": [ + "../codeforlife-package-python" + ], + "python.defaultInterpreterPath": "backend/.venv/bin/python", + "python.testing.cwd": "${workspaceFolder}/backend", + "python.testing.pytestArgs": [ + "-n=auto", + "-c=pyproject.toml", + "." + ], + "python.testing.pytestEnabled": true, + "python.testing.unittestEnabled": false, + "typescript.preferences.quoteStyle": "single" } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ed16f832..ed804e8e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,38 +1,37 @@ { - "version": "2.0.0", - "tasks": [ - { - "isBackground": true, - "type": "npm", - "script": "start", - "options": { - "env": { - "BROWSER": "none", - "REACT_APP_SERVICE_NAME": "portal" - } - }, - "path": "frontend", - "problemMatcher": [], - "label": "start-react-dev-server" - }, - { - "label": "install-dev-deps", - "type": "shell", - "options": { - "cwd": "${workspaceFolder}/backend" - }, - "command": "pipenv install --dev" - }, - { - "label": "migrate-db", - "type": "shell", - "options": { - "cwd": "${workspaceFolder}/backend" - }, - "dependsOn": [ - "install-dev-deps" - ], - "command": "pipenv run python ./manage.py migrate" - } - ] + "tasks": [ + { + "isBackground": true, + "label": "start-react-dev-server", + "options": { + "env": { + "BROWSER": "none" + } + }, + "path": "frontend", + "problemMatcher": [], + "script": "start", + "type": "npm" + }, + { + "command": "pipenv install --dev", + "label": "pipenv-install-dev", + "options": { + "cwd": "${workspaceFolder}/backend" + }, + "type": "shell" + }, + { + "command": "pipenv run python ./manage.py migrate", + "dependsOn": [ + "pipenv-install-dev" + ], + "label": "migrate-db", + "options": { + "cwd": "${workspaceFolder}/backend" + }, + "type": "shell" + } + ], + "version": "2.0.0" } \ No newline at end of file diff --git a/backend/Pipfile b/backend/Pipfile index 8cfa0241..e123a847 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -3,11 +3,28 @@ url = "https://pypi.org/simple" verify_ssl = true name = "pypi" +## ℹ️ HOW-TO: Make the python-package editable. +# +# 1. Comment out the git-codeforlife package under [packages]. +# 2. Comment out the git-codeforlife package under [dev-packages]. +# 3. Uncomment the editable-codeforlife package under [dev-packages]. +# 4. Run `pipenv install --dev` in your terminal. +# +# ⚠️ Make sure you revert these changes before pushing your changes or the +# pipeline will fail to install the python-package. +# +## ℹ️ HOW-TO: Install a new version of the python-package. +# +# 1. Uncomment the git-codeforlife package under [packages]. +# 2. Uncomment the git-codeforlife package under [dev-packages]. +# 3. Comment out the editable-codeforlife package under [dev-packages]. +# 4. Set the ref key of the git-codeforlife packages under [packages] and +# [dev-packages] to have the same version number. +# 5. Run `pipenv install --dev` in your terminal. + [packages] -# Before adding a new package, check it's not listed under [packages] at -# https://github.com/ocadotechnology/codeforlife-package-python/blob/{ref}/Pipfile -# Replace "{ref}" in the above URL with the ref set below. codeforlife = {ref = "v0.14.0", git = "https://github.com/ocadotechnology/codeforlife-package-python.git"} +# 🚫 Don't add [packages] below that are inhertited from the CFL package. # TODO: check if we need the below packages whitenoise = "==6.5.0" django-pipeline = "==2.0.8" @@ -31,10 +48,9 @@ google-cloud-container = "==2.3.0" # "django-anymail[amazon_ses]" = "==7.0.*" [dev-packages] -# Before adding a new package, check it's not listed under [dev-packages] at -# https://github.com/ocadotechnology/codeforlife-package-python/blob/{ref}/Pipfile -# Replace "{ref}" in the above URL with the ref set below. codeforlife = {ref = "v0.14.0", git = "https://github.com/ocadotechnology/codeforlife-package-python.git", extras = ["dev"]} +# codeforlife = {file = "../../codeforlife-package-python", editable = true, extras = ["dev"]} +# 🚫 Don't add [dev-packages] below that are inhertited from the CFL package. # TODO: check if we need the below packages django-selenium-clean = "==0.3.3" django-test-migrations = "==1.2.0" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 73d5c6ca..54059f01 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -12,6 +12,7 @@ env = [ [tool.mypy] plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"] check_untyped_defs = true +mypy_path = "../../codeforlife-package-python" [tool.django-stubs] django_settings_module = "service.settings" diff --git a/codeforlife.code-workspace b/codeforlife.code-workspace new file mode 100644 index 00000000..51a0c43f --- /dev/null +++ b/codeforlife.code-workspace @@ -0,0 +1,22 @@ +{ + "folders": [ + { + "name": "portal-react", + "path": "." + }, + { + "name": "package-python", + "path": "../codeforlife-package-python" + }, + { + "name": "package-javascript", + "path": "../codeforlife-package-javascript" + } + ], + "settings": { + "autoDocstring.customTemplatePath": ".vscode/extensions/autoDocstring/docstring.mustache", + "workbench.colorCustomizations": { + "editorRuler.foreground": "#008000" + } + } +} \ No newline at end of file