1616
1717import logging
1818from dataclasses import dataclass , field
19- from typing import Any
19+ from typing import Any , Dict , List
2020from urllib .parse import urlparse
2121
2222
@@ -37,7 +37,7 @@ class Metadata:
3737 langs : list [str ] = field (default_factory = lambda : ["cpp" , "rust" ])
3838
3939 @classmethod
40- def from_dict (cls , data : dict [str , Any ]) -> Metadata :
40+ def from_dict (cls , data : Dict [str , Any ]) -> Metadata :
4141 """Create a Metadata instance from a dictionary.
4242
4343 Args:
@@ -53,7 +53,7 @@ def from_dict(cls, data: dict[str, Any]) -> Metadata:
5353 langs = data .get ("langs" , ["cpp" , "rust" ]),
5454 )
5555
56- def to_dict (self ) -> dict [str , Any ]:
56+ def to_dict (self ) -> Dict [str , Any ]:
5757 """Convert Metadata instance to dictionary representation.
5858
5959 Returns:
@@ -79,30 +79,30 @@ class Module:
7979 pin_version : bool = False
8080
8181 @classmethod
82- def from_dict (cls , name : str , module_data : dict [str , Any ]) -> Module :
82+ def from_dict (cls , name : str , module_data : Dict [str , Any ]) -> Module :
8383 """Create a Module instance from a dictionary representation.
8484
8585 Args:
86- name: The module name
87- module_data: Dictionary containing module configuration with keys:
88- - repo (str): Repository URL
89- - hash or commit (str): Commit hash
90- - version (str, optional): Module version (when present, hash is ignored)
91- - bazel_patches (list[str], optional): List of patch files for Bazel
92- - metadata (dict, optional): Metadata configuration
93- Example: {
94- "code_root_path": "path/to/code/root",
95- "extra_test_config": [""],
96- "exclude_test_targets": [""],
97- "langs": ["cpp", "rust"]
98- }
99- If not present, uses default Metadata values.
100- - branch (str, optional): Git branch name (default: main)
101- - pin_version (bool, optional): If true, module hash is not updated
102- to latest HEAD by update scripts (default: false)
86+ name: The module name
87+ module_data: Dictionary containing module configuration with keys:
88+ - repo (str): Repository URL
89+ - hash or commit (str): Commit hash
90+ - version (str, optional): Module version (when present, hash is ignored)
91+ - bazel_patches (list[str], optional): List of patch files for Bazel
92+ - metadata (dict, optional): Metadata configuration
93+ Example: {
94+ "code_root_path": "path/to/code/root",
95+ "extra_test_config": [""],
96+ "exclude_test_targets": [""],
97+ "langs": ["cpp", "rust"]
98+ }
99+ If not present, uses default Metadata values.
100+ - branch (str, optional): Git branch name (default: main)
101+ - pin_version (bool, optional): If true, module hash is not updated
102+ to latest HEAD by update scripts (default: false)
103103
104104 Returns:
105- Module instance
105+ Module instance
106106 """
107107 repo = module_data .get ("repo" , "" )
108108 # Support both 'hash' and 'commit' keys
@@ -119,14 +119,17 @@ def from_dict(cls, name: str, module_data: dict[str, Any]) -> Module:
119119
120120 # Parse metadata - if not present or is None/empty dict, use defaults
121121 metadata_data = module_data .get ("metadata" )
122- metadata = Metadata .from_dict (metadata_data ) if metadata_data is not None else Metadata ()
123-
124- # Enable once we are able to remove '*' in known_good.json
125- # if any("*" in target for target in metadata.exclude_test_targets):
126- # raise Exception(
127- # f"Module {name} has wildcard '*' in exclude_test_targets, which is not allowed. "
128- # "Please specify explicit test targets to exclude or remove the key if no exclusions are needed."
129- # )
122+ if metadata_data is not None :
123+ metadata = Metadata .from_dict (metadata_data )
124+ # Enable once we are able to remove '*' in known_good.json
125+ # if any("*" in target for target in metadata.exclude_test_targets):
126+ # raise Exception(
127+ # f"Module {name} has wildcard '*' in exclude_test_targets, which is not allowed. "
128+ # "Please specify explicit test targets to exclude or remove the key if no exclusions are needed."
129+ # )
130+ else :
131+ # If metadata key is missing, create with defaults
132+ metadata = Metadata ()
130133
131134 branch = module_data .get ("branch" , "main" )
132135 pin_version = module_data .get ("pin_version" , False )
@@ -143,7 +146,7 @@ def from_dict(cls, name: str, module_data: dict[str, Any]) -> Module:
143146 )
144147
145148 @classmethod
146- def parse_modules (cls , modules_dict : dict [str , Any ]) -> list [Module ]:
149+ def parse_modules (cls , modules_dict : Dict [str , Any ]) -> List [Module ]:
147150 """Parse modules dictionary into Module dataclass instances.
148151
149152 Args:
@@ -184,13 +187,13 @@ def owner_repo(self) -> str:
184187
185188 return f"{ parts [0 ]} /{ parts [1 ]} "
186189
187- def to_dict (self ) -> dict [str , Any ]:
190+ def to_dict (self ) -> Dict [str , Any ]:
188191 """Convert Module instance to dictionary representation for JSON output.
189192
190193 Returns:
191194 Dictionary with module configuration
192195 """
193- result : dict [str , Any ] = {"repo" : self .repo }
196+ result : Dict [str , Any ] = {"repo" : self .repo }
194197 if self .version :
195198 result ["version" ] = self .version
196199 else :
0 commit comments