File tree Expand file tree Collapse file tree 3 files changed +25
-18
lines changed
Expand file tree Collapse file tree 3 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 55
66import aiocache
77
8- from .config import get_settings
8+ from .config import _Settings
99
1010LOGGER = logging .getLogger (name = "app.caches" )
1111
12- SETTINGS = get_settings ()
12+ SETTINGS = _Settings . get_settings ()
1313
1414if SETTINGS .rediscloud_url :
1515 REDIS_URL = SETTINGS .rediscloud_url
Original file line number Diff line number Diff line change 88
99
1010class _Settings (BaseSettings ):
11+
12+ settingsInstance = None
13+
1114 port : int = 5000
1215 rediscloud_url : AnyUrl = None
1316 local_redis_url : AnyUrl = None
@@ -16,18 +19,23 @@ class _Settings(BaseSettings):
1619 # Sentry
1720 sentry_dsn : str = None
1821
22+ def __init__ (self ):
23+ if _Settings .settingsInstance :
24+ raise Exception ("This is a singleton" )
25+ else :
26+ _Settings .settingsInstance = self
1927
2028@functools .lru_cache ()
21- def get_settings (** kwargs ) -> BaseSettings :
22- """
23- Read settings from the environment or `.env` file.
24- https://pydantic-docs.helpmanual.io/usage/settings/#dotenv-env-support
25-
26- Usage:
27- import app.config
28-
29- settings = app.config.get_settings(_env_file="")
30- port_number = settings.port
31- """
32- CFG_LOGGER .info ("Loading Config settings from Environment ..." )
33- return _Settings (** kwargs )
29+ def get_settings (** kwargs ) -> BaseSettings :
30+ """
31+ Read settings from the environment or `.env` file.
32+ https://pydantic-docs.helpmanual.io/usage/settings/#dotenv-env-support
33+
34+ Usage:
35+ import app.config
36+
37+ settings = app.config._Settings .get_settings(_env_file="")
38+ port_number = settings.port
39+ """
40+ CFG_LOGGER .info ("Loading Config settings from Environment ..." )
41+ return _Settings (** kwargs )
Original file line number Diff line number Diff line change 1313from scout_apm .async_ .starlette import ScoutMiddleware
1414from sentry_sdk .integrations .asgi import SentryAsgiMiddleware
1515
16- from .config import get_settings
16+ from .config import _Settings
1717from .data import data_source
1818from .routers import V1 , V2
1919from .utils .httputils import setup_client_session , teardown_client_session
2323# ############
2424LOGGER = logging .getLogger ("api" )
2525
26- SETTINGS = get_settings ()
26+ SETTINGS = _Settings . get_settings ()
2727
2828if SETTINGS .sentry_dsn : # pragma: no cover
2929 sentry_sdk .init (dsn = SETTINGS .sentry_dsn )
@@ -113,7 +113,6 @@ async def handle_validation_error(
113113APP .include_router (V1 , prefix = "" , tags = ["v1" ])
114114APP .include_router (V2 , prefix = "/v2" , tags = ["v2" ])
115115
116-
117116# Running of app.
118117if __name__ == "__main__" :
119118 uvicorn .run (
You can’t perform that action at this time.
0 commit comments