Chromium Code Reviews| Index: presubmit_canned_checks.py |
| diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py |
| index 2dec66b4a52406bb9759c7611431e7cde100062d..72ae189cb93b3a25e993b41fa0af4bfccec893a9 100644 |
| --- a/presubmit_canned_checks.py |
| +++ b/presubmit_canned_checks.py |
| @@ -450,6 +450,40 @@ def RunPythonUnitTests(input_api, output_api, unit_tests): |
| return [] |
| +def RunPylint(input_api, output_api, source_file_filter=None): |
| + """Run pylint on python files.""" |
| + import warnings |
| + # On certain pylint/python version combination, running pylint throws a lot of |
| + # warnings messages. |
|
Evan Martin
2010/12/13 20:54:10
typo: warning (no s)
|
| + warnings.filterwarnings('ignore', category=DeprecationWarning) |
| + try: |
| + if not source_file_filter: |
| + source_file_filter = lambda f: f.LocalPath().endswith('.py') |
| + files = [f.LocalPath() |
| + for f in input_api.AffectedSourceFiles(source_file_filter)] |
| + else: |
| + files = [f.LocalPath() |
| + for f in input_api.AffectedFiles() |
| + if source_file_filter(f)] |
|
Evan Martin
2010/12/13 20:54:10
Do you know why this can't share code with the abo
|
| + try: |
| + from pylint import lint |
| + if lint.Run(sorted(files)): |
| + return [output_api.PresubmitPromptWarning('Fix pylint errors first.')] |
| + return [] |
| + except ImportError: |
| + if input_api.platform == 'win32': |
| + return [output_api.PresubmitNotifyResult( |
| + 'Warning: Can\'t run pylint because it is not installed. Please ' |
| + 'install manually\n' |
| + 'Cannot do static analysis of python files.')] |
| + return [output_api.PresubmitError( |
| + 'Please install pylint with "sudo apt-get install python-setuptools; ' |
| + 'sudo easy_install pylint"\n' |
| + 'Cannot do static analysis of python files.')] |
| + finally: |
| + warnings.filterwarnings('default', category=DeprecationWarning) |
| + |
| + |
| def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, |
| owner): |
| if not input_api.is_committing: |