From 64f8058c60b1b829a1e1383c2b11f96b4d81925b Mon Sep 17 00:00:00 2001 From: bohd4nx Date: Thu, 5 Mar 2026 04:23:34 +0200 Subject: [PATCH] fix: don't sys.exit in config at import time, support CI env vars --- app/core/config.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 6ca9814..145e27e 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -1,6 +1,5 @@ import logging import os -import sys from pathlib import Path from dotenv import load_dotenv @@ -15,28 +14,24 @@ class Config: API_KEY: str def __init__(self) -> None: + # Load .env if present; env vars already in the process take precedence env_path = Path(__file__).resolve().parents[2] / ".env" - - if not env_path.exists(): - raise ConfigError( - ".env file not found. " - "Copy .env.example to .env and fill in SEED and API_KEY." - ) - - load_dotenv(env_path) + if env_path.exists(): + load_dotenv(env_path) missing = [k for k in ("SEED", "API_KEY") if not os.getenv(k, "").strip()] if missing: raise ConfigError( f"Missing required environment variables: {', '.join(missing)}. " - "Open .env and fill in all required fields." + "Copy .env.example to .env and fill in SEED and API_KEY." ) self.SEED = os.getenv("SEED", "").strip() self.API_KEY = os.getenv("API_KEY", "").strip() + +config: Config | None = None try: config = Config() except ConfigError as e: - logger.error("Configuration error: %s", e) - sys.exit(1) + logger.warning("Configuration not loaded: %s", e)