From 0831f721e194810fdf56673fa71639514ebe7489 Mon Sep 17 00:00:00 2001 From: koko210Serve Date: Wed, 8 Apr 2026 14:40:16 +0300 Subject: [PATCH] cleanup: remove dead backward-compat globals from config.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed the Config Manager Integration block and all 19 backward-compat variable re-exports (LLAMA_URL, CHESHIRE_CAT_URL, LANGUAGE_MODE, etc.) from config.py. These were dead code because: 1. Circular import: config.py tried to import config_manager at module level, but config_manager.py imports from config.py first, so HAS_CONFIG_MANAGER was always False and _get_config_value() was a no-op that always returned the static value. 2. Frozen snapshots: Even if the circular import worked, the values were assigned to module-level names at import time and never updated. Other modules importing 'from config import LLAMA_URL' would get a stale snapshot, not a live value. 3. Nothing imports them: The entire codebase uses globals.py for mutable runtime state, not these config.py copies. Only ERROR_WEBHOOK_URL was imported (by error_handler.py), so it is kept as a simple re-export from SECRETS. Also cleaned up unused imports: Any, field_validator. Japanese mode is NOT affected — LANGUAGE_MODE and JAPANESE_TEXT_MODEL live in globals.py and are untouched. --- bot/config.py | 59 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/bot/config.py b/bot/config.py index 7f137e1..38b135e 100644 --- a/bot/config.py +++ b/bot/config.py @@ -7,8 +7,8 @@ Uses Pydantic for type-safe configuration loading from: import os from pathlib import Path -from typing import Any, Optional -from pydantic import BaseModel, Field, field_validator +from typing import Optional +from pydantic import BaseModel, Field from pydantic_settings import BaseSettings, SettingsConfigDict # ============================================ @@ -175,60 +175,9 @@ CONFIG = load_config() SECRETS = load_secrets() # ============================================ -# Config Manager Integration +# Re-exports for modules that import from config # ============================================ -# Import config_manager for unified configuration with Web UI support -try: - from config_manager import config_manager - HAS_CONFIG_MANAGER = True -except ImportError: - # Fallback if config_manager is not yet imported - HAS_CONFIG_MANAGER = False - config_manager = None - -# ============================================ -# Backward Compatibility Globals -# ============================================ -# These provide a transition path from globals.py to config.py -# These now support runtime overrides via config_manager -# TODO: Gradually migrate all code to use CONFIG/SECRETS directly - -# Legacy globals (for backward compatibility) -# These now support runtime overrides via config_manager - -def _get_config_value(static_value: Any, key_path: str, default: Any = None) -> Any: - """Get configuration value with config_manager fallback.""" - if HAS_CONFIG_MANAGER and config_manager: - runtime_value = config_manager.get(key_path) - return runtime_value if runtime_value is not None else static_value - return static_value - -def _get_config_state(static_value: Any, state_key: str) -> Any: - """Get configuration state from config_manager.""" - if HAS_CONFIG_MANAGER and config_manager: - state_value = config_manager.get_state(state_key) - return state_value if state_value is not None else static_value - return static_value - -# Service URLs -DISCORD_BOT_TOKEN = SECRETS.discord_bot_token -CHESHIRE_CAT_API_KEY = SECRETS.cheshire_cat_api_key -CHESHIRE_CAT_URL = _get_config_value(CONFIG.cheshire_cat.url, "services.cheshire_cat.url", "http://cheshire-cat:80") -USE_CHESHIRE_CAT = _get_config_value(CONFIG.cheshire_cat.enabled, "services.cheshire_cat.enabled", True) -CHESHIRE_CAT_TIMEOUT = _get_config_value(CONFIG.cheshire_cat.timeout_seconds, "services.cheshire_cat.timeout_seconds", 120) -LLAMA_URL = _get_config_value(CONFIG.services.url, "services.llama.url", "http://llama-swap:8080") -LLAMA_AMD_URL = _get_config_value(CONFIG.services.amd_url, "services.llama.amd_url", "http://llama-swap-amd:8080") -TEXT_MODEL = _get_config_value(CONFIG.models.text, "models.text", "llama3.1") -VISION_MODEL = _get_config_value(CONFIG.models.vision, "models.vision", "vision") -EVIL_TEXT_MODEL = _get_config_value(CONFIG.models.evil, "models.evil", "darkidol") -JAPANESE_TEXT_MODEL = _get_config_value(CONFIG.models.japanese, "models.japanese", "swallow") -OWNER_USER_ID = SECRETS.owner_user_id -AUTONOMOUS_DEBUG = _get_config_value(CONFIG.autonomous.debug_mode, "autonomous.debug_mode", False) -VOICE_DEBUG_MODE = _get_config_value(CONFIG.voice.debug_mode, "voice.debug_mode", False) -LANGUAGE_MODE = _get_config_value(CONFIG.discord.language_mode, "discord.language_mode", "english") -LOG_DIR = _get_config_value(CONFIG.memory.log_dir, "memory.log_dir", "/app/memory/logs") -PREFER_AMD_GPU = _get_config_value(CONFIG.gpu.prefer_amd, "gpu.prefer_amd", False) -AMD_MODELS_ENABLED = _get_config_value(CONFIG.gpu.amd_models_enabled, "gpu.amd_models_enabled", True) +# error_handler.py imports ERROR_WEBHOOK_URL from here ERROR_WEBHOOK_URL = SECRETS.error_webhook_url # ============================================