Normalize submodule declarations from YAML data to a standard format.
(
yaml_data: Dict[str, Any],
yaml_file_path: str,
)
| 7 | |
| 8 | |
| 9 | def normalize_submodule_declarations( |
| 10 | yaml_data: Dict[str, Any], |
| 11 | yaml_file_path: str, |
| 12 | ) -> List[Dict[str, Any]]: |
| 13 | """Normalize submodule declarations from YAML data to a standard format.""" |
| 14 | submodules = yaml_data.get("submodules", []) |
| 15 | if not submodules: |
| 16 | return [] |
| 17 | if isinstance(submodules, dict): |
| 18 | submodules = [{"name": name, "path": path} for name, path in submodules.items()] |
| 19 | if not isinstance(submodules, list): |
| 20 | raise ValueError("submodules must be a list or mapping") |
| 21 | |
| 22 | base_dir = Path(yaml_file_path).resolve().parent |
| 23 | normalized = [] |
| 24 | for entry in submodules: |
| 25 | if isinstance(entry, str): |
| 26 | entry = {"path": entry} |
| 27 | if not isinstance(entry, dict): |
| 28 | raise ValueError("Each submodule entry must be a mapping or string path") |
| 29 | name = entry.get("name") |
| 30 | path = entry.get("path") or entry.get("file") or entry.get("filepath") |
| 31 | if not path: |
| 32 | raise ValueError("Submodule entry must include a file path") |
| 33 | module_path = ( |
| 34 | str((base_dir / path).resolve()) if not os.path.isabs(path) else path |
| 35 | ) |
| 36 | normalized.append({"name": name, "path": module_path}) |
| 37 | return normalized |
| 38 | |
| 39 | |
| 40 | def parse_submodule_function_declaration( |