Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: presubmit_canned_checks.py

Issue 5682011: Add RunPylint as a canned presubmit check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Addressed review comments Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index 2dec66b4a52406bb9759c7611431e7cde100062d..c7c93be6ca5b484d5b70e99a1479bffc73a01d2d 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -450,6 +450,36 @@ 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
+ # warning messages.
+ 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)]
+ 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:
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698