aboutsummaryrefslogtreecommitdiff
path: root/qc_app
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-27 05:23:21 +0300
committerFrederick Muriuki Muriithi2024-02-27 05:23:21 +0300
commit0828eb4f7400c72b37381bbaea6496e8a8a92f09 (patch)
treee53ba6a463cb3638f1a41308ece788b1e975a1ed /qc_app
parent075b554cdde11f32e73981222a2cede3bb249151 (diff)
downloadgn-uploader-0828eb4f7400c72b37381bbaea6496e8a8a92f09.tar.gz
Remove use of instance path in configurations.
Diffstat (limited to 'qc_app')
-rw-r--r--qc_app/__init__.py25
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="/")