|
1 | 1 | #!/usr/bin/env python3 |
| 2 | +"""Check proposed changes for common issues.""" |
2 | 3 | import re |
3 | 4 | import sys |
4 | 5 | import shutil |
@@ -135,7 +136,7 @@ def report_modified_files(file_paths): |
135 | 136 | return "\n".join(lines) |
136 | 137 |
|
137 | 138 |
|
138 | | -@status("Fixing whitespace", info=report_modified_files) |
| 139 | +@status("Fixing Python file whitespace", info=report_modified_files) |
139 | 140 | def normalize_whitespace(file_paths): |
140 | 141 | """Make sure that the whitespace for .py files have been normalized.""" |
141 | 142 | reindent.makebackup = False # No need to create backups. |
@@ -212,6 +213,27 @@ def regenerated_pyconfig_h_in(file_paths): |
212 | 213 | else: |
213 | 214 | return "not needed" |
214 | 215 |
|
| 216 | +def travis(pull_request): |
| 217 | + if pull_request == 'false': |
| 218 | + print('Not a pull request; skipping') |
| 219 | + return |
| 220 | + base_branch = get_base_branch() |
| 221 | + file_paths = changed_files(base_branch) |
| 222 | + python_files = [fn for fn in file_paths if fn.endswith('.py')] |
| 223 | + c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))] |
| 224 | + doc_files = [fn for fn in file_paths if fn.startswith('Doc') and |
| 225 | + fn.endswith(('.rst', '.inc'))] |
| 226 | + fixed = [] |
| 227 | + fixed.extend(normalize_whitespace(python_files)) |
| 228 | + fixed.extend(normalize_c_whitespace(c_files)) |
| 229 | + fixed.extend(normalize_docs_whitespace(doc_files)) |
| 230 | + if not fixed: |
| 231 | + print('No whitespace issues found') |
| 232 | + else: |
| 233 | + print(f'Please fix the {len(fixed)} file(s) with whitespace issues') |
| 234 | + print('(on UNIX you can run `make patchcheck` to make the fixes)') |
| 235 | + sys.exit(1) |
| 236 | + |
215 | 237 | def main(): |
216 | 238 | base_branch = get_base_branch() |
217 | 239 | file_paths = changed_files(base_branch) |
@@ -246,4 +268,12 @@ def main(): |
246 | 268 |
|
247 | 269 |
|
248 | 270 | if __name__ == '__main__': |
249 | | - main() |
| 271 | + import argparse |
| 272 | + parser = argparse.ArgumentParser(description=__doc__) |
| 273 | + parser.add_argument('--travis', |
| 274 | + help='Perform pass/fail checks') |
| 275 | + args = parser.parse_args() |
| 276 | + if args.travis: |
| 277 | + travis(args.travis) |
| 278 | + else: |
| 279 | + main() |
0 commit comments