@@ -95,6 +95,18 @@ def parse_args() -> argparse.Namespace:
9595 return parser .parse_args ()
9696
9797
98+ def deep_merge_dicts (base : dict [str , Any ], new : dict [str , Any ]) -> dict [str , Any ]:
99+ """
100+ Merge two dictionaries recursively.
101+ """
102+ for key , value in new .items ():
103+ if isinstance (value , dict ) and isinstance (base .get (key ), dict ):
104+ base [key ] = deep_merge_dicts (base [key ], value )
105+ else :
106+ base [key ] = value
107+ return base
108+
109+
98110def load_config (config_path : str ) -> dict [str , Any ]:
99111 """
100112 Loads the YAML configuration file and returns it as a dictionary.
@@ -106,9 +118,19 @@ def load_config(config_path: str) -> dict[str, Any]:
106118 dict[str, Any]: Parsed YAML configuration
107119 """
108120 with open (config_path , "r" , encoding = "utf-8" ) as f :
109- config = yaml .safe_load (f )
110- if not isinstance (config , dict ):
111- raise ValueError ("Invalid YAML configuration format." )
121+ config = yaml .safe_load (f ) or {}
122+
123+ includes = config .pop ("include" , [])
124+ if not isinstance (includes , list ):
125+ raise ValueError ("'include' must be a list of file paths." )
126+
127+ for inc_path in includes :
128+ inc_abs_path = os .path .join (os .path .dirname (config_path ), inc_path )
129+ if os .path .exists (inc_abs_path ):
130+ with open (inc_abs_path , "r" , encoding = "utf-8" ) as f :
131+ sub_config = yaml .safe_load (f ) or {}
132+ config = deep_merge_dicts (config , sub_config )
133+
112134 return config
113135
114136
0 commit comments