Skip to content

Commit 07e51c6

Browse files
committed
Update linters
1 parent 4dae3d6 commit 07e51c6

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[flake8]
2-
exclude = tests/
2+
exclude = .anaconda3/, tests/
3+
ignore =

generate_readme.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,69 @@
1010

1111
def get_section(title, data, h=2):
1212
if not isinstance(data, list):
13-
content = '%s %s\n\n' % ('#' * h, title.capitalize())
13+
content = "%s %s\n\n" % ("#" * h, title.capitalize())
1414
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)
1616
return content
1717

18-
headers = ['Numpy', 'PyTorch']
19-
keys = ['numpy', 'pytorch']
18+
headers = ["Numpy", "PyTorch"]
19+
keys = ["numpy", "pytorch"]
2020
rows = []
2121
for d in data:
2222
row = []
2323
for key in keys:
2424
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)
2727
elif d[key] is None:
28-
content = ''
28+
content = ""
2929
is_code = False
3030
else:
3131
content = d[key]
3232
is_code = True
3333
if is_code and content:
3434
if len(content.splitlines()) > 1:
35-
content = '<pre>\n{}</pre>'.format(content)
35+
content = "<pre>\n{}</pre>".format(content)
3636
else:
37-
content = '<code>{}</code>'.format(content)
37+
content = "<code>{}</code>".format(content)
3838
row.append(content)
3939
rows.append(row)
4040

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"
4444
return content
4545

4646

4747
def get_contents():
4848
# keep order in yaml file
4949
yaml.add_constructor(
5050
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+
),
5354
)
5455

55-
yaml_file = osp.join(here, 'conversions.yaml')
56+
yaml_file = osp.join(here, "conversions.yaml")
5657
with open(yaml_file) as f:
5758
data = yaml.load(f)
5859
contents = []
5960
for title, data in data.items():
6061
section = get_section(title, data)
6162
contents.append(section)
62-
return '\n'.join(contents)
63+
return "\n".join(contents)
6364

6465

6566
here = osp.dirname(osp.abspath(__file__))
6667

6768

6869
def main():
69-
with open(osp.join(here, 'README.md.in')) as f:
70+
with open(osp.join(here, "README.md.in")) as f:
7071
template = f.read()
7172
template = string.Template(template)
7273
readme = template.substitute(contents=get_contents())
7374
print(readme)
7475

7576

76-
if __name__ == '__main__':
77+
if __name__ == "__main__":
7778
main()

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.black]
2+
line-length = 79
3+
exclude = '''
4+
(
5+
^/\..*
6+
| ^/docs/
7+
| ^/github2pypi/
8+
)
9+
'''

run_tests.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def parse(data):
2020
for key in item:
2121
item_k = item[key]
2222
if isinstance(item_k, dict):
23-
content = item_k['content']
24-
is_code = item_k.get('is_code', True)
25-
if item_k.get('skip_test', False):
23+
content = item_k["content"]
24+
is_code = item_k.get("is_code", True)
25+
if item_k.get("skip_test", False):
2626
continue
2727
else:
2828
content = item_k
@@ -34,47 +34,47 @@ def parse(data):
3434
def main():
3535
here = osp.dirname(osp.abspath(__file__))
3636

37-
with open(osp.join(here, 'conversions.yaml')) as f:
37+
with open(osp.join(here, "conversions.yaml")) as f:
3838
data = yaml.load(f)
3939

40-
for fname in glob.glob(osp.join(here, 'tests/*.py')):
40+
for fname in glob.glob(osp.join(here, "tests/*.py")):
4141
os.remove(fname)
4242

4343
for i, (key, content) in enumerate(parse(data)):
44-
if key == 'numpy':
45-
code = '''\
44+
if key == "numpy":
45+
code = """\
4646
import numpy as np
4747
4848
4949
def test_{key}_{id:04d}():
5050
x = np.array([[1, 2, 3], [4, 5, 6]])
5151
{content}
52-
'''
53-
elif key == 'pytorch':
54-
code = '''\
52+
"""
53+
elif key == "pytorch":
54+
code = """\
5555
import torch
5656
5757
5858
def test_{key}_{id:04d}():
5959
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
6060
{content}
61-
'''
61+
"""
6262
else:
6363
raise ValueError
6464

65-
content = '\n'.join(' ' * 4 + l for l in content.splitlines())
65+
content = "\n".join(" " * 4 + l for l in content.splitlines())
6666
code = code.format(key=key, id=i, content=content)
6767

6868
test_file = osp.join(
69-
here, 'tests/test_{key}_{id:04d}.py'.format(key=key, id=i)
69+
here, "tests/test_{key}_{id:04d}.py".format(key=key, id=i)
7070
)
71-
with open(test_file, 'w') as f:
71+
with open(test_file, "w") as f:
7272
f.write(code)
7373

74-
cmd = 'pytest -vs tests'
75-
print('+ %s' % cmd)
74+
cmd = "pytest -vs tests"
75+
print("+ %s" % cmd)
7676
subprocess.call(cmd, shell=True)
7777

7878

79-
if __name__ == '__main__':
79+
if __name__ == "__main__":
8080
main()

0 commit comments

Comments
 (0)