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

Unified Diff: presubmit_canned_checks.py

Issue 5695007: Enhance RunPylint to use white_list and black_list arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: address review comment 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') | pylintrc » ('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 c7c93be6ca5b484d5b70e99a1479bffc73a01d2d..51dfcff37e40cf1ebeff077845fb3b541485675b 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -450,17 +450,48 @@ 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
+def RunPylint(input_api, output_api, white_list=None, black_list=None):
+ """Run pylint on python files.
+
+ The default white_list enforces looking only a *.py files.
+ """
+ white_list = white_list or ['.*\.py$']
+ black_list = black_list or input_api.DEFAULT_BLACK_LIST
+
+ # Only trigger if there is at least one python file affected.
+ src_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
+ if not input_api.AffectedSourceFiles(src_filter):
+ return []
+
# On certain pylint/python version combination, running pylint throws a lot of
# warning messages.
+ import warnings
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)]
+ # We cannot use AffectedFiles here because we want to test every python
+ # file on each single python change. It's because a change in a python file
+ # can break another unmodified file.
+ # Use code similar to InputApi.FilterSourceFile()
+ def Find(filepath, filters):
+ for item in filters:
+ if input_api.re.match(item, filepath):
+ return True
+ return False
+
+ import os
+ files = []
+ for dirpath, dirnames, filenames in os.walk(input_api.PresubmitLocalPath()):
+ # Passes dirnames in black list to speed up search.
+ for item in dirnames[:]:
+ if Find(input_api.os_path.join(dirpath, item), black_list):
+ dirnames.remove(item)
+ for item in filenames:
+ filepath = input_api.os_path.join(dirpath, item)
+ if Find(filepath, white_list) and not Find(filepath, black_list):
+ files.append(filepath)
+
+ # Now that at least one python file was modified and all the python files
+ # were listed, try to run pylint.
try:
from pylint import lint
if lint.Run(sorted(files)):
« no previous file with comments | « PRESUBMIT.py ('k') | pylintrc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698