@@ -30,9 +30,7 @@ def load_from_py_file(
30
30
) -> Any :
31
31
"""Load a config value from a Python file."""
32
32
path = Path (path )
33
- _log .info (
34
- f"Loading configuration from Python file { path !r} (variable { variable !r} )"
35
- )
33
+ _log .debug (f"Loading configuration from Python file { path !r} (variable { variable !r} )" )
36
34
37
35
# Based on flask's Config.from_pyfile
38
36
with path .open (mode = "rb" ) as f :
@@ -73,11 +71,9 @@ def __call__(self, force_reload: bool = False) -> OpenEoBackendConfig:
73
71
def get (self , force_reload : bool = False ) -> OpenEoBackendConfig :
74
72
"""Lazy load the config."""
75
73
if self ._config is None :
76
- _log .info ("Lazy load config" )
77
- self ._config = self ._load ()
74
+ self ._config = self ._load (reason = "lazy_load" )
78
75
elif force_reload :
79
- _log .info ("Force reload config" )
80
- self ._config = self ._load ()
76
+ self ._config = self ._load (reason = "force_reload" )
81
77
82
78
return self ._config
83
79
@@ -87,13 +83,13 @@ def _default_config(self) -> ContextManager[Path]:
87
83
"""
88
84
return importlib_resources .path ("openeo_driver.config" , "default.py" )
89
85
90
- def _load (self ) -> OpenEoBackendConfig :
86
+ def _load (self , reason : Optional [ str ] = None ) -> OpenEoBackendConfig :
91
87
"""Load the config from config file."""
92
88
with self ._default_config () as default_config :
93
89
config_path = os .environ .get (self .OPENEO_BACKEND_CONFIG ) or default_config
94
90
config = load_from_py_file (path = config_path , variable = "config" , expected_class = self .expected_class )
95
- if hasattr (config , "id" ):
96
- _log .info (f"Loaded config { config . id = } " )
91
+ config_id = getattr (config , "id" , None )
92
+ _log .info (f"Loaded config { config_id = } from { config_path = } ( { reason = } ) " )
97
93
return config
98
94
99
95
def flush (self ):
0 commit comments