diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py --- a/Tools/scripts/patchcheck.py +++ b/Tools/scripts/patchcheck.py @@ -47,10 +47,26 @@ def changed_files(): @status("Fixing whitespace", info=lambda x: "%s files" % x) def normalize_whitespace(file_paths): """Make sure that the whitespace for .py files have been normalized.""" + pyfiles = (x for x in file_paths if x.endswith('.py')) reindent.makebackup = False # No need to create backups. - result = list(map(reindent.check, (x for x in file_paths if x.endswith('.py')))) + result = list(map(reindent.check, pyfiles)) return sum(result) +@status("Checking whitespace and line length in C files, ACKS and NEWS", + info=lambda x: "%s files" % x) +def check_pep7(file_paths): + """Report tabs, trailing whitespace and long lines in .[ch], ACKS, NEWS.""" + files = (x for x in file_paths + if x.endswith(('.c', '.h')) or x in ('Misc/ACKS', 'Misc/NEWS')) + result = 0 + for filename in files: + with open(filename) as fp: + for line in fp: + if '\t' in line or line[-1].isspace() or len(line) > 79: + result += 1 + break + return result + @status("Docs modified", modal=True) def docs_modified(file_paths): """Report if any files in the Docs directory.""" @@ -74,6 +90,7 @@ def main(): file_paths = changed_files() # PEP 7/8 verification. normalize_whitespace(file_paths) + check_pep7(file_paths) # Docs updated. docs_modified(file_paths) # Misc/ACKS changed.