mirror of
https://github.com/Doctorado-ML/beflask.git
synced 2025-08-15 15:15:52 +00:00
Refactor project structure
Add version, multiple configs and pyproject
This commit is contained in:
1
app/.gitignore → .gitignore
vendored
1
app/.gitignore → .gitignore
vendored
@@ -24,6 +24,7 @@ share/python-wheels/
|
|||||||
*.egg-info/
|
*.egg-info/
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
*.egg
|
*.egg
|
||||||
|
*.egg-info/*
|
||||||
MANIFEST
|
MANIFEST
|
||||||
|
|
||||||
# PyInstaller
|
# PyInstaller
|
@@ -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"
|
|
@@ -1 +0,0 @@
|
|||||||
SECRET=Really-hard-to-guess-secret.
|
|
@@ -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
16
beflask/__init__.py
Normal 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
1
beflask/_version.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__version__ = "1.0.0"
|
@@ -13,7 +13,7 @@ from wtforms.validators import (
|
|||||||
Email,
|
Email,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
)
|
)
|
||||||
from app.models import User
|
from beflask.models import User
|
||||||
|
|
||||||
|
|
||||||
class UserForm(FlaskForm):
|
class UserForm(FlaskForm):
|
@@ -1,6 +1,6 @@
|
|||||||
{% extends "report_tables.html" %}
|
{% extends "report_tables.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container col-7">
|
<div class="container col-9">
|
||||||
<div class="alert alert-primary" role="alert">
|
<div class="alert alert-primary" role="alert">
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
<div class="float-left">
|
<div class="float-left">
|
@@ -1,9 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import os
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_bootstrap import Bootstrap5
|
from flask_bootstrap import Bootstrap5
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
from .config import Config
|
from .config import config, load_env
|
||||||
from .models import User, db
|
from .models import User, db
|
||||||
|
|
||||||
from .results.main_results import results
|
from .results.main_results import results
|
||||||
@@ -28,8 +29,9 @@ def make_shell_context():
|
|||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
bootstrap.init_app(app)
|
bootstrap.init_app(app)
|
||||||
# app.register_blueprint(results)
|
load_env()
|
||||||
app.config.from_object(Config)
|
config_object = config[os.getenv("BEFLASK_ENV", "development")]
|
||||||
|
app.config.from_object(config_object)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
login_manager.login_view = "main.login"
|
login_manager.login_view = "main.login"
|
68
beflask/config.py
Normal file
68
beflask/config.py
Normal 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
5
beflask/env.dist
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
COMPARE=True
|
||||||
|
DEBUG=True
|
||||||
|
SECRET_KEY=Really-hard-to-guess-string
|
||||||
|
# possible values: development, testing, productions
|
||||||
|
BEFLASK_ENV=development
|
Before Width: | Height: | Size: 14 MiB After Width: | Height: | Size: 14 MiB |
@@ -19,7 +19,7 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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) %}
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
12
beflask/templates/status.html
Normal file
12
beflask/templates/status.html
Normal 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>
|
@@ -1,5 +1,5 @@
|
|||||||
from app.models import Benchmark, db, User
|
from beflask.models import Benchmark, db, User
|
||||||
from app import app
|
from beflask import app
|
||||||
|
|
||||||
app = app.create_app()
|
app = app.create_app()
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
from app.models import Benchmark, db, User
|
from beflask.models import Benchmark, db, User
|
||||||
from app import app
|
from beflask import app
|
||||||
|
|
||||||
app = app.create_app()
|
app = app.create_app()
|
||||||
|
|
||||||
|
@@ -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]
|
[tool.black]
|
||||||
line-length = 79
|
line-length = 79
|
||||||
|
target_version = ['py38', 'py39', 'py310']
|
||||||
include = '\.pyi?$'
|
include = '\.pyi?$'
|
||||||
exclude = '''
|
exclude = '''
|
||||||
/(
|
/(
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
benchmark
|
||||||
flask
|
flask
|
||||||
flask-login
|
flask-login
|
||||||
bootstrap-flask
|
bootstrap-flask
|
||||||
|
Reference in New Issue
Block a user