@@ -49,6 +49,10 @@ class Configuration(BaseModel):
4949 )
5050
5151 shortened_downloaded_filename : Optional [bool ] = False
52+ # Path to the configuration file this object was read from. This field is
53+ # populated by :py:meth:`Configuration.read` and is not part of the input
54+ # schema.
55+ config_file : Optional [str ] = Field (default = None , exclude = True )
5256
5357 @model_validator (mode = "after" )
5458 def expand_cache_path (self ):
@@ -96,12 +100,17 @@ def read(cls, config_path: Optional[str] = None):
96100 :return: Populated configuration object
97101 """
98102 if config_path :
99- yaml_config = cls ._add_from_path (Path (config_path ), walk_up_tree = False )
103+ yaml_config , cfg_path = cls ._add_from_path (
104+ Path (config_path ), walk_up_tree = False
105+ )
100106 else :
101- yaml_config = cls ._add_from_path (walk_up_tree = True )
107+ yaml_config , cfg_path = cls ._add_from_path (walk_up_tree = True )
102108
103109 if yaml_config :
104- return Configuration .model_validate (yaml_config )
110+ cfg = Configuration .model_validate (yaml_config )
111+ if cfg_path :
112+ cfg .config_file = str (cfg_path )
113+ return cfg
105114 else :
106115 path_extra = f"in { config_path } " if config_path else ""
107116 raise NameError (
@@ -111,8 +120,9 @@ def read(cls, config_path: Optional[str] = None):
111120 @classmethod
112121 def _add_from_path (cls , path : Optional [Path ] = None , walk_up_tree : bool = False ):
113122 config = None
123+ found_file : Optional [Path ] = None
114124 if path :
115- path .resolve ()
125+ path = path .resolve ()
116126 name = path .name
117127 dir = path .parent .resolve ()
118128 alt_name = None
@@ -126,14 +136,16 @@ def _add_from_path(cls, path: Optional[Path] = None, walk_up_tree: bool = False)
126136 if f .exists ():
127137 with open (f ) as config_file :
128138 config = yaml .safe_load (config_file )
129- break
139+ found_file = f
140+ break
130141
131142 if alt_name :
132143 f = dir / alt_name # if neither option above, find servicex.yaml
133144 if f .exists ():
134145 with open (f ) as config_file :
135146 config = yaml .safe_load (config_file )
136- break
147+ found_file = f
148+ break
137149
138150 if not walk_up_tree :
139151 break
@@ -155,6 +167,7 @@ def _add_from_path(cls, path: Optional[Path] = None, walk_up_tree: bool = False)
155167 if f .exists ():
156168 with open (f ) as config_file :
157169 config = yaml .safe_load (config_file )
170+ found_file = f
158171 break
159172
160- return config
173+ return config , found_file
0 commit comments