@@ -49,6 +49,10 @@ class Configuration(BaseModel):
49
49
)
50
50
51
51
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 )
52
56
53
57
@model_validator (mode = "after" )
54
58
def expand_cache_path (self ):
@@ -96,12 +100,17 @@ def read(cls, config_path: Optional[str] = None):
96
100
:return: Populated configuration object
97
101
"""
98
102
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
+ )
100
106
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 )
102
108
103
109
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
105
114
else :
106
115
path_extra = f"in { config_path } " if config_path else ""
107
116
raise NameError (
@@ -111,6 +120,7 @@ def read(cls, config_path: Optional[str] = None):
111
120
@classmethod
112
121
def _add_from_path (cls , path : Optional [Path ] = None , walk_up_tree : bool = False ):
113
122
config = None
123
+ found_file : Optional [Path ] = None
114
124
if path :
115
125
path .resolve ()
116
126
name = path .name
@@ -126,14 +136,16 @@ def _add_from_path(cls, path: Optional[Path] = None, walk_up_tree: bool = False)
126
136
if f .exists ():
127
137
with open (f ) as config_file :
128
138
config = yaml .safe_load (config_file )
129
- break
139
+ found_file = f
140
+ break
130
141
131
142
if alt_name :
132
143
f = dir / alt_name # if neither option above, find servicex.yaml
133
144
if f .exists ():
134
145
with open (f ) as config_file :
135
146
config = yaml .safe_load (config_file )
136
- break
147
+ found_file = f
148
+ break
137
149
138
150
if not walk_up_tree :
139
151
break
@@ -155,6 +167,7 @@ def _add_from_path(cls, path: Optional[Path] = None, walk_up_tree: bool = False)
155
167
if f .exists ():
156
168
with open (f ) as config_file :
157
169
config = yaml .safe_load (config_file )
170
+ found_file = f
158
171
break
159
172
160
- return config
173
+ return config , found_file
0 commit comments