Refactor project structure

Add version, multiple configs and pyproject
This commit is contained in:
2023-06-11 18:09:00 +02:00
parent 51040577fc
commit 869ba82695
58 changed files with 167 additions and 35 deletions

View File

@@ -24,6 +24,7 @@ share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
*.egg-info/*
MANIFEST
# PyInstaller

View File

View File

@@ -1,17 +0,0 @@
import os
from dotenv import load_dotenv
dotenv_file = ".env"
basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(basedir, dotenv_file))
class Config(object):
COMPARE = os.environ.get("COMPARE") == "True" or False
TEMPLATES_AUTO_RELOAD = True
SECRET_KEY = os.environ.get("SECRET_KEY") or "really-hard-to-guess-key"
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(basedir, "app.db")
SQLALCHEMY_TRACK_MODIFICATIONS = False
INDEX = "main.index"

View File

@@ -1 +0,0 @@
SECRET=Really-hard-to-guess-secret.

View File

@@ -1,5 +0,0 @@
<nav class="navbar fixed-bottom navbar-dark bg-dark navbar-custom">
<ul class="navbar-nav mr-auto pie">
<small>Versión <b>1.00</b></small>
</ul>
</nav>

16
beflask/__init__.py Normal file
View File

@@ -0,0 +1,16 @@
from ._version import __version__
__author__ = "Ricardo Montañana Gómez"
__copyright__ = "Copyright 2020-2023, Ricardo Montañana Gómez"
__license__ = "MIT License"
__author_email__ = "ricardo.montanana@alu.uclm.es"
__status__ = "Development"
__all__ = [
"__version__",
"__author__",
"__copyright__",
"__license__",
"__author_email__",
"__status__",
]

1
beflask/_version.py Normal file
View File

@@ -0,0 +1 @@
__version__ = "1.0.0"

View File

@@ -13,7 +13,7 @@ from wtforms.validators import (
Email,
ValidationError,
)
from app.models import User
from beflask.models import User
class UserForm(FlaskForm):

View File

@@ -1,6 +1,6 @@
{% extends "report_tables.html" %}
{% block content %}
<div class="container col-7">
<div class="container col-9">
<div class="alert alert-primary" role="alert">
<div class="navbar">
<div class="float-left">

View File

@@ -1,9 +1,10 @@
#!/usr/bin/env python
import os
from flask import Flask
from flask_bootstrap import Bootstrap5
from flask_login import LoginManager
from flask_socketio import SocketIO
from .config import Config
from .config import config, load_env
from .models import User, db
from .results.main_results import results
@@ -28,8 +29,9 @@ def make_shell_context():
def create_app():
app = Flask(__name__)
bootstrap.init_app(app)
# app.register_blueprint(results)
app.config.from_object(Config)
load_env()
config_object = config[os.getenv("BEFLASK_ENV", "development")]
app.config.from_object(config_object)
db.init_app(app)
login_manager.init_app(app)
login_manager.login_view = "main.login"

68
beflask/config.py Normal file
View File

@@ -0,0 +1,68 @@
import os
from dotenv import load_dotenv
import benchmark
from beflask import __version__
def get_base_dir():
return os.path.abspath(os.path.dirname(__file__))
def load_env():
dotenv_file = ".env"
file_name = os.path.join(get_base_dir(), dotenv_file)
load_dotenv(file_name)
class Config(object):
COMPARE = os.environ.get("COMPARE") == "True" or False
TEMPLATES_AUTO_RELOAD = True
SECRET_KEY = os.environ.get("SECRET_KEY") or "really-hard-to-guess-key"
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL"
) or "sqlite:///" + os.path.join(get_base_dir(), "app.db")
SQLALCHEMY_TRACK_MODIFICATIONS = False
INDEX = "main.index"
APP_VERSION = __version__
BENCHMARK_VERSION = benchmark.__version__
DEBUG = os.environ.get("DEBUG") == "True" or False
TESTING = False
class DevelopmentConfig(Config):
DEBUG = True
class ProductionConfig(Config):
pass
class TestingConfig(Config):
TESTING = True
SQLALCHEMY_DATABASE_URI = "sqlite://"
SOCKETIO_MESSAGE_QUEUE = None
# class Config(object):
# DEBUG = False
# TESTING = False
# SECRET_KEY = os.environ.get(
# "SECRET_KEY", "51f52814-0071-11e6-a247-000ec6c2372c"
# )
# SQLALCHEMY_DATABASE_URI = os.environ.get(
# "DATABASE_URL", "sqlite:///" + os.path.join(basedir, "db.sqlite")
# )
# SQLALCHEMY_TRACK_MODIFICATIONS = False
# REQUEST_STATS_WINDOW = 15
# CELERY_CONFIG = {}
# SOCKETIO_MESSAGE_QUEUE = os.environ.get(
# "SOCKETIO_MESSAGE_QUEUE",
# os.environ.get("CELERY_BROKER_URL", "redis://"),
# )
config = {
"development": DevelopmentConfig,
"production": ProductionConfig,
"testing": TestingConfig,
}

5
beflask/env.dist Normal file
View File

@@ -0,0 +1,5 @@
COMPARE=True
DEBUG=True
SECRET_KEY=Really-hard-to-guess-string
# possible values: development, testing, productions
BEFLASK_ENV=development

View File

Before

Width:  |  Height:  |  Size: 14 MiB

After

Width:  |  Height:  |  Size: 14 MiB

View File

@@ -19,7 +19,7 @@
{% endblock %}
</head>
<body>
<div class="container-fluid">{% include "_nav.html" %}</div>
<div class="container-fluid">{% include "_header.html" %}</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class="col-md-4">

View File

@@ -0,0 +1,12 @@
<nav class="navbar fixed-bottom navbar-dark bg-dark navbar-custom">
<div class="float-start">
<ul class="navbar-nav mr-auto pie">
<small>App Versión <b>{{ config.APP_VERSION }}</b></small>
</ul>
</div>
<div class="float-end">
<ul class="navbar-nav mr-auto pie">
<small>Benchmark Versión <b>{{ config.BENCHMARK_VERSION }}</b></small>
</ul>
</div>
</nav>

View File

@@ -1,5 +1,5 @@
from app.models import Benchmark, db, User
from app import app
from beflask.models import Benchmark, db, User
from beflask import app
app = app.create_app()

View File

@@ -1,5 +1,5 @@
from app.models import Benchmark, db, User
from app import app
from beflask.models import Benchmark, db, User
from beflask import app
app = app.create_app()

View File

@@ -1,5 +1,53 @@
[build-system]
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
packages = ["beflask"]
license-files = ["LICENSE"]
[tool.setuptools.dynamic]
version = { attr = "beflask.__version__" }
dependencies = {file = ["requirements.txt"]}
[project]
name = "beflask"
description = "Flask application to manage benchmarking experiments"
readme = "README.md"
authors = [
{ name = "Ricardo Montañana", email = "ricardo.montanana@alu.uclm.es" },
]
dynamic = ['version', 'dependencies']
requires-python = ">=3.8"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
"Topic :: Software Development",
"Topic :: Scientific/Engineering",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]
[project.optional-dependencies]
dev = ["black", "pre-commit", "flake8", "mypy"]
[project.urls]
Home = "https://github.com/doctorado-ml/beflask"
[tool.coverage.run]
source = ["beflask"]
[tool.black]
line-length = 79
target_version = ['py38', 'py39', 'py310']
include = '\.pyi?$'
exclude = '''
/(

View File

@@ -1,3 +1,4 @@
benchmark
flask
flask-login
bootstrap-flask

5
run.py Normal file → Executable file
View File

@@ -1,4 +1,5 @@
from app import app
#!/usr/bin/env python
from beflask import app
socketio, app = app.create_app()
socketio.run(app, debug=True)
socketio.run(app, debug=app.config["DEBUG"])