@@ -930,25 +930,36 @@ def check_overwrite(path):
930930
931931 ActionLink .strip_link_target_keys (self , cfg )
932932
933+ def is_path_action (key ):
934+ action = _find_action (self , key )
935+ return isinstance (action , (ActionJsonSchema , ActionJsonnet , ActionTypeHint , _ActionConfigLoad ))
936+
937+ def save_path (val ):
938+ val_path = Path (os .path .basename (val ["__path__" ].absolute ), mode = "fc" )
939+ check_overwrite (val_path )
940+ val_out = strip_meta (val )
941+ if isinstance (val , Namespace ):
942+ val_out = val_out .as_dict ()
943+ if "__orig__" in val :
944+ val_str = val ["__orig__" ]
945+ else :
946+ is_json = str (val_path ).lower ().endswith (".json" )
947+ val_str = dump_using_format (self , val_out , "json_indented" if is_json else format )
948+ with open (val_path .absolute , "w" ) as f :
949+ f .write (val_str )
950+ return os .path .basename (val_path )
951+
933952 def save_paths (cfg ):
934953 for key in cfg .get_sorted_keys ():
935954 val = cfg [key ]
936955 if isinstance (val , (Namespace , dict )) and "__path__" in val :
937- action = _find_action (self , key )
938- if isinstance (action , (ActionJsonSchema , ActionJsonnet , ActionTypeHint , _ActionConfigLoad )):
939- val_path = Path (os .path .basename (val ["__path__" ].absolute ), mode = "fc" )
940- check_overwrite (val_path )
941- val_out = strip_meta (val )
942- if isinstance (val , Namespace ):
943- val_out = val_out .as_dict ()
944- if "__orig__" in val :
945- val_str = val ["__orig__" ]
946- else :
947- is_json = str (val_path ).lower ().endswith (".json" )
948- val_str = dump_using_format (self , val_out , "json_indented" if is_json else format )
949- with open (val_path .absolute , "w" ) as f :
950- f .write (val_str )
951- cfg [key ] = os .path .basename (val_path .absolute )
956+ if is_path_action (key ):
957+ cfg [key ] = save_path (val )
958+ elif isinstance (val , list ):
959+ if is_path_action (key ):
960+ for num , item in enumerate (val ):
961+ if isinstance (item , (Namespace , dict )) and "__path__" in item :
962+ val [num ] = save_path (item )
952963 elif isinstance (val , Path ) and key in self .save_path_content and "r" in val .mode :
953964 val_path = Path (os .path .basename (val .absolute ), mode = "fc" )
954965 check_overwrite (val_path )
@@ -1356,9 +1367,9 @@ def _apply_actions(
13561367 cfg_branch = cfg
13571368 cfg = Namespace ()
13581369 cfg [parent_key ] = cfg_branch
1359- keys = [parent_key + "." + k for k in cfg_branch .__dict__ ]
1370+ keys = [parent_key + "." + k for k in cfg_branch .keys ( branches = True , nested = False ) ]
13601371 else :
1361- keys = list (cfg .__dict__ )
1372+ keys = list (cfg .keys ( branches = True , nested = False ) )
13621373
13631374 if prev_cfg :
13641375 prev_cfg = prev_cfg .clone ()
@@ -1385,7 +1396,7 @@ def _apply_actions(
13851396 if isinstance (value , dict ):
13861397 value = Namespace (value )
13871398 if isinstance (value , Namespace ):
1388- new_keys = value .__dict__ . keys ()
1399+ new_keys = value .keys (branches = True , nested = False )
13891400 keys += [key + "." + k for k in new_keys if key + "." + k not in keys ]
13901401 cfg [key ] = value
13911402 continue
0 commit comments