diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..2c5e820 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..3def489 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,33 @@ +{ + "name": "retro_olympics_webapp", + "dockerComposeFile": "docker-compose.yml", + "workspaceFolder": "/workspace", + "service": "webapp", + "customizations": { + "vscode": { + "settings": { + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + } + }, + "isort.args": ["--profile", "black"], + "ruff.nativeServer": true + }, + "extensions": [ + "eamodio.gitlens", + "ms-python.python", + "ms-python.vscode-pylance", + "ms-python.black-formatter", + "ms-python.isort", + "charliermarsh.ruff" + ] + } + }, + "remoteUser": "root", + "remoteEnv": { + "PYTHONPATH": "/workspace/backend/src" + } +} 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 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-dev.in b/backend/requirements-dev.in new file mode 100644 index 0000000..a3753a4 --- /dev/null +++ b/backend/requirements-dev.in @@ -0,0 +1,5 @@ +black==24.4.2 +invoke==2.2.0 +pip-tools==7.4.1 +isort==5.13.2 +ruff==0.4.9 \ No newline at end of file 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..00efe8a --- /dev/null +++ b/backend/src/api/components/hello/controller.py @@ -0,0 +1,10 @@ +from flask import Blueprint, jsonify + +from api.consts import COMMON_API_PREFIX + +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..3aac698 --- /dev/null +++ b/backend/src/api/main.py @@ -0,0 +1,15 @@ +from flask import Flask + +from api.components.hello import hello_api + +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..9a7dab7 --- /dev/null +++ b/tasks.py @@ -0,0 +1,22 @@ +from invoke import task + +from api import get_api + + +# 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()