@@ -107,25 +107,7 @@ def _load_all_dependencies(self) -> dict:
107107 self ._validate_descriptor (descriptor )
108108 downstream_node = (instrument , data_type , descriptor )
109109
110- # Flatten upstream dependencies because of how YAML aliases are
111- # loaded in code. New YAML format loads dependencies as dicts:
112- # (l1a, all):
113- # - source: hi
114- # data_type: l0
115- # descriptor: raw
116- # - *spice_basic # YAML alias expands to list of dicts
117- # When aliased, it may be read as list of lists of dicts.
118- flattened_upstream_deps = []
119- for item in upstream_list :
120- # Handle YAML aliases that expand to list of dicts
121- if (
122- isinstance (item , list )
123- and item
124- and isinstance (item [0 ], dict )
125- ):
126- flattened_upstream_deps .extend (item )
127- else :
128- flattened_upstream_deps .append (item )
110+ flattened_upstream_deps = self .recursive_flatten_list (upstream_list )
129111
130112 # Validate each upstream node
131113 for upstream in flattened_upstream_deps :
@@ -140,6 +122,56 @@ def _load_all_dependencies(self) -> dict:
140122
141123 return dependencies
142124
125+ def recursive_flatten_list (self , nested_list ):
126+ """Recursively flatten a nested list structure.
127+
128+ Multiple inheritance in dependency YAML files can result in
129+ lists containing other lists, which this method flattens.
130+
131+ For example:
132+ spice_basic: &spice_basic
133+ - upstream_source: leapseconds
134+ upstream_data_type: spice
135+ upstream_descriptor: historical
136+ kickoff_job: false
137+ - upstream_source: spacecraft_clock
138+ upstream_data_type: spice
139+ upstream_descriptor: historical
140+ kickoff_job: false
141+
142+ spice_45sensor_l1b: &spice_45sensor_l1b
143+ - *spice_basic
144+ - upstream_source: imap_frames
145+ upstream_data_type: spice
146+ upstream_descriptor: historical
147+ kickoff_job: false
148+
149+ (l1b, 45sensor-de):
150+ - *spice_45sensor_l1b
151+ - upstream_source: hi
152+ upstream_data_type: l1a
153+ upstream_descriptor: 45sensor-de
154+
155+ Parameters
156+ ----------
157+ nested_list : list
158+ A potentially nested list of dependencies.
159+
160+ Returns
161+ -------
162+ list
163+ A single flattened list of dependencies.
164+ """
165+ flat_list = []
166+ for item in nested_list :
167+ if isinstance (item , list ):
168+ # If the item is a list, extend with the flattened version of that list
169+ flat_list .extend (self .recursive_flatten_list (item ))
170+ else :
171+ # Otherwise, append the item (which can be any object)
172+ flat_list .append (item )
173+ return flat_list
174+
143175 def validate_node (self , node : list ) -> bool :
144176 """Validate a dependency node.
145177
0 commit comments