diff options
-rw-r--r-- | qc_app/__init__.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/qc_app/__init__.py b/qc_app/__init__.py index 1215954..045572c 100644 --- a/qc_app/__init__.py +++ b/qc_app/__init__.py @@ -11,22 +11,23 @@ from .samples import samples from .dbinsert import dbinsertbp from .errors import register_error_handlers -def instance_path(): - """Retrieve the `instance_path`. Raise an exception if not defined.""" - path = os.getenv("QCAPP_INSTANCE_PATH", None) - if path is None: - raise Exception(( - "Configuration Error: Set the `QCAPP_INSTANCE_PATH` environment " - "variable.")) - - return path +def override_settings_with_envvars( + app: Flask, ignore: tuple[str, ...]=tuple()) -> None: + """Override settings in `app` with those in ENVVARS""" + for setting in (key for key in app.config if key not in ignore): + app.config[setting] = os.environ.get(setting) or app.config[setting] def create_app(instance_dir): """The application factory""" - app = Flask( - __name__, instance_path=instance_dir, instance_relative_config=True) + app = Flask(__name__) app.config.from_pyfile(os.path.join(os.getcwd(), "etc/default_config.py")) - app.config.from_pyfile("config.py") # Override defaults with instance path + if "QCAPP_CONF" in os.environ: + app.config.from_envvar("QCAPP_CONF") # Override defaults with instance path + + override_settings_with_envvars(app, ignore=tuple()) + + if "QCAPP_SECRETS" in os.environ: + app.config.from_envvar("QCAPP_SECRETS") # setup blueprints app.register_blueprint(entrybp, url_prefix="/") |