File: parity_table_parser.py

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (67 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from collections import namedtuple


ParityStatus = namedtuple("ParityStatus", ["has_impl_parity", "has_doc_parity"])

"""
This function expects the parity tracker Markdown file to have the following format:

```
## package1_name

API | Implementation Parity | Doc Parity
------------- | ------------- | -------------
API_Name|No|No
...

## package2_name

API | Implementation Parity | Doc Parity
------------- | ------------- | -------------
API_Name|No|No
...
```

The returned dict has the following format:

```
Dict[package_name]
    -> Dict[api_name]
        -> ParityStatus
```
"""


def parse_parity_tracker_table(file_path):
    def parse_parity_choice(str):
        if str in ["Yes", "No"]:
            return str == "Yes"
        else:
            raise RuntimeError(
                f'{str} is not a supported parity choice. The valid choices are "Yes" and "No".'
            )

    parity_tracker_dict = {}

    with open(file_path) as f:
        all_text = f.read()
        packages = all_text.split("##")
        for package in packages[1:]:
            lines = [line.strip() for line in package.split("\n") if line.strip() != ""]
            package_name = lines[0]
            if package_name in parity_tracker_dict:
                raise RuntimeError(
                    f"Duplicated package name `{package_name}` found in {file_path}"
                )
            else:
                parity_tracker_dict[package_name] = {}
            for api_status in lines[3:]:
                api_name, has_impl_parity_str, has_doc_parity_str = (
                    x.strip() for x in api_status.split("|")
                )
                parity_tracker_dict[package_name][api_name] = ParityStatus(
                    has_impl_parity=parse_parity_choice(has_impl_parity_str),
                    has_doc_parity=parse_parity_choice(has_doc_parity_str),
                )

    return parity_tracker_dict