generated from john/python-template
This commit is contained in:
@@ -50,7 +50,6 @@ async def _lifespan(app: FastAPI):
|
||||
settings.upload_dir.mkdir(parents=True, exist_ok=True)
|
||||
settings.prompt_dir.mkdir(parents=True, exist_ok=True)
|
||||
settings.log_dir.mkdir(parents=True, exist_ok=True)
|
||||
settings.database_backup_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
await _recover_stale_processing_jobs(app)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Centralized application configuration.
|
||||
|
||||
All settings are loaded from environment variables (or a .env file)
|
||||
All settings are loaded from environment variables (or an env file)
|
||||
once at startup. Provider-specific defaults (model names, base URLs)
|
||||
are resolved by the provider adapters, not here.
|
||||
"""
|
||||
@@ -65,7 +65,7 @@ DatabaseSettings = Annotated[
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file=".env.production",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
env_nested_delimiter="__",
|
||||
@@ -108,7 +108,6 @@ class Settings(BaseSettings):
|
||||
# --- filesystem paths ---
|
||||
upload_dir: Path = Path("./data")
|
||||
prompt_dir: Path = Path("./prompts")
|
||||
database_backup_dir: Path = Path("./data/backups")
|
||||
|
||||
# --- worker reliability ---
|
||||
worker_max_retries: int = Field(default=0, ge=0)
|
||||
|
||||
@@ -99,12 +99,13 @@ HIDDEN_SETTINGS_CATEGORIES: tuple[HiddenSettingsCategory, ...] = (
|
||||
"CLOUDFLARE_TUNNEL_TOKEN",
|
||||
"RUNTIME_SETTINGS_ENV_FILE",
|
||||
"BACKUP_DIR",
|
||||
"APP_DATA_BACKUP_DIR",
|
||||
"UPLOADS_BACKUP_DIR",
|
||||
"BACKUP_RETENTION_DAYS",
|
||||
"SYNOLOGY_BACKUP_DIR",
|
||||
"ENV_FILE",
|
||||
"COMPOSE_FILE",
|
||||
"DATABASE_BACKUP_DIR",
|
||||
"APP_DATA_BACKUP_DIR",
|
||||
"UPLOADS_BACKUP_DIR",
|
||||
"SYNOLOGY_BACKUP_DIR",
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -250,13 +251,6 @@ RUNTIME_SETTINGS_CATALOG: tuple[RuntimeSettingDescriptor, ...] = (
|
||||
"Directory containing editable markdown prompts.",
|
||||
"text",
|
||||
),
|
||||
RuntimeSettingDescriptor(
|
||||
"database_backup_dir",
|
||||
"DATABASE_BACKUP_DIR",
|
||||
"Database backup directory",
|
||||
"Directory for generated database backups.",
|
||||
"text",
|
||||
),
|
||||
RuntimeSettingDescriptor(
|
||||
"worker_max_retries",
|
||||
"WORKER_MAX_RETRIES",
|
||||
@@ -404,7 +398,7 @@ def _resolve_env_file_path(*, settings: Settings, env_file_path: Path | None) ->
|
||||
|
||||
configured = settings.model_config.get("env_file")
|
||||
if configured is None:
|
||||
return Path(".env")
|
||||
return Path(".env.production")
|
||||
if isinstance(configured, Path):
|
||||
return Path(configured)
|
||||
if isinstance(configured, str):
|
||||
@@ -415,7 +409,7 @@ def _resolve_env_file_path(*, settings: Settings, env_file_path: Path | None) ->
|
||||
return Path(first)
|
||||
if isinstance(first, str):
|
||||
return Path(first)
|
||||
return Path(".env")
|
||||
return Path(".env.production")
|
||||
|
||||
|
||||
def _display_value(value: object) -> str | bool:
|
||||
@@ -459,7 +453,7 @@ def _validate_candidate_env(*, env_map: dict[str, str], env_file_path: Path) ->
|
||||
raise AppError(
|
||||
"One or more settings values are invalid.",
|
||||
category=ErrorCategory.VALIDATION,
|
||||
suggestion="Review the highlighted values and use the same formats shown in .env.example.",
|
||||
suggestion="Review the highlighted values and use the same formats shown in .env.production.example.",
|
||||
detail=f"Invalid runtime settings for {env_file_path}: {exc}",
|
||||
) from exc
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user