about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-10-15 17:44:22 -0500
committerFrederick Muriuki Muriithi2025-10-15 17:44:22 -0500
commit977efbb54da284fb3e8476f200206d00cb8e64cd (patch)
treedbe02a37da26b256ba054799cbd1d19eb0683777
parentd24ffc9afa92c7d938813ee6745f8d43ac88a0a8 (diff)
downloadgenenetwork3-977efbb54da284fb3e8476f200206d00cb8e64cd.tar.gz
Configurations: Use non-executable file for settings.
Move configuration from executable .py file into a non-executable
.json file.

See https://issues.genenetwork.org/issues/genenetwork3/genenetwork3_configuration
-rw-r--r--gn3/app.py6
-rw-r--r--gn3/settings.json59
-rw-r--r--gn3/settings.py86
3 files changed, 63 insertions, 88 deletions
diff --git a/gn3/app.py b/gn3/app.py
index 864ae99..0868f3a 100644
--- a/gn3/app.py
+++ b/gn3/app.py
@@ -1,7 +1,7 @@
 """Entry point from spinning up flask"""
-
 import os
 import sys
+import json
 import logging
 from pathlib import Path
 
@@ -63,7 +63,9 @@ def create_app(config: Union[Dict, str, None] = None) -> Flask:
     """Create a new flask object"""
     app = Flask(__name__)
     # Load default configuration
-    app.config.from_object("gn3.settings")
+    app.config.from_file(
+        Path(__file__).absolute().parent.joinpath("settings.json"),
+        load=json.load)
 
     # Load environment configuration
     if "GN3_CONF" in os.environ:
diff --git a/gn3/settings.json b/gn3/settings.json
new file mode 100644
index 0000000..a2f427e
--- /dev/null
+++ b/gn3/settings.json
@@ -0,0 +1,59 @@
+{
+    "==": "================ FLASK SETTINGS ================",
+    "--": "-- Base --",
+    "SECRET_KEY": "password",
+    "APPLICATION_ENVIRONMENT": "",
+
+    "--": "-- Flask-CORS --",
+    "CORS_ORIGINS": "*",
+    "CORS_HEADERS": [
+        "Content-Type",
+        "Authorization",
+        "Access-Control-Allow-Credentials"
+    ],
+    "==": "================================================",
+
+
+    "==": "================ Filesystem Paths SETTINGS ================",
+    "TMPDIR": "/tmp",
+    "DATA_DIR": "",
+    "CACHEDIR": "",
+    "LMDB_DATA_PATH": "/var/lib/lmdb",
+    "XAPIAN_DB_PATH": "xapian",
+    "LLM_DB_PATH": "",
+    "GENOTYPE_FILES": "/var/lib/genenetwork/genotype-files/genotype",
+    "TEXTDIR": "/gnshare/gn/web/ProbeSetFreeze_DataMatrix",
+    "_comment_TEXTDIR": "The configuration variable `TEXTDIR` points to a directory containing text files used for certain processes. On tux01 this path is '/home/gn1/production/gnshare/gn/web/ProbeSetFreeze_DataMatrix'.",
+    "==": "================================================",
+
+
+    "==": "================ Connection URIs ================",
+    "REDIS_URI": "redis://localhost:6379/0",
+    "SQL_URI": "mysql://user:password@host/db",
+    "SPARQL_ENDPOINT": "http://localhost:9082/sparql",
+    "AUTH_SERVER_URL": "",
+    "==": "================================================",
+
+
+    "==": "================ CLI Commands ================",
+    "GEMMA_WRAPPER_CMD": "gemma-wrapper",
+    "WGCNA_RSCRIPT": "wgcna_analysis.R",
+    "REAPER_COMMAND": "qtlreaper",
+    "CORRELATION_COMMAND": "correlation_rust",
+    "==": "================================================",
+
+
+    "==": "================ Service-Specific Settings ================",
+    "--": "-- Redis --",
+    "REDIS_JOB_QUEUE": "GN3::job-queue",
+
+    "--": "-- Fahamu --",
+    "FAHAMU_AUTH_TOKEN": "",
+    "==": "================================================",
+
+
+    "==": "================ Application-Specific Settings ================",
+    "ROUND_TO": 10,
+    "MULTIPROCESSOR_PROCS": 6,
+    "==": "================================================"
+}
diff --git a/gn3/settings.py b/gn3/settings.py
deleted file mode 100644
index 769e466..0000000
--- a/gn3/settings.py
+++ /dev/null
@@ -1,86 +0,0 @@
-"""
-Default configuration settings for this project.
-
-DO NOT import from this file, use `flask.current_app.config` instead to get the
-application settings.
-"""
-import os
-import tempfile
-
-### APPLICATION_ENVIRONMENT: can be something like
-### production, staging, development, tux02-prod, tux04-staging, etc.
-### Useful to distinguish resources for different containers if you run multiple
-## containers on the same host e.g. distinguish keys on a redis instance for
-## different containers.
-APPLICATION_ENVIRONMENT = ""
-
-DATA_DIR = ""
-GEMMA_WRAPPER_CMD = os.environ.get("GEMMA_WRAPPER", "gemma-wrapper")
-CACHEDIR = ""
-REDIS_URI = "redis://localhost:6379/0"
-REDIS_JOB_QUEUE = "GN3::job-queue"
-TMPDIR = os.environ.get("TMPDIR", tempfile.gettempdir())
-
-# SPARQL endpoint
-SPARQL_ENDPOINT = os.environ.get(
-    "SPARQL_ENDPOINT",
-    "http://localhost:9082/sparql")
-
-# LMDB paths
-LMDB_DATA_PATH = os.environ.get("LMDB_DATA_PATH")
-
-# SQL confs
-SQL_URI = os.environ.get(
-    "SQL_URI", "mysql://webqtlout:webqtlout@localhost/db_webqtl")
-SECRET_KEY = "password"
-
-# FAHAMU API TOKEN
-FAHAMU_AUTH_TOKEN = ""
-
-# wgcna script
-WGCNA_RSCRIPT = "wgcna_analysis.R"
-# qtlreaper command
-REAPER_COMMAND = f"{os.environ.get('GUIX_ENVIRONMENT')}/bin/qtlreaper"
-
-# correlation command
-
-CORRELATION_COMMAND = f"{os.environ.get('GN2_PROFILE')}/bin/correlation_rust"
-
-# genotype files
-GENOTYPE_FILES = os.environ.get(
-    "GENOTYPE_FILES", f"{os.environ.get('HOME')}/genotype_files/genotype")
-
-# Xapian index
-XAPIAN_DB_PATH = "xapian"
-
-# sqlite path
-
-LLM_DB_PATH = ""
-# CROSS-ORIGIN SETUP
-
-
-def parse_env_cors(default):
-    """Parse comma-separated configuration into list of strings."""
-    origins_str = os.environ.get("CORS_ORIGINS", None)
-    if origins_str:
-        return [
-            origin.strip() for origin in origins_str.split(",") if origin != ""]
-    return default
-
-
-CORS_ORIGINS = parse_env_cors("*")
-
-CORS_HEADERS = [
-    "Content-Type",
-    "Authorization",
-    "Access-Control-Allow-Credentials"
-]
-
-GNSHARE = os.environ.get("GNSHARE", "/gnshare/gn/")
-TEXTDIR = f"{GNSHARE}/web/ProbeSetFreeze_DataMatrix"
-
-ROUND_TO = 10
-
-MULTIPROCESSOR_PROCS = 6  # Number of processes to spawn
-
-AUTH_SERVER_URL = ""