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
|
||||
import os
|
||||
|
||||
|
@ -10,8 +9,8 @@ class AmanuensisConfig:
|
|||
# config values defined on the config object itself.
|
||||
CONFIG_FILE: Optional[str] = None
|
||||
STATIC_ROOT: Optional[str] = "static"
|
||||
SECRET_KEY: Optional[str] = "secret"
|
||||
DATABASE_URI: Optional[str] = "sqlite:///:memory:"
|
||||
SECRET_KEY: Optional[str] = None
|
||||
DATABASE_URI: Optional[str] = None
|
||||
TESTING: bool = False
|
||||
|
||||
|
||||
|
@ -25,21 +24,3 @@ class EnvironmentConfig(AmanuensisConfig):
|
|||
"AMANUENSIS_DATABASE_URI", AmanuensisConfig.DATABASE_URI
|
||||
)
|
||||
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 amanuensis.config import AmanuensisConfig, CommandLineConfig
|
||||
from amanuensis.config import AmanuensisConfig
|
||||
from amanuensis.db import DbContext
|
||||
|
||||
|
||||
def get_app(
|
||||
config: AmanuensisConfig,
|
||||
db: DbContext = None,
|
||||
) -> Flask:
|
||||
def get_app(config: AmanuensisConfig, db: DbContext = None,) -> Flask:
|
||||
"""Application factory"""
|
||||
# Create the Flask object
|
||||
app = Flask(__name__, template_folder=".", static_folder=config.STATIC_ROOT)
|
||||
|
@ -54,9 +51,3 @@ def get_app(
|
|||
app.route("/")(test)
|
||||
|
||||
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"
|
||||
mypy = "^0.812"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
amanuensis-server = "amanuensis.server:run"
|
||||
|
||||
[tool.black]
|
||||
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