feat(config): pydantic settings loader from .env
Aggiunge Settings (BaseSettings) che carica configurazione da variabili d'ambiente / file .env, con validazione obbligatoria dei segreti Cerbero testnet e OpenRouter. Test: - test_settings_loads_from_env: happy path via monkeypatch.setenv - test_settings_requires_tokens: ValidationError quando token obbligatori mancano (forza _env_file=None per isolare il test da eventuale .env locale popolato). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Pydantic settings loader for Multi_Swarm_Coevolutive.
|
||||
|
||||
Loads configuration from environment variables and an optional ``.env`` file
|
||||
in the project root. Required secrets are validated at instantiation time.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import Field, SecretStr
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
case_sensitive=False,
|
||||
)
|
||||
|
||||
cerbero_base_url: str = "http://localhost:9000"
|
||||
cerbero_testnet_token: SecretStr
|
||||
cerbero_mainnet_token: SecretStr | None = None
|
||||
cerbero_bot_tag: str = "swarm-poc-phase1"
|
||||
|
||||
openrouter_api_key: SecretStr
|
||||
anthropic_api_key: SecretStr | None = None
|
||||
|
||||
run_name: str = "phase1-spike-001"
|
||||
data_dir: Path = Field(default=Path("./data"))
|
||||
series_dir: Path = Field(default=Path("./series"))
|
||||
db_path: Path = Field(default=Path("./runs.db"))
|
||||
|
||||
|
||||
def load_settings() -> Settings:
|
||||
# Required fields are populated from environment / .env, not init kwargs.
|
||||
return Settings() # type: ignore[call-arg]
|
||||
Reference in New Issue
Block a user