1from collections import namedtuple 2 3 4ParityStatus = namedtuple("ParityStatus", ["has_impl_parity", "has_doc_parity"]) 5 6""" 7This function expects the parity tracker Markdown file to have the following format: 8 9``` 10## package1_name 11 12API | Implementation Parity | Doc Parity 13------------- | ------------- | ------------- 14API_Name|No|No 15... 16 17## package2_name 18 19API | Implementation Parity | Doc Parity 20------------- | ------------- | ------------- 21API_Name|No|No 22... 23``` 24 25The returned dict has the following format: 26 27``` 28Dict[package_name] 29 -> Dict[api_name] 30 -> ParityStatus 31``` 32""" 33 34 35def parse_parity_tracker_table(file_path): 36 def parse_parity_choice(str): 37 if str in ["Yes", "No"]: 38 return str == "Yes" 39 else: 40 raise RuntimeError( 41 f'{str} is not a supported parity choice. The valid choices are "Yes" and "No".' 42 ) 43 44 parity_tracker_dict = {} 45 46 with open(file_path) as f: 47 all_text = f.read() 48 packages = all_text.split("##") 49 for package in packages[1:]: 50 lines = [line.strip() for line in package.split("\n") if line.strip() != ""] 51 package_name = lines[0] 52 if package_name in parity_tracker_dict: 53 raise RuntimeError( 54 f"Duplicated package name `{package_name}` found in {file_path}" 55 ) 56 else: 57 parity_tracker_dict[package_name] = {} 58 for api_status in lines[3:]: 59 api_name, has_impl_parity_str, has_doc_parity_str = ( 60 x.strip() for x in api_status.split("|") 61 ) 62 parity_tracker_dict[package_name][api_name] = ParityStatus( 63 has_impl_parity=parse_parity_choice(has_impl_parity_str), 64 has_doc_parity=parse_parity_choice(has_doc_parity_str), 65 ) 66 67 return parity_tracker_dict 68