-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstants.py
More file actions
67 lines (51 loc) · 1.69 KB
/
constants.py
File metadata and controls
67 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import os
from pathlib import Path
from sample.utils.config import load_env
load_env()
APP_TITLE = ":blue[Greeting Feature]"
DEFAULT_GREETING = "Hello"
DEFAULT_PORT = 8501
FAQ_TITLE = "FAQs"
logging.basicConfig(
level=logging.INFO, # or DEBUG
format="%(asctime)s - %(levelname)s - %(message)s",
)
# --- Asset paths ---
PROJECT_ROOT = Path(__file__).parent.parent.resolve()
print(f"Project root: {PROJECT_ROOT}") # Debugging statement to verify path resolution
ASSETS_DIR = PROJECT_ROOT / "assets" / "images"
COMPANY_LOGO = ASSETS_DIR / "logo.png"
def safe_get(env_key: str = "", default: str = "") -> str:
"""
Safely retrieve a configuration value from:
1. Streamlit secrets (if secrets.toml exists)
2. Environment variable
3. Default fallback
Logs the source used for each config value.
"""
value = default
source = "default"
# If secrets not used, fallback to env
if source != "secrets" and env_key:
env_val = os.getenv(env_key)
if env_val:
value = env_val
source = "env"
logging.info(
f"Loaded config for '{env_key}' from [{source}]",
extra={"color": "yellow"},
)
return value
def get_mongo_config():
return {
"MONGODB_URI": safe_get("MONGODB_URI"),
"DATABASE_NAME": safe_get("DATABASE_NAME"),
}
PORT = safe_get("PORT", DEFAULT_PORT)
PORT_API = safe_get("API_PORT", int(PORT) + 1)
MONGO_CONFIG = get_mongo_config()
# === Environment Selection ===
ENVIRONMENT = safe_get("ENVIRONMENT", "development").lower()
logging.info(f"Environment: {ENVIRONMENT}", extra={"color": "yellow"})
logging.info(f"Project root: {PROJECT_ROOT}", extra={"color": "yellow"})