|
10 | 10 |
|
11 | 11 | def get_section(title, data, h=2): |
12 | 12 | if not isinstance(data, list): |
13 | | - content = '%s %s\n\n' % ('#' * h, title.capitalize()) |
| 13 | + content = "%s %s\n\n" % ("#" * h, title.capitalize()) |
14 | 14 | for sub_title, sub_data in data.items(): |
15 | | - content += get_section(sub_title, sub_data, h=h+1) |
| 15 | + content += get_section(sub_title, sub_data, h=h + 1) |
16 | 16 | return content |
17 | 17 |
|
18 | | - headers = ['Numpy', 'PyTorch'] |
19 | | - keys = ['numpy', 'pytorch'] |
| 18 | + headers = ["Numpy", "PyTorch"] |
| 19 | + keys = ["numpy", "pytorch"] |
20 | 20 | rows = [] |
21 | 21 | for d in data: |
22 | 22 | row = [] |
23 | 23 | for key in keys: |
24 | 24 | if isinstance(d[key], dict): |
25 | | - content = d[key]['content'] |
26 | | - is_code = d[key].get('is_code', True) |
| 25 | + content = d[key]["content"] |
| 26 | + is_code = d[key].get("is_code", True) |
27 | 27 | elif d[key] is None: |
28 | | - content = '' |
| 28 | + content = "" |
29 | 29 | is_code = False |
30 | 30 | else: |
31 | 31 | content = d[key] |
32 | 32 | is_code = True |
33 | 33 | if is_code and content: |
34 | 34 | if len(content.splitlines()) > 1: |
35 | | - content = '<pre>\n{}</pre>'.format(content) |
| 35 | + content = "<pre>\n{}</pre>".format(content) |
36 | 36 | else: |
37 | | - content = '<code>{}</code>'.format(content) |
| 37 | + content = "<code>{}</code>".format(content) |
38 | 38 | row.append(content) |
39 | 39 | rows.append(row) |
40 | 40 |
|
41 | | - content = '%s %s\n\n' % ('#' * h, title.capitalize()) |
42 | | - content += tabulate.tabulate(rows, headers=headers, tablefmt='html') |
43 | | - content += '\n\n' |
| 41 | + content = "%s %s\n\n" % ("#" * h, title.capitalize()) |
| 42 | + content += tabulate.tabulate(rows, headers=headers, tablefmt="html") |
| 43 | + content += "\n\n" |
44 | 44 | return content |
45 | 45 |
|
46 | 46 |
|
47 | 47 | def get_contents(): |
48 | 48 | # keep order in yaml file |
49 | 49 | yaml.add_constructor( |
50 | 50 | yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, |
51 | | - lambda loader, node: |
52 | | - collections.OrderedDict(loader.construct_pairs(node)), |
| 51 | + lambda loader, node: collections.OrderedDict( |
| 52 | + loader.construct_pairs(node) |
| 53 | + ), |
53 | 54 | ) |
54 | 55 |
|
55 | | - yaml_file = osp.join(here, 'conversions.yaml') |
| 56 | + yaml_file = osp.join(here, "conversions.yaml") |
56 | 57 | with open(yaml_file) as f: |
57 | 58 | data = yaml.load(f) |
58 | 59 | contents = [] |
59 | 60 | for title, data in data.items(): |
60 | 61 | section = get_section(title, data) |
61 | 62 | contents.append(section) |
62 | | - return '\n'.join(contents) |
| 63 | + return "\n".join(contents) |
63 | 64 |
|
64 | 65 |
|
65 | 66 | here = osp.dirname(osp.abspath(__file__)) |
66 | 67 |
|
67 | 68 |
|
68 | 69 | def main(): |
69 | | - with open(osp.join(here, 'README.md.in')) as f: |
| 70 | + with open(osp.join(here, "README.md.in")) as f: |
70 | 71 | template = f.read() |
71 | 72 | template = string.Template(template) |
72 | 73 | readme = template.substitute(contents=get_contents()) |
73 | 74 | print(readme) |
74 | 75 |
|
75 | 76 |
|
76 | | -if __name__ == '__main__': |
| 77 | +if __name__ == "__main__": |
77 | 78 | main() |
0 commit comments