-
Notifications
You must be signed in to change notification settings - Fork 735
Expand file tree
/
Copy pathtest_codespell.py
More file actions
72 lines (59 loc) · 2.26 KB
/
test_codespell.py
File metadata and controls
72 lines (59 loc) · 2.26 KB
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
68
69
70
71
72
import pymupdf
import os
import platform
import shlex
import subprocess
import sys
import textwrap
def test_codespell():
'''
Check Python code with codespell.
'''
if os.environ.get('PYODIDE_ROOT'):
print('test_codespell(): not running on Pyodide - cannot run child processes.')
return
if platform.system() == 'Windows':
# Git commands seem to fail on Github Windows runners.
print(f'test_codespell(): Not running on Windows')
return
root = os.path.abspath(f'{__file__}/../..')
# For now we ignore files that we would ideally still look at, because it
# is difficult to exclude some text sections.
skips = textwrap.dedent('''
*.pdf
docs/_static/prism/prism.js
docs/_static/prism/prism.js
docs/locales/ja/LC_MESSAGES/changes.po
docs/locales/ja/LC_MESSAGES/recipes-common-issues-and-their-solutions.po
docs/locales/
src_classic/*
''')
skips = skips.strip().replace('\n', ',')
command = textwrap.dedent(f'''
cd {root} && codespell
--skip {shlex.quote(skips)}
--ignore-words-list re-use,flate,thirdparty,re-using
--ignore-regex 'https?://[a-z0-9/_.]+'
--ignore-multiline-regex 'codespell:ignore-begin.*codespell:ignore-end'
''')
import pipcl
git_files = pipcl.git_items(root)
command_args_path = os.path.normpath(f'{__file__}/../test_codespell_args.txt')
command += f' @{command_args_path}'
with open(command_args_path, 'w') as f:
for p in git_files:
_, ext = os.path.splitext(p)
if ext in ('.png', '.pdf', '.jpg', '.svg'):
pass
else:
#command += f' {p}\n'
print(p, file=f)
if platform.system() != 'Windows':
command = command.replace('\n', ' \\\n')
if 0:
with open(command_args_path) as f:
command_args_path_contents = f.read()
print(f'command_args_path:{command_args_path_contents}')
print(f'Running codespell: {command}')
subprocess.run(command, shell=1, check=1)
print('test_codespell(): codespell succeeded.')