@@ -124,14 +124,6 @@ def _resolve_one_item(self, id: str, waiting_list: Optional[Set[str]] = None):
124
124
else :
125
125
self .resolved_content [id ] = new_config
126
126
127
- def resolve_all (self ):
128
- """
129
- Resolve the references for all the config items.
130
-
131
- """
132
- for k in self .items :
133
- self ._resolve_one_item (id = k )
134
-
135
127
def get_resolved_content (self , id : str ):
136
128
"""
137
129
Get the resolved content with specified id name.
@@ -194,9 +186,7 @@ def update_refs_pattern(value: str, refs: Dict) -> str:
194
186
return value
195
187
196
188
@staticmethod
197
- def find_refs_in_config (
198
- config : Union [Dict , List , str ], id : Optional [str ] = None , refs : Optional [List [str ]] = None
199
- ) -> List [str ]:
189
+ def find_refs_in_config (config : Union [Dict , List , str ], id : str , refs : Optional [List [str ]] = None ) -> List [str ]:
200
190
"""
201
191
Recursively search all the content of input config item to get the ids of references.
202
192
References mean: the IDs of other config items used as "@XXX" in this config item, or the
@@ -205,7 +195,7 @@ def find_refs_in_config(
205
195
206
196
Args:
207
197
config: input config content to search.
208
- id: ID name for the input config item, default to `None` .
198
+ id: ID name for the input config item.
209
199
refs: list of the ID name of found references, default to `None`.
210
200
211
201
"""
@@ -216,21 +206,21 @@ def find_refs_in_config(
216
206
if isinstance (config , (list , dict )):
217
207
subs = enumerate (config ) if isinstance (config , list ) else config .items ()
218
208
for k , v in subs :
219
- sub_id = f"{ id } #{ k } " if id is not None else f"{ k } "
209
+ sub_id = f"{ id } #{ k } " if len ( id ) > 0 else f"{ k } "
220
210
if ConfigComponent .is_instantiable (v ) or ConfigExpression .is_expression (v ):
221
211
refs_ .append (sub_id )
222
212
refs_ = ReferenceResolver .find_refs_in_config (v , sub_id , refs_ )
223
213
return refs_
224
214
225
215
@staticmethod
226
- def update_config_with_refs (config : Union [Dict , List , str ], id : Optional [ str ] = None , refs : Optional [Dict ] = None ):
216
+ def update_config_with_refs (config : Union [Dict , List , str ], id : str , refs : Optional [Dict ] = None ):
227
217
"""
228
218
With all the references in `refs`, update the input config content with references
229
219
and return the new config.
230
220
231
221
Args:
232
222
config: input config content to update.
233
- id: ID name for the input config, default to `None` .
223
+ id: ID name for the input config.
234
224
refs: all the referring content with ids, default to `None`.
235
225
236
226
"""
@@ -241,7 +231,7 @@ def update_config_with_refs(config: Union[Dict, List, str], id: Optional[str] =
241
231
# all the items in the list should be replaced with the references
242
232
ret_list : List = []
243
233
for i , v in enumerate (config ):
244
- sub_id = f"{ id } #{ i } " if id is not None else f"{ i } "
234
+ sub_id = f"{ id } #{ i } " if len ( id ) > 0 else f"{ i } "
245
235
if ConfigComponent .is_instantiable (v ) or ConfigExpression .is_expression (v ):
246
236
ret_list .append (refs_ [sub_id ])
247
237
else :
@@ -251,7 +241,7 @@ def update_config_with_refs(config: Union[Dict, List, str], id: Optional[str] =
251
241
# all the items in the dict should be replaced with the references
252
242
ret_dict : Dict = {}
253
243
for k , v in config .items ():
254
- sub_id = f"{ id } #{ k } " if id is not None else f"{ k } "
244
+ sub_id = f"{ id } #{ k } " if len ( id ) > 0 else f"{ k } "
255
245
if ConfigComponent .is_instantiable (v ) or ConfigExpression .is_expression (v ):
256
246
ret_dict [k ] = refs_ [sub_id ]
257
247
else :
0 commit comments