Incorporate server and cli into new code #13

Merged
Jaculabilis merged 16 commits from tvb/server into develop 2021-06-16 03:53:07 +00:00
2 changed files with 6 additions and 4 deletions
Showing only changes of commit 1d1895c32d - Show all commits

View File

@ -9,7 +9,7 @@ class AmanuensisConfig:
# If CONFIG_FILE is defined, the config file it points to may override # If CONFIG_FILE is defined, the config file it points to may override
# 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] = "../resources"
SECRET_KEY: Optional[str] = "secret" SECRET_KEY: Optional[str] = "secret"
DATABASE_URI: Optional[str] = "sqlite:///:memory:" DATABASE_URI: Optional[str] = "sqlite:///:memory:"
TESTING: bool = False TESTING: bool = False

View File

@ -1,4 +1,5 @@
import json import json
import os
from flask import Flask, g from flask import Flask, g
@ -18,8 +19,8 @@ def get_app(
app.config.from_object(config) app.config.from_object(config)
# If a config file is now specified, also load keys from there # If a config file is now specified, also load keys from there
if app.config.get("CONFIG_FILE", None): if config_path := app.config.get("CONFIG_FILE", None):
app.config.from_file(app.config["CONFIG_FILE"], json.load) app.config.from_file(os.path.abspath(config_path), json.load)
# Assert that all required config values are now set # Assert that all required config values are now set
for config_key in ("SECRET_KEY", "DATABASE_URI"): for config_key in ("SECRET_KEY", "DATABASE_URI"):
@ -59,4 +60,5 @@ def get_app(
def run(): def run():
"""Run the server, populating the config from the command line.""" """Run the server, populating the config from the command line."""
config = CommandLineConfig() config = CommandLineConfig()
get_app(config).run(debug=config.TESTING) app = get_app(config)
app.run(debug=app.testing)