File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 1+ from functools import lru_cache
2+
13from pydantic_settings import BaseSettings , SettingsConfigDict
24
35
@@ -10,4 +12,11 @@ class Settings(BaseSettings):
1012 model_config = SettingsConfigDict (env_file = ".env" )
1113
1214
13- settings = Settings ()
15+ @lru_cache
16+ def get_settings ():
17+ """Return the application settings.
18+
19+ A function so the actual construction is deferred until needed (avoiding test issues), and
20+ lru_cached for efficiency.
21+ """
22+ return Settings ()
Original file line number Diff line number Diff line change 66from fastapi .middleware .cors import CORSMiddleware
77from mangum import Mangum
88
9- from app .config import settings
9+ from app .config import get_settings
1010from app .explain import process_request
1111from app .explain_api import (
1212 AvailableOptions ,
2121logger = logging .getLogger ()
2222logger .setLevel (logging .INFO )
2323
24- app = FastAPI (root_path = settings .root_path )
24+ app = FastAPI (root_path = get_settings () .root_path )
2525
2626# Configure CORS - allows all origins for public API
2727app .add_middleware (
3434)
3535handler = Mangum (app )
3636
37- anthropic_client = Anthropic (api_key = settings .anthropic_api_key )
37+ anthropic_client = Anthropic (api_key = get_settings () .anthropic_api_key )
3838logger .info (f"Anthropic SDK version: { anthropic_version } " )
3939
4040
Original file line number Diff line number Diff line change 55from aws_embedded_metrics .logger .metrics_logger import MetricsLogger
66from aws_embedded_metrics .logger .metrics_logger_factory import create_metrics_logger
77
8- from app .config import settings
8+ from app .config import get_settings
99
1010
1111class MetricsProvider (ABC ):
@@ -52,7 +52,7 @@ async def get_metrics_provider() -> AsyncGenerator[MetricsProvider]:
5252 When metrics are enabled, creates a CloudWatch metrics provider and ensures
5353 proper flushing. When disabled, provides a no-op implementation.
5454 """
55- if settings .metrics_enabled :
55+ if get_settings () .metrics_enabled :
5656 metrics_logger = create_metrics_logger ()
5757 metrics_logger .set_namespace ("CompilerExplorer" )
5858 provider = CloudWatchMetricsProvider (metrics_logger )
You can’t perform that action at this time.
0 commit comments