Packagind and build step

This commit is contained in:
Firq 2023-11-24 20:50:18 +01:00
parent c2916a260a
commit e4e48591a6
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
25 changed files with 98 additions and 57 deletions

View file

@ -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!"

3
backend/.gitignore vendored
View file

@ -1,2 +1,3 @@
.venv/
__pycache__/
__pycache__/
*.egg-info

View file

View file

@ -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

View file

@ -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

View file

@ -0,0 +1 @@
from .settings import APISettings, DatabaseSettings, ServerSettings

View file

@ -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"

View file

@ -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

View file

@ -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")

View file

@ -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()

View file

@ -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")

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 }

30
backend/pyproject.toml Normal file
View file

@ -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*"]

View file

@ -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

View file

@ -1,5 +0,0 @@
# pylint: disable=too-few-public-methods
from pathlib import Path
class DatabaseSettings:
DATABASE_DIRECTORY = Path(__file__).parents[1] / "database" / "storage"

View file

@ -1,5 +0,0 @@
# pylint: disable=too-few-public-methods
class ServerSettings:
HOSTNAME = "localhost"
PORT = 5000