From e4e48591a6fc88e7c1b4fc1984a8f24448d8e03d Mon Sep 17 00:00:00 2001 From: Firq Date: Fri, 24 Nov 2023 20:50:18 +0100 Subject: [PATCH] Packagind and build step --- .gitlab-ci.yml | 32 +++++++++++++++---- backend/.gitignore | 3 +- backend/fgo-request-manager/__init__.py | 0 .../__main__.py} | 8 ++--- backend/{src => fgo-request-manager}/app.py | 6 ++-- .../fgo-request-manager/config/__init__.py | 1 + .../config/settings.py} | 15 ++++++--- .../database/__init__.py | 0 .../database/database.py | 13 ++++---- .../database/storage/.gitignore | 0 .../models/interface.py | 0 .../models/requestentry.py | 2 +- .../models/requests.py | 0 .../routes/__init__.py | 0 .../routes/health.py | 4 +-- .../routes/openapi.py | 2 +- .../routes/requests/__init__.py | 0 .../routes/requests/base.py | 6 ++-- .../routes/requests/create.py | 6 ++-- .../routes/requests/interact.py | 6 ++-- .../routes/version.py | 6 ++-- backend/pyproject.toml | 30 +++++++++++++++++ backend/requirements.txt | 5 --- backend/src/config/db_settings.py | 5 --- backend/src/config/server_settings.py | 5 --- 25 files changed, 98 insertions(+), 57 deletions(-) create mode 100644 backend/fgo-request-manager/__init__.py rename backend/{src/server.py => fgo-request-manager/__main__.py} (82%) rename backend/{src => fgo-request-manager}/app.py (90%) create mode 100644 backend/fgo-request-manager/config/__init__.py rename backend/{src/config/api_settings.py => fgo-request-manager/config/settings.py} (69%) rename backend/{src => fgo-request-manager}/database/__init__.py (100%) rename backend/{src => fgo-request-manager}/database/database.py (71%) rename backend/{src => fgo-request-manager}/database/storage/.gitignore (100%) rename backend/{src => fgo-request-manager}/models/interface.py (100%) rename backend/{src => fgo-request-manager}/models/requestentry.py (96%) rename backend/{src => fgo-request-manager}/models/requests.py (100%) rename backend/{src => fgo-request-manager}/routes/__init__.py (100%) rename backend/{src => fgo-request-manager}/routes/health.py (87%) rename backend/{src => fgo-request-manager}/routes/openapi.py (89%) rename backend/{src => fgo-request-manager}/routes/requests/__init__.py (100%) rename backend/{src => fgo-request-manager}/routes/requests/base.py (81%) rename backend/{src => fgo-request-manager}/routes/requests/create.py (85%) rename backend/{src => fgo-request-manager}/routes/requests/interact.py (88%) rename backend/{src => fgo-request-manager}/routes/version.py (65%) create mode 100644 backend/pyproject.toml delete mode 100644 backend/requirements.txt delete mode 100644 backend/src/config/db_settings.py delete mode 100644 backend/src/config/server_settings.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07243fd..5743d60 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - quality assurance +- build - deploy .init_venv: &init_venv @@ -8,24 +9,23 @@ stages: - python --version - echo "venv '$VIRTUAL_ENV'" -.install_requirements: &install_requirements - - pip install -r requirements.txt --disable-pip-version-check -q +.install_package: &install_package + - pip install -e . -q - python -m pip list --format=columns --disable-pip-version-check backend-pylint: stage: quality assurance - image: python:3.11.4-buster + image: python:3.11.0 before_script: - mkdir -p public - cd backend - *init_venv - - *install_requirements + - *install_package - pip install pylint~=2.17.7 pylint-gitlab --disable-pip-version-check -q - pylint --version - - cd .. script: - - pylint backend/src/* --rcfile=backend/.pylintrc --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter > codeclimate.json - - pylint backend/src/* --rcfile=backend/.pylintrc --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter > public/index.html + - pylint **/*.py --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter > ../codeclimate.json + - pylint **/*.py --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter > ../public/index.html artifacts: paths: - public @@ -33,8 +33,26 @@ backend-pylint: codequality: codeclimate.json when: always +build:package: + stage: build + needs: [ "backend-pylint" ] + image: python:3.11.0 + before_script: + - mkdir -p dist + - cd backend + - *init_venv + - pip install build + script: + - py -m build + - cp dist ../dist + artifacts: + paths: + - dist + when: always + pages: stage: deploy + needs: [ "backend-pylint" ] image: alpine:latest script: - echo "Deployed!" diff --git a/backend/.gitignore b/backend/.gitignore index 808386f..69b7c60 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,2 +1,3 @@ .venv/ -__pycache__/ \ No newline at end of file +__pycache__/ +*.egg-info \ No newline at end of file diff --git a/backend/fgo-request-manager/__init__.py b/backend/fgo-request-manager/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/server.py b/backend/fgo-request-manager/__main__.py similarity index 82% rename from backend/src/server.py rename to backend/fgo-request-manager/__main__.py index 9b17d58..96b1d65 100644 --- a/backend/src/server.py +++ b/backend/fgo-request-manager/__main__.py @@ -2,10 +2,10 @@ from gevent.monkey import patch_all; patch_all() from gevent.pywsgi import WSGIServer -from app import Application -from routes import routes -from routes.requests import routes_requests -from config.server_settings import ServerSettings +from .app import Application +from .routes import routes +from .routes.requests import routes_requests +from .config import ServerSettings instance = Application.get_instance() app, api = instance.app, instance.api diff --git a/backend/src/app.py b/backend/fgo-request-manager/app.py similarity index 90% rename from backend/src/app.py rename to backend/fgo-request-manager/app.py index d54b818..ceebd10 100644 --- a/backend/src/app.py +++ b/backend/fgo-request-manager/app.py @@ -3,7 +3,7 @@ from datetime import datetime from flask import Flask from flask_smorest import Api -from config.api_settings import DefaultSettings +from .config import APISettings class IsSingletonException(Exception): pass @@ -13,13 +13,13 @@ class Application: This is a singleton that can be accessed using get_instance() It has 2 properties - - app: Used for WSGI servers and such - api: Used for Blueprints """ + __instance = None app = Flask(__name__) - app.config.from_object(DefaultSettings) + app.config.from_object(APISettings) api = None alive_since = None diff --git a/backend/fgo-request-manager/config/__init__.py b/backend/fgo-request-manager/config/__init__.py new file mode 100644 index 0000000..1deb32a --- /dev/null +++ b/backend/fgo-request-manager/config/__init__.py @@ -0,0 +1 @@ +from .settings import APISettings, DatabaseSettings, ServerSettings diff --git a/backend/src/config/api_settings.py b/backend/fgo-request-manager/config/settings.py similarity index 69% rename from backend/src/config/api_settings.py rename to backend/fgo-request-manager/config/settings.py index 95d851f..5611458 100644 --- a/backend/src/config/api_settings.py +++ b/backend/fgo-request-manager/config/settings.py @@ -1,9 +1,16 @@ # pylint: disable=too-few-public-methods from pathlib import Path -class DefaultSettings: +class ServerSettings: + HOSTNAME = "localhost" + PORT = 5000 + +class DatabaseSettings: + DATABASE_DIRECTORY = Path(__file__).parents[1] / "database" / "storage" + +class APISettings: API_TITLE = "Support Organizer" - API_VERSION = 0.1 + API_VERSION = "0.1.0-a" OPENAPI_VERSION = "3.1.0" # openapi.json settings @@ -12,7 +19,7 @@ class DefaultSettings: # swagger settings OPENAPI_SWAGGER_UI_PATH = "/swagger" - OPENAPI_SWAGGER_UI_URL = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/" + OPENAPI_SWAGGER_UI_URL = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.10.0/" SWAGGER_UI_DOC_EXPANSION = "list" # redoc settings @@ -25,4 +32,4 @@ class DefaultSettings: 'description': 'Support Organizer for FGO' } } - FILE_SAVE_DIRECTORY = Path(__file__).parents[1] / "temp" + FILE_SAVE_DIRECTORY = Path(__file__).parents[1] / ".temp" diff --git a/backend/src/database/__init__.py b/backend/fgo-request-manager/database/__init__.py similarity index 100% rename from backend/src/database/__init__.py rename to backend/fgo-request-manager/database/__init__.py diff --git a/backend/src/database/database.py b/backend/fgo-request-manager/database/database.py similarity index 71% rename from backend/src/database/database.py rename to backend/fgo-request-manager/database/database.py index 37aa28d..f267ae5 100644 --- a/backend/src/database/database.py +++ b/backend/fgo-request-manager/database/database.py @@ -1,19 +1,18 @@ # pylint: disable=too-few-public-methods import dictdatabase as DDB -from config.db_settings import DatabaseSettings - -class IsSingletonException(Exception): - pass +from ..config import DatabaseSettings class Database: """ This is a singleton that can be accessed using get_instance() """ + class IsSingletonException(Exception): + pass + __instance = None db = DDB - if not DatabaseSettings.DATABASE_DIRECTORY.is_dir(): - DatabaseSettings.DATABASE_DIRECTORY.mkdir() + DatabaseSettings.DATABASE_DIRECTORY.mkdir(exist_ok=True, parents=True) db.config.storage_directory = DatabaseSettings.DATABASE_DIRECTORY if not db.at("requests").exists(): db.at("requests").create({}) @@ -28,5 +27,5 @@ class Database: def __init__(self): if Database.__instance is not None: - raise IsSingletonException("This class is a singleton") + raise self.IsSingletonException("This class is a singleton") Database.__instance = self diff --git a/backend/src/database/storage/.gitignore b/backend/fgo-request-manager/database/storage/.gitignore similarity index 100% rename from backend/src/database/storage/.gitignore rename to backend/fgo-request-manager/database/storage/.gitignore diff --git a/backend/src/models/interface.py b/backend/fgo-request-manager/models/interface.py similarity index 100% rename from backend/src/models/interface.py rename to backend/fgo-request-manager/models/interface.py diff --git a/backend/src/models/requestentry.py b/backend/fgo-request-manager/models/requestentry.py similarity index 96% rename from backend/src/models/requestentry.py rename to backend/fgo-request-manager/models/requestentry.py index f24bc1a..07d4413 100644 --- a/backend/src/models/requestentry.py +++ b/backend/fgo-request-manager/models/requestentry.py @@ -1,6 +1,6 @@ import marshmallow as ma -from models.requests import RequestStatus +from .requests import RequestStatus class BaseField(ma.Schema): id = ma.fields.Integer(description="Atlas Academy id") diff --git a/backend/src/models/requests.py b/backend/fgo-request-manager/models/requests.py similarity index 100% rename from backend/src/models/requests.py rename to backend/fgo-request-manager/models/requests.py diff --git a/backend/src/routes/__init__.py b/backend/fgo-request-manager/routes/__init__.py similarity index 100% rename from backend/src/routes/__init__.py rename to backend/fgo-request-manager/routes/__init__.py diff --git a/backend/src/routes/health.py b/backend/fgo-request-manager/routes/health.py similarity index 87% rename from backend/src/routes/health.py rename to backend/fgo-request-manager/routes/health.py index a88e1a2..d25042c 100644 --- a/backend/src/routes/health.py +++ b/backend/fgo-request-manager/routes/health.py @@ -1,8 +1,8 @@ from datetime import datetime from flask.views import MethodView -from app import Application -from models.interface import HealthGet, HealthStatus +from ..app import Application +from ..models.interface import HealthGet, HealthStatus from . import routes as blp instance = Application.get_instance() diff --git a/backend/src/routes/openapi.py b/backend/fgo-request-manager/routes/openapi.py similarity index 89% rename from backend/src/routes/openapi.py rename to backend/fgo-request-manager/routes/openapi.py index 308e377..e012725 100644 --- a/backend/src/routes/openapi.py +++ b/backend/fgo-request-manager/routes/openapi.py @@ -1,7 +1,7 @@ from flask import redirect, url_for from flask.views import MethodView -from models.interface import OpenAPIGet +from ..models.interface import OpenAPIGet from . import routes as blp @blp.route("/openapi") diff --git a/backend/src/routes/requests/__init__.py b/backend/fgo-request-manager/routes/requests/__init__.py similarity index 100% rename from backend/src/routes/requests/__init__.py rename to backend/fgo-request-manager/routes/requests/__init__.py diff --git a/backend/src/routes/requests/base.py b/backend/fgo-request-manager/routes/requests/base.py similarity index 81% rename from backend/src/routes/requests/base.py rename to backend/fgo-request-manager/routes/requests/base.py index dc67b5c..e112ef9 100644 --- a/backend/src/routes/requests/base.py +++ b/backend/fgo-request-manager/routes/requests/base.py @@ -1,8 +1,8 @@ from flask.views import MethodView -from database import Database -from models.requests import RequestStatus -from models.requestentry import RequestDatabaseEntry +from ...database import Database +from ...models.requests import RequestStatus +from ...models.requestentry import RequestDatabaseEntry from . import routes_requests as blp db = Database.get_instance().db diff --git a/backend/src/routes/requests/create.py b/backend/fgo-request-manager/routes/requests/create.py similarity index 85% rename from backend/src/routes/requests/create.py rename to backend/fgo-request-manager/routes/requests/create.py index 232c977..a12ad39 100644 --- a/backend/src/routes/requests/create.py +++ b/backend/fgo-request-manager/routes/requests/create.py @@ -1,9 +1,9 @@ from uuid import uuid4 from flask.views import MethodView -from database import Database -from models.requests import RequestsCreate, RequestStatus -from models.requestentry import RequestPostData +from ...database import Database +from ...models.requests import RequestsCreate, RequestStatus +from ...models.requestentry import RequestPostData from . import routes_requests as blp db = Database.get_instance().db diff --git a/backend/src/routes/requests/interact.py b/backend/fgo-request-manager/routes/requests/interact.py similarity index 88% rename from backend/src/routes/requests/interact.py rename to backend/fgo-request-manager/routes/requests/interact.py index 69db1a8..e308350 100644 --- a/backend/src/routes/requests/interact.py +++ b/backend/fgo-request-manager/routes/requests/interact.py @@ -1,9 +1,9 @@ from flask_smorest import abort from flask.views import MethodView -from database import Database -from models.requests import UuidSchema, RequestsInteractionDelete, RequestStatus -from models.requestentry import RequestDatabaseEntry +from ...database import Database +from ...models.requests import UuidSchema, RequestsInteractionDelete, RequestStatus +from ...models.requestentry import RequestDatabaseEntry from . import routes_requests as blp db = Database.get_instance().db diff --git a/backend/src/routes/version.py b/backend/fgo-request-manager/routes/version.py similarity index 65% rename from backend/src/routes/version.py rename to backend/fgo-request-manager/routes/version.py index 62b005b..9d05d05 100644 --- a/backend/src/routes/version.py +++ b/backend/fgo-request-manager/routes/version.py @@ -1,7 +1,7 @@ from flask.views import MethodView -from config.api_settings import DefaultSettings -from models.interface import ApiVersionGet +from ..config import APISettings +from ..models.interface import ApiVersionGet from . import routes as blp @blp.route("/version") @@ -9,4 +9,4 @@ class ApiVersion(MethodView): @blp.doc(summary="Get the REST interface version identification.") @blp.response(200, ApiVersionGet, description="Successful operation") def get(self): - return { "version": DefaultSettings.API_VERSION } + return { "version": APISettings.API_VERSION } diff --git a/backend/pyproject.toml b/backend/pyproject.toml new file mode 100644 index 0000000..b0840ce --- /dev/null +++ b/backend/pyproject.toml @@ -0,0 +1,30 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "fgo-request-manager" +version = "0.1.0a1" +dependencies = [ + "flask~=2.3.3", + "flask-smorest~=0.42.1", + "marshmallow~=3.20.1", + "gevent~=23.9.1", + "dictdatabase~=2.4.6", +] +requires-python = ">= 3.10" +authors = [{name = "Firq", email = "firelp42@gmail.com"}] +maintainers = [{name = "Firq", email = "firelp42@gmail.com"}] +description = "Tool to manage requests for supports" +classifiers = [ + "Development Status :: 3 - Alpha", + "Framework :: Flask", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] + +[tool.setuptools.packages.find] +where = ["."] +include = ["fgo-request-manager*"] diff --git a/backend/requirements.txt b/backend/requirements.txt deleted file mode 100644 index b789342..0000000 --- a/backend/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -flask~=2.3.3 -flask-smorest~=0.42.1 -marshmallow~=3.20.1 -gevent~=23.9.1 -dictdatabase~=2.4.6 \ No newline at end of file diff --git a/backend/src/config/db_settings.py b/backend/src/config/db_settings.py deleted file mode 100644 index a7a4b40..0000000 --- a/backend/src/config/db_settings.py +++ /dev/null @@ -1,5 +0,0 @@ -# pylint: disable=too-few-public-methods -from pathlib import Path - -class DatabaseSettings: - DATABASE_DIRECTORY = Path(__file__).parents[1] / "database" / "storage" diff --git a/backend/src/config/server_settings.py b/backend/src/config/server_settings.py deleted file mode 100644 index b00a884..0000000 --- a/backend/src/config/server_settings.py +++ /dev/null @@ -1,5 +0,0 @@ -# pylint: disable=too-few-public-methods - -class ServerSettings: - HOSTNAME = "localhost" - PORT = 5000