Skip to content

Commit 5ad4faf

Browse files
committed
Run patchcheck in GitHub Actions
1 parent 8ea4ad4 commit 5ad4faf

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

.github/workflows/lint.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ jobs:
2424
with:
2525
python-version: "3.x"
2626
- uses: pre-commit/[email protected]
27+
28+
patchcheck:
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 10
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
show-progress: false
36+
- uses: actions/setup-python@v4
37+
with:
38+
python-version: "3.x"
39+
- name: "Run patchcheck.py"
40+
run: python ./Tools/patchcheck/patchcheck.py --ci true

Tools/patchcheck/patchcheck.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os.path
77
import subprocess
88
import sysconfig
9+
from pathlib import Path
910

1011
import reindent
1112
import untabify
@@ -14,10 +15,10 @@
1415
# Excluded directories which are copies of external libraries:
1516
# don't check their coding style
1617
EXCLUDE_DIRS = [
17-
os.path.join('Modules', '_decimal', 'libmpdec'),
18-
os.path.join('Modules', 'expat'),
19-
os.path.join('Modules', 'zlib'),
20-
]
18+
'Modules/_decimal/libmpdec',
19+
'Modules/expat',
20+
'Modules/zlib',
21+
]
2122
SRCDIR = sysconfig.get_config_var('srcdir')
2223

2324

@@ -159,6 +160,17 @@ def changed_files(base_branch=None):
159160
return filenames2
160161

161162

163+
@status("Getting the list of all files",
164+
info=lambda x: n_files_str(len(x)))
165+
def all_files():
166+
return [
167+
file for path in Path(SRCDIR).rglob("*")
168+
if (file := path.resolve().relative_to(SRCDIR).as_posix())
169+
and not any(file.startswith(path) for path in EXCLUDE_DIRS)
170+
]
171+
172+
173+
162174
def report_modified_files(file_paths):
163175
count = len(file_paths)
164176
if count == 0:
@@ -175,6 +187,15 @@ def report_modified_files(file_paths):
175187
'Tools/c-analyzer/cpython/_parser.py',
176188
})
177189

190+
#: Python files with bad syntax
191+
_PYTHON_SYNTAX_PROBLEMS = frozenset({
192+
'Lib/test/tokenizedata/bad_coding.py',
193+
'Lib/test/tokenizedata/bad_coding2.py',
194+
'Lib/test/tokenizedata/badsyntax_3131.py',
195+
'Lib/test/tokenizedata/coding20731.py',
196+
'Lib/test/badsyntax_pep3120.py'
197+
})
198+
178199

179200
@status("Fixing Python file whitespace", info=report_modified_files)
180201
def normalize_whitespace(file_paths):
@@ -184,7 +205,7 @@ def normalize_whitespace(file_paths):
184205
path for path in file_paths
185206
if (
186207
path.endswith('.py')
187-
and path not in _PYTHON_FILES_WITH_TABS
208+
and path not in _PYTHON_FILES_WITH_TABS | _PYTHON_SYNTAX_PROBLEMS
188209
and reindent.check(os.path.join(SRCDIR, path))
189210
)
190211
]
@@ -264,8 +285,7 @@ def ci(pull_request):
264285
if pull_request == 'false':
265286
print('Not a pull request; skipping')
266287
return
267-
base_branch = get_base_branch()
268-
file_paths = changed_files(base_branch)
288+
file_paths = all_files()
269289
python_files = [fn for fn in file_paths if fn.endswith('.py')]
270290
c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]
271291
doc_files = [fn for fn in file_paths if fn.startswith('Doc') and
@@ -320,6 +340,7 @@ def main():
320340
help='Perform pass/fail checks')
321341
args = parser.parse_args()
322342
if args.ci:
343+
SRCDIR = Path(__file__).resolve().parents[2].as_posix()
323344
ci(args.ci)
324345
else:
325346
main()

0 commit comments

Comments
 (0)