66import os .path
77import subprocess
88import sysconfig
9+ from pathlib import Path
910
1011import reindent
1112import untabify
1415# Excluded directories which are copies of external libraries:
1516# don't check their coding style
1617EXCLUDE_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+ ]
2122SRCDIR = 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+
162174def 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 )
180201def 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