From 0ae14e9aad83c1387df8dd565cce3748fce3dec7 Mon Sep 17 00:00:00 2001 From: Nodir Turakulov Date: Thu, 31 May 2018 14:53:53 -0700 Subject: [PATCH] [presubmit] Add python formatting check Add check_python parameter to CheckPatchFormatted to check that python files are well formatted. Change-Id: Ibd20d5ec9d1d5142a26f7f4cd5f05c51223da6ca Reviewed-on: https://chromium-review.googlesource.com/1081342 Commit-Queue: Nodir Turakulov Reviewed-by: Andrii Shyshkalov --- presubmit_canned_checks.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 946d7739d..fb7e6c0ea 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1055,12 +1055,19 @@ def PanProjectChecks(input_api, output_api, return results -def CheckPatchFormatted(input_api, output_api, check_js=False): +def CheckPatchFormatted( + input_api, output_api, check_js=False, check_python=False): import git_cl - cmd = ['-C', input_api.change.RepositoryRoot(), - 'cl', 'format', '--dry-run', '--presubmit'] + + display_args = [] if check_js: - cmd.append('--js') + display_args.append('--js') + if check_python: + # --python requires --full + display_args.extend(['--python', '--full']) + + cmd = ['-C', input_api.change.RepositoryRoot(), + 'cl', 'format', '--dry-run', '--presubmit'] + display_args presubmit_subdir = input_api.os_path.relpath( input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()) if presubmit_subdir.startswith('..') or presubmit_subdir == '.': @@ -1076,10 +1083,11 @@ def CheckPatchFormatted(input_api, output_api, check_js=False): short_path = presubmit_subdir else: short_path = input_api.basename(input_api.change.RepositoryRoot()) + display_args.append(presubmit_subdir) return [output_api.PresubmitPromptWarning( 'The %s directory requires source formatting. ' - 'Please run: git cl format %s%s' % - (short_path, '--js ' if check_js else '', presubmit_subdir))] + 'Please run: git cl format %s' % + (short_path, ' '.join(display_args)))] # As this is just a warning, ignore all other errors if the user # happens to have a broken clang-format, doesn't use git, etc etc. return []