From fb506b92f4dd3b309b11a26a6d5120d00a9f0139 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Wed, 19 Jun 2024 14:32:01 +0000 Subject: [PATCH 1/8] chore: create basic devcontainer --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 39 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 13 +++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..42c9219 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM python:3.12 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..162d23c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +{ + "name": "retro_olympics_webapp", + "dockerComposeFile": "docker-compose.yml", + "workspaceFolder": "/workspace", + "service": "webapp", + "customizations": { + "vscode": { + "settings": { + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.flake8Args": [ + "--max-line-length=88" + ], + "python.linting.mypyEnabled": true, + "python.formatting.provider": "black", + "python.sortImports.args": [ + "--profile", + "black" + ], + "python.analysis.autoImportCompletions": false, + "[python]": { + "editor.codeActionsOnSave": { + "source.organizeImports": true + } + } + }, + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "eamodio.gitlens", + "esbenp.prettier-vscode" + ] + } + }, + "remoteUser": "root", + "remoteEnv": { + "PYTHONPATH": "/workspace/backend/src" + } +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..c4e1ce5 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.8" +services: + webapp: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + entrypoint: ["tail", "-f", "/dev/null"] + volumes: + - ..:/workspace + postgres: + image: "postgres:16" + environment: + POSTGRES_HOST_AUTH_METHOD: trust \ No newline at end of file From 655816c025ee225c258495affc825c18e68cf753 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 11:57:11 +0000 Subject: [PATCH 2/8] add python dev reqs: black for autoformatting, invoke and pip-tools --- .devcontainer/Dockerfile | 6 +++- .devcontainer/devcontainer.json | 61 ++++++++++++++------------------- backend/requirements-dev.in | 3 ++ 3 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 backend/requirements-dev.in diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 42c9219..2c5e820 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1 +1,5 @@ -FROM python:3.12 \ No newline at end of file +FROM python:3.12 + +# Install python requirements +COPY backend/requirements-combined.txt requirements-combined.txt +RUN pip install -r requirements-combined.txt \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 162d23c..52f65d2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,39 +1,28 @@ { - "name": "retro_olympics_webapp", - "dockerComposeFile": "docker-compose.yml", - "workspaceFolder": "/workspace", - "service": "webapp", - "customizations": { - "vscode": { - "settings": { - "python.linting.pylintEnabled": false, - "python.linting.flake8Enabled": true, - "python.linting.flake8Args": [ - "--max-line-length=88" - ], - "python.linting.mypyEnabled": true, - "python.formatting.provider": "black", - "python.sortImports.args": [ - "--profile", - "black" - ], - "python.analysis.autoImportCompletions": false, - "[python]": { - "editor.codeActionsOnSave": { - "source.organizeImports": true - } - } - }, - "extensions": [ - "ms-python.python", - "ms-python.vscode-pylance", - "eamodio.gitlens", - "esbenp.prettier-vscode" - ] + "name": "retro_olympics_webapp", + "dockerComposeFile": "docker-compose.yml", + "workspaceFolder": "/workspace", + "service": "webapp", + "customizations": { + "vscode": { + "settings": { + "python.linting.pylintEnabled": false, + "python.linting.mypyEnabled": false, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true } - }, - "remoteUser": "root", - "remoteEnv": { - "PYTHONPATH": "/workspace/backend/src" + }, + "extensions": [ + "eamodio.gitlens", + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.black-formatter" + ] } -} \ No newline at end of file + }, + "remoteUser": "root", + "remoteEnv": { + "PYTHONPATH": "/workspace/backend/src" + } +} diff --git a/backend/requirements-dev.in b/backend/requirements-dev.in new file mode 100644 index 0000000..cf83c60 --- /dev/null +++ b/backend/requirements-dev.in @@ -0,0 +1,3 @@ +black==24.4.2 +invoke==2.2.0 +pip-tools==7.4.1 \ No newline at end of file From c85dddc241916fbb25cf0d80b50040c15ababce4 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:00:37 +0000 Subject: [PATCH 3/8] add isort --- .devcontainer/devcontainer.json | 11 ++++++++--- backend/requirements-dev.in | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 52f65d2..b910d4b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,14 +10,19 @@ "python.linting.mypyEnabled": false, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", - "editor.formatOnSave": true - } + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + } + }, + "isort.args": ["--profile", "black"] }, "extensions": [ "eamodio.gitlens", "ms-python.python", "ms-python.vscode-pylance", - "ms-python.black-formatter" + "ms-python.black-formatter", + "ms-python.isort" ] } }, diff --git a/backend/requirements-dev.in b/backend/requirements-dev.in index cf83c60..1140f84 100644 --- a/backend/requirements-dev.in +++ b/backend/requirements-dev.in @@ -1,3 +1,4 @@ black==24.4.2 invoke==2.2.0 -pip-tools==7.4.1 \ No newline at end of file +pip-tools==7.4.1 +isort==5.13.2 \ No newline at end of file From 01f430ae29d8763e9643327023aa64327392638c Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:04:53 +0000 Subject: [PATCH 4/8] add ruff --- .devcontainer/devcontainer.json | 6 ++++-- backend/requirements-dev.in | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b910d4b..846c108 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,14 +15,16 @@ "source.organizeImports": "always" } }, - "isort.args": ["--profile", "black"] + "isort.args": ["--profile", "black"], + "ruff.nativeServer": true }, "extensions": [ "eamodio.gitlens", "ms-python.python", "ms-python.vscode-pylance", "ms-python.black-formatter", - "ms-python.isort" + "ms-python.isort", + "charliermarsh.ruff" ] } }, diff --git a/backend/requirements-dev.in b/backend/requirements-dev.in index 1140f84..a3753a4 100644 --- a/backend/requirements-dev.in +++ b/backend/requirements-dev.in @@ -1,4 +1,5 @@ black==24.4.2 invoke==2.2.0 pip-tools==7.4.1 -isort==5.13.2 \ No newline at end of file +isort==5.13.2 +ruff==0.4.9 \ No newline at end of file From 788a6f400bfb18342404865f7313f0992725a2b6 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:29:25 +0000 Subject: [PATCH 5/8] setup a hello world flask app --- .gitignore | 3 + backend/.gitkeep | 0 backend/requirements-combined.txt | 57 +++++++++++++++++++ backend/requirements.in | 1 + backend/requirements.txt | 22 +++++++ backend/src/api/__init__.py | 3 + backend/src/api/components/hello/__init__.py | 3 + .../src/api/components/hello/controller.py | 9 +++ backend/src/api/consts.py | 1 + backend/src/api/main.py | 15 +++++ tasks.py | 20 +++++++ 11 files changed, 134 insertions(+) delete mode 100644 backend/.gitkeep create mode 100644 backend/requirements-combined.txt create mode 100644 backend/requirements.in create mode 100644 backend/requirements.txt create mode 100644 backend/src/api/__init__.py create mode 100644 backend/src/api/components/hello/__init__.py create mode 100644 backend/src/api/components/hello/controller.py create mode 100644 backend/src/api/consts.py create mode 100644 backend/src/api/main.py create mode 100644 tasks.py diff --git a/.gitignore b/.gitignore index 969997e..79ddccc 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ build # typescript *.tsbuildinfo next-env.d.ts + +# Python +*.pyc \ No newline at end of file diff --git a/backend/.gitkeep b/backend/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/backend/requirements-combined.txt b/backend/requirements-combined.txt new file mode 100644 index 0000000..159ca8b --- /dev/null +++ b/backend/requirements-combined.txt @@ -0,0 +1,57 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile --output-file=backend/requirements-combined.txt backend/requirements-dev.in backend/requirements.in +# +black==24.4.2 + # via -r backend/requirements-dev.in +blinker==1.8.2 + # via flask +build==1.2.1 + # via pip-tools +click==8.1.7 + # via + # black + # flask + # pip-tools +flask==3.0.3 + # via -r backend/requirements.in +invoke==2.2.0 + # via -r backend/requirements-dev.in +isort==5.13.2 + # via -r backend/requirements-dev.in +itsdangerous==2.2.0 + # via flask +jinja2==3.1.4 + # via flask +markupsafe==2.1.5 + # via + # jinja2 + # werkzeug +mypy-extensions==1.0.0 + # via black +packaging==24.1 + # via + # black + # build +pathspec==0.12.1 + # via black +pip-tools==7.4.1 + # via -r backend/requirements-dev.in +platformdirs==4.2.2 + # via black +pyproject-hooks==1.1.0 + # via + # build + # pip-tools +ruff==0.4.9 + # via -r backend/requirements-dev.in +werkzeug==3.0.3 + # via flask +wheel==0.43.0 + # via pip-tools + +# The following packages are considered to be unsafe in a requirements file: +# pip +# setuptools diff --git a/backend/requirements.in b/backend/requirements.in new file mode 100644 index 0000000..a993b8d --- /dev/null +++ b/backend/requirements.in @@ -0,0 +1 @@ +Flask==3.0.3 \ No newline at end of file diff --git a/backend/requirements.txt b/backend/requirements.txt new file mode 100644 index 0000000..8793ec9 --- /dev/null +++ b/backend/requirements.txt @@ -0,0 +1,22 @@ +# +# This file is autogenerated by pip-compile with Python 3.12 +# by the following command: +# +# pip-compile backend/requirements.in +# +blinker==1.8.2 + # via flask +click==8.1.7 + # via flask +flask==3.0.3 + # via -r backend/requirements.in +itsdangerous==2.2.0 + # via flask +jinja2==3.1.4 + # via flask +markupsafe==2.1.5 + # via + # jinja2 + # werkzeug +werkzeug==3.0.3 + # via flask diff --git a/backend/src/api/__init__.py b/backend/src/api/__init__.py new file mode 100644 index 0000000..ba338fd --- /dev/null +++ b/backend/src/api/__init__.py @@ -0,0 +1,3 @@ +from .main import get_api + +__all__ = ["get_api"] diff --git a/backend/src/api/components/hello/__init__.py b/backend/src/api/components/hello/__init__.py new file mode 100644 index 0000000..87fb2ba --- /dev/null +++ b/backend/src/api/components/hello/__init__.py @@ -0,0 +1,3 @@ +from .controller import hello_api + +__all__ = ["hello_api"] diff --git a/backend/src/api/components/hello/controller.py b/backend/src/api/components/hello/controller.py new file mode 100644 index 0000000..295c5b5 --- /dev/null +++ b/backend/src/api/components/hello/controller.py @@ -0,0 +1,9 @@ +from api.consts import COMMON_API_PREFIX +from flask import Blueprint, jsonify + +hello_api = Blueprint("hello_api", __name__, url_prefix=COMMON_API_PREFIX + "/hello") + + +@hello_api.route("/", methods=["GET"]) +def get_collections(): + return jsonify({"message": "Hello World ! From the retro olympics backend !"}), 200 diff --git a/backend/src/api/consts.py b/backend/src/api/consts.py new file mode 100644 index 0000000..7afb23c --- /dev/null +++ b/backend/src/api/consts.py @@ -0,0 +1 @@ +COMMON_API_PREFIX = "/api/v1" diff --git a/backend/src/api/main.py b/backend/src/api/main.py new file mode 100644 index 0000000..cfda193 --- /dev/null +++ b/backend/src/api/main.py @@ -0,0 +1,15 @@ +from api.components.hello import hello_api +from flask import Flask + +api: Flask | None = None + + +def get_api() -> Flask: + global api + if api is None: + api = Flask(__name__) + + api.register_blueprint(hello_api) + + return api + diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..3839be8 --- /dev/null +++ b/tasks.py @@ -0,0 +1,20 @@ +from api import get_api +from invoke import task + + +# Python reqs +@task +def update_app_reqs(c): + c.run("pip-compile backend/requirements.in") + + +@task +def update_combined_reqs(c): + c.run( + "pip-compile backend/requirements.in backend/requirements-dev.in -o backend/requirements-combined.txt" + ) + +# Run +@task +def run_back(c): + get_api().run() \ No newline at end of file From 39fe704b6667dce417c9ed7455e139d359d60c03 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:31:16 +0000 Subject: [PATCH 6/8] apply black and isort --- backend/src/api/components/hello/controller.py | 3 ++- backend/src/api/main.py | 4 ++-- tasks.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/api/components/hello/controller.py b/backend/src/api/components/hello/controller.py index 295c5b5..00efe8a 100644 --- a/backend/src/api/components/hello/controller.py +++ b/backend/src/api/components/hello/controller.py @@ -1,6 +1,7 @@ -from api.consts import COMMON_API_PREFIX from flask import Blueprint, jsonify +from api.consts import COMMON_API_PREFIX + hello_api = Blueprint("hello_api", __name__, url_prefix=COMMON_API_PREFIX + "/hello") diff --git a/backend/src/api/main.py b/backend/src/api/main.py index cfda193..3aac698 100644 --- a/backend/src/api/main.py +++ b/backend/src/api/main.py @@ -1,6 +1,7 @@ -from api.components.hello import hello_api from flask import Flask +from api.components.hello import hello_api + api: Flask | None = None @@ -12,4 +13,3 @@ def get_api() -> Flask: api.register_blueprint(hello_api) return api - diff --git a/tasks.py b/tasks.py index 3839be8..1964e61 100644 --- a/tasks.py +++ b/tasks.py @@ -14,7 +14,8 @@ def update_combined_reqs(c): "pip-compile backend/requirements.in backend/requirements-dev.in -o backend/requirements-combined.txt" ) + # Run @task def run_back(c): - get_api().run() \ No newline at end of file + get_api().run() From 799cb078fc27991500501b12beff8683da565639 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:38:32 +0000 Subject: [PATCH 7/8] remove deprecated settings from devcontainer.json --- .devcontainer/devcontainer.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 846c108..3def489 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,8 +6,6 @@ "customizations": { "vscode": { "settings": { - "python.linting.pylintEnabled": false, - "python.linting.mypyEnabled": false, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnSave": true, From 01773fd47a5997f77cdfa8f5a5a8385fae32b664 Mon Sep 17 00:00:00 2001 From: amine4567 Date: Thu, 20 Jun 2024 12:42:17 +0000 Subject: [PATCH 8/8] fix imports order --- tasks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 1964e61..9a7dab7 100644 --- a/tasks.py +++ b/tasks.py @@ -1,6 +1,7 @@ -from api import get_api from invoke import task +from api import get_api + # Python reqs @task