refactor(config): migrate from .env to YAML with OmegaConf#350
refactor(config): migrate from .env to YAML with OmegaConf#350looksaw2 wants to merge 3 commits into
Conversation
Replace pydantic-settings + python-dotenv with OmegaConf-based config.yaml. Supports nested YAML structure, environment variable override (os.environ > config.yaml > defaults), auto-migration from existing .env, and hot-reload via file watcher. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Update design.md to reflect the nested YAML structure (via flat↔nested mapping), update tasks.md to mark all 10 task groups completed, and document implementation differences from the original plan. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Translate requirements.md, design.md, and tasks.md from Chinese to English to meet project contribution guidelines. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
| # Load .env into os.environ for backward compatibility and priority override | ||
| if os.path.exists(self._env_path): | ||
| for k, v in dotenv_values(self._env_path).items(): | ||
| os.environ[k] = v |
There was a problem hiding this comment.
This loop copies every key from .env into os.environ before YAML/env override resolution. That reverses the intended deployment precedence when the process already has real environment variables: I reproduced this with .env containing OPENAI_API_KEY=from_dotenv while launching with OPENAI_API_KEY=from_real_env, and llm_settings.openai_chat_api_key became from_dotenv. Existing pydantic settings gave the real environment precedence over the dotenv file, so a stale local .env can override Docker/Kubernetes secrets after this migration. Please only fill missing keys from .env (for example os.environ.setdefault(...), skipping empty values) and add a regression test for env > .env/config.yaml precedence.
| os.environ[k] = v | |
| for k, v in dotenv_values(self._env_path).items(): | |
| if v: | |
| os.environ.setdefault(k, v) |
Migrated config storage from .env to config.yaml using OmegaConf.
/ admin / index sections with nested structure.
restarting. Polling interval is configurable.
first run, no manual setup needed.
environment variables, overriding YAML values (12-factor friendly).
exactly the same, 46 consumer files untouched.