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

Unified Diff: presubmit_canned_checks.py

Issue 6004006: Fix path filtering to be on the relative path and no on the absolute path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: added 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') | presubmit_support.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 bfbf52e94220c0a3f9328932db82419874edd2be..e22912fb81ff7e97f37ff82b6b278a1c8d1ac477 100644
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -450,6 +450,34 @@ def RunPythonUnitTests(input_api, output_api, unit_tests):
return []
+def _FetchAllFiles(input_api, white_list, black_list):
+ """Hack to fetch all files."""
+ # 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 = []
+ path_len = len(input_api.PresubmitLocalPath())
+ for dirpath, dirnames, filenames in os.walk(input_api.PresubmitLocalPath()):
+ # Passes dirnames in black list to speed up search.
+ for item in dirnames[:]:
+ filepath = input_api.os_path.join(dirpath, item)[path_len + 1:]
+ if Find(filepath, black_list):
+ dirnames.remove(item)
+ for item in filenames:
+ filepath = input_api.os_path.join(dirpath, item)[path_len + 1:]
+ if Find(filepath, white_list) and not Find(filepath, black_list):
+ files.append(filepath)
+ return files
+
+
def RunPylint(input_api, output_api, white_list=None, black_list=None):
"""Run pylint on python files.
@@ -468,28 +496,9 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None):
import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)
try:
- # 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)
-
+ files = _FetchAllFiles(input_api, white_list, black_list)
+ if not files:
+ return []
# Now that at least one python file was modified and all the python files
# were listed, try to run pylint.
try:
@@ -509,7 +518,11 @@ def RunPylint(input_api, output_api, white_list=None, black_list=None):
'sudo easy_install pylint"\n'
'Cannot do static analysis of python files.')]
if result:
- return [output_api.PresubmitPromptWarning('Fix pylint errors first.')]
+ if input_api.is_committing:
+ error_type = output_api.PresubmitError
+ else:
+ error_type = output_api.PresubmitPromptWarning
+ return [error_type('Fix pylint errors first.')]
return []
finally:
warnings.filterwarnings('default', category=DeprecationWarning)
« no previous file with comments | « PRESUBMIT.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698