35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import os
|
||
import logging
|
||
from dotenv import load_dotenv
|
||
|
||
log = logging.getLogger("ainventory")
|
||
|
||
def load_config():
|
||
"""
|
||
Centralized environment loader for TFM aInventory.
|
||
Prioritizes existing environment variables (Docker),
|
||
then inventory.env at project root, then backend/.env.
|
||
"""
|
||
# Base directory is backend/
|
||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||
# Project root is one level up
|
||
project_root = os.path.dirname(base_dir)
|
||
|
||
inventory_env_path = os.path.join(project_root, "inventory.env")
|
||
backend_env_path = os.path.join(base_dir, ".env")
|
||
|
||
# Check for inventory.env in root (Master Config)
|
||
if os.path.exists(inventory_env_path):
|
||
load_dotenv(inventory_env_path)
|
||
log.info(f"✅ Loaded master configuration from {inventory_env_path}")
|
||
|
||
# Check for local backend/.env (Legacy/Fragmented)
|
||
elif os.path.exists(backend_env_path):
|
||
load_dotenv(backend_env_path)
|
||
log.info(f"ℹ️ Loaded local configuration from {backend_env_path}")
|
||
else:
|
||
log.info("ℹ️ [CONFIG] Using system environment variables (Docker/Server environment).")
|
||
|
||
# Auto-run if imported
|
||
load_config()
|