summaryrefslogtreecommitdiffstats
path: root/Tools/scripts
diff options
context:
space:
mode:
authorBrett Cannon <brettcannon@users.noreply.github.com>2017-06-24 23:51:23 (GMT)
committerGitHub <noreply@github.com>2017-06-24 23:51:23 (GMT)
commit70cb1875bb5343e31d7268f4b2d231a5fecdf989 (patch)
tree99e32d498812ed6b6056024e9fe72c16562e7f65 /Tools/scripts
parent13e96cc596d158b98996db3fa291086ea4afecd9 (diff)
downloadcpython-70cb1875bb5343e31d7268f4b2d231a5fecdf989.zip
cpython-70cb1875bb5343e31d7268f4b2d231a5fecdf989.tar.gz
cpython-70cb1875bb5343e31d7268f4b2d231a5fecdf989.tar.bz2
Check the whitespace of pull requests on Travis (GH-2367)
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-xTools/scripts/patchcheck.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py
index 33a9fea..436b277 100755
--- a/Tools/scripts/patchcheck.py
+++ b/Tools/scripts/patchcheck.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
+"""Check proposed changes for common issues."""
import re
import sys
import shutil
@@ -135,7 +136,7 @@ def report_modified_files(file_paths):
return "\n".join(lines)
-@status("Fixing whitespace", info=report_modified_files)
+@status("Fixing Python file whitespace", info=report_modified_files)
def normalize_whitespace(file_paths):
"""Make sure that the whitespace for .py files have been normalized."""
reindent.makebackup = False # No need to create backups.
@@ -212,6 +213,27 @@ def regenerated_pyconfig_h_in(file_paths):
else:
return "not needed"
+def travis(pull_request):
+ if pull_request == 'false':
+ print('Not a pull request; skipping')
+ return
+ base_branch = get_base_branch()
+ file_paths = changed_files(base_branch)
+ python_files = [fn for fn in file_paths if fn.endswith('.py')]
+ c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]
+ doc_files = [fn for fn in file_paths if fn.startswith('Doc') and
+ fn.endswith(('.rst', '.inc'))]
+ fixed = []
+ fixed.extend(normalize_whitespace(python_files))
+ fixed.extend(normalize_c_whitespace(c_files))
+ fixed.extend(normalize_docs_whitespace(doc_files))
+ if not fixed:
+ print('No whitespace issues found')
+ else:
+ print(f'Please fix the {len(fixed)} file(s) with whitespace issues')
+ print('(on UNIX you can run `make patchcheck` to make the fixes)')
+ sys.exit(1)
+
def main():
base_branch = get_base_branch()
file_paths = changed_files(base_branch)
@@ -246,4 +268,12 @@ def main():
if __name__ == '__main__':
- main()
+ import argparse
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--travis',
+ help='Perform pass/fail checks')
+ args = parser.parse_args()
+ if args.travis:
+ travis(args.travis)
+ else:
+ main()