separated cli settings

This commit is contained in:
John Lancaster
2026-07-31 19:23:12 -05:00
parent 4ed1f43eda
commit 209c48987c
2 changed files with 23 additions and 9 deletions
+13 -6
View File
@@ -1,17 +1,24 @@
import uvicorn
from fastapi import FastAPI
from .config import LOGGING_CONFIG
from .config import get_settings
from .app import create_app
from .config import parse_cli_settings
def create_cli_app() -> FastAPI:
"""Create an app from CLI settings for Uvicorn's reload process."""
return create_app(settings=parse_cli_settings())
def main() -> None:
settings = get_settings()
settings = parse_cli_settings()
application = "transcription.__main__:create_cli_app" if settings.reload else create_app(settings=settings)
uvicorn.run(
"transcription.app:create_app",
factory=True,
application,
factory=settings.reload,
host=settings.host,
port=settings.port,
log_level=LOGGING_CONFIG.get("root", {}).get("level", "info").lower(),
log_level=settings.log_level,
reload=settings.reload,
)
+10 -3
View File
@@ -6,6 +6,7 @@ are resolved by the provider adapters, not here.
"""
import logging.config
from collections.abc import Sequence
from enum import StrEnum
from functools import cache
from pathlib import Path
@@ -51,7 +52,6 @@ class Settings(BaseSettings):
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
cli_parse_args=True,
cli_implicit_flags=True,
cli_kebab_case=True,
)
@@ -99,8 +99,15 @@ class Settings(BaseSettings):
@cache
def get_settings(**kwargs) -> Settings:
return Settings(**kwargs)
def get_settings(**kwargs: Any) -> Settings:
"""Load cached settings without reading process CLI arguments."""
return Settings(_cli_parse_args=False, **kwargs)
def parse_cli_settings(args: Sequence[str] | None = None) -> Settings:
"""Load settings with CLI arguments at the executable boundary."""
cli_args = True if args is None else list(args)
return Settings(_cli_parse_args=cli_args)
LOGGING_CONFIG: dict[str, Any] = {