Compare commits
5 Commits
e23019bff6
...
d29a656c98
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | d29a656c98 | |
Tim Van Baak | 3c09dcc5f4 | |
Tim Van Baak | 73dc2127e7 | |
Tim Van Baak | a8da877aa5 | |
Tim Van Baak | 9b9def281b |
|
@ -1,4 +1,3 @@
|
||||||
from argparse import ArgumentParser
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -10,8 +9,8 @@ class AmanuensisConfig:
|
||||||
# config values defined on the config object itself.
|
# config values defined on the config object itself.
|
||||||
CONFIG_FILE: Optional[str] = None
|
CONFIG_FILE: Optional[str] = None
|
||||||
STATIC_ROOT: Optional[str] = "static"
|
STATIC_ROOT: Optional[str] = "static"
|
||||||
SECRET_KEY: Optional[str] = "secret"
|
SECRET_KEY: Optional[str] = None
|
||||||
DATABASE_URI: Optional[str] = "sqlite:///:memory:"
|
DATABASE_URI: Optional[str] = None
|
||||||
TESTING: bool = False
|
TESTING: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,21 +24,3 @@ class EnvironmentConfig(AmanuensisConfig):
|
||||||
"AMANUENSIS_DATABASE_URI", AmanuensisConfig.DATABASE_URI
|
"AMANUENSIS_DATABASE_URI", AmanuensisConfig.DATABASE_URI
|
||||||
)
|
)
|
||||||
TESTING = os.environ.get("AMANUENSIS_TESTING", "").lower() in ("true", "1")
|
TESTING = os.environ.get("AMANUENSIS_TESTING", "").lower() in ("true", "1")
|
||||||
|
|
||||||
|
|
||||||
class CommandLineConfig(AmanuensisConfig):
|
|
||||||
"""Loads config values from command line arguments."""
|
|
||||||
def __init__(self) -> None:
|
|
||||||
parser = ArgumentParser()
|
|
||||||
parser.add_argument("--config-file", default=AmanuensisConfig.CONFIG_FILE)
|
|
||||||
parser.add_argument("--static-root", default=AmanuensisConfig.STATIC_ROOT)
|
|
||||||
parser.add_argument("--secret-key", default=AmanuensisConfig.SECRET_KEY)
|
|
||||||
parser.add_argument("--database-uri", default=AmanuensisConfig.DATABASE_URI)
|
|
||||||
parser.add_argument("--debug", action="store_true")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
self.CONFIG_FILE = args.config_file
|
|
||||||
self.STATIC_ROOT = args.static_root
|
|
||||||
self.SECRET_KEY = args.secret_key
|
|
||||||
self.DATABASE_URI = args.database_uri
|
|
||||||
self.TESTING = args.debug
|
|
||||||
|
|
|
@ -2,14 +2,11 @@ import json
|
||||||
|
|
||||||
from flask import Flask, g
|
from flask import Flask, g
|
||||||
|
|
||||||
from amanuensis.config import AmanuensisConfig, CommandLineConfig
|
from amanuensis.config import AmanuensisConfig
|
||||||
from amanuensis.db import DbContext
|
from amanuensis.db import DbContext
|
||||||
|
|
||||||
|
|
||||||
def get_app(
|
def get_app(config: AmanuensisConfig, db: DbContext = None,) -> Flask:
|
||||||
config: AmanuensisConfig,
|
|
||||||
db: DbContext = None,
|
|
||||||
) -> Flask:
|
|
||||||
"""Application factory"""
|
"""Application factory"""
|
||||||
# Create the Flask object
|
# Create the Flask object
|
||||||
app = Flask(__name__, template_folder=".", static_folder=config.STATIC_ROOT)
|
app = Flask(__name__, template_folder=".", static_folder=config.STATIC_ROOT)
|
||||||
|
@ -54,9 +51,3 @@ def get_app(
|
||||||
app.route("/")(test)
|
app.route("/")(test)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
def run():
|
|
||||||
"""Run the server, populating the config from the command line."""
|
|
||||||
config = CommandLineConfig()
|
|
||||||
get_app(config).run(debug=config.TESTING)
|
|
||||||
|
|
|
@ -16,9 +16,6 @@ pytest = "^5.2"
|
||||||
black = "^21.5b2"
|
black = "^21.5b2"
|
||||||
mypy = "^0.812"
|
mypy = "^0.812"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
|
||||||
amanuensis-server = "amanuensis.server:run"
|
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
extend-exclude = "^/amanuensis/cli/.*|^/amanuensis/config/.*|^/amanuensis/lexicon/.*|^/amanuensis/log/.*|^/amanuensis/models/.*|^/amanuensis/resources/.*|^/amanuensis/server/.*|^/amanuensis/user/.*|^/amanuensis/__main__.py"
|
extend-exclude = "^/amanuensis/cli/.*|^/amanuensis/config/.*|^/amanuensis/lexicon/.*|^/amanuensis/log/.*|^/amanuensis/models/.*|^/amanuensis/resources/.*|^/amanuensis/server/.*|^/amanuensis/user/.*|^/amanuensis/__main__.py"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue