Commit 0ae14e9a authored by Nodir Turakulov's avatar Nodir Turakulov Committed by Commit Bot

[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 <nodir@chromium.org>
Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
parent af43f40e
......@@ -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 []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment