from functools import lru_cache from pydantic import Field, computed_field from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict( env_file = ".env", env_file_encoding = "utf-8" ) # CORS as a private field with a string type: cors_origins_raw: str = Field( default="http://localhost:5173", alias="cors_origins" ) @computed_field @property def cors_origins(self) -> list[str]: """Converts a string into list.""" if isinstance(self.cors_origins_raw, list): return self.cors_origins_raw return [ origin.strip() for origin in self.cors_origins_raw.split(",") if origin.strip() ] # Autres configurations futures app_name: str = "Dough Calculator" debug: bool = False @lru_cache def get_settings() -> Settings: return Settings()