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

Side by Side Diff: presubmit_canned_checks.py

Issue 1092313003: Enable passing custom pylintrc files to PRESUBMIT.RunPylint. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 # Justifications for each filter: 10 # Justifications for each filter:
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 if Find(filepath, black_list): 707 if Find(filepath, black_list):
708 dirnames.remove(item) 708 dirnames.remove(item)
709 for item in filenames: 709 for item in filenames:
710 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:] 710 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:]
711 if Find(filepath, white_list) and not Find(filepath, black_list): 711 if Find(filepath, white_list) and not Find(filepath, black_list):
712 files.append(filepath) 712 files.append(filepath)
713 return files 713 return files
714 714
715 715
716 def GetPylint(input_api, output_api, white_list=None, black_list=None, 716 def GetPylint(input_api, output_api, white_list=None, black_list=None,
717 disabled_warnings=None, extra_paths_list=None): 717 disabled_warnings=None, extra_paths_list=None, pylintrc=None):
718 """Run pylint on python files. 718 """Run pylint on python files.
719 719
720 The default white_list enforces looking only at *.py files. 720 The default white_list enforces looking only at *.py files.
721 """ 721 """
722 white_list = tuple(white_list or ('.*\.py$',)) 722 white_list = tuple(white_list or ('.*\.py$',))
723 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) 723 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
724 extra_paths_list = extra_paths_list or [] 724 extra_paths_list = extra_paths_list or []
725 725
726 if input_api.is_committing: 726 if input_api.is_committing:
727 error_type = output_api.PresubmitError 727 error_type = output_api.PresubmitError
(...skipping 14 matching lines...) Expand all
742 742
743 prefix = input_api.os_path.join(input_api.os_path.relpath( 743 prefix = input_api.os_path.join(input_api.os_path.relpath(
744 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '') 744 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '')
745 return input_api.re.escape(prefix) + regex 745 return input_api.re.escape(prefix) + regex
746 src_filter = lambda x: input_api.FilterSourceFile( 746 src_filter = lambda x: input_api.FilterSourceFile(
747 x, map(rel_path, white_list), map(rel_path, black_list)) 747 x, map(rel_path, white_list), map(rel_path, black_list))
748 if not input_api.AffectedSourceFiles(src_filter): 748 if not input_api.AffectedSourceFiles(src_filter):
749 input_api.logging.info('Skipping pylint: no matching changes.') 749 input_api.logging.info('Skipping pylint: no matching changes.')
750 return [] 750 return []
751 751
752 extra_args = ['--rcfile=%s' % input_api.os_path.join(_HERE, 'pylintrc')] 752 if pylintrc is not None:
753 pylintrc = input_api.os_path.join(input_api.PresubmitLocalPath(), pylintrc)
754 else:
755 pylintrc = input_api.os_path.join(_HERE, 'pylintrc')
756 extra_args = ['--rcfile=%s' % pylintrc]
753 if disabled_warnings: 757 if disabled_warnings:
754 extra_args.extend(['-d', ','.join(disabled_warnings)]) 758 extra_args.extend(['-d', ','.join(disabled_warnings)])
755 759
756 files = _FetchAllFiles(input_api, white_list, black_list) 760 files = _FetchAllFiles(input_api, white_list, black_list)
757 if not files: 761 if not files:
758 return [] 762 return []
759 files.sort() 763 files.sort()
760 764
761 input_api.logging.info('Running pylint on %d files', len(files)) 765 input_api.logging.info('Running pylint on %d files', len(files))
762 input_api.logging.debug('Running pylint on: %s', files) 766 input_api.logging.debug('Running pylint on: %s', files)
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 for f in affected_files: 1129 for f in affected_files:
1126 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] 1130 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1127 rc = gn.main(cmd) 1131 rc = gn.main(cmd)
1128 if rc == 2: 1132 if rc == 2:
1129 warnings.append(output_api.PresubmitPromptWarning( 1133 warnings.append(output_api.PresubmitPromptWarning(
1130 '%s requires formatting. Please run `gn format --in-place %s`.' % ( 1134 '%s requires formatting. Please run `gn format --in-place %s`.' % (
1131 f.AbsoluteLocalPath(), f.LocalPath()))) 1135 f.AbsoluteLocalPath(), f.LocalPath())))
1132 # It's just a warning, so ignore other types of failures assuming they'll be 1136 # It's just a warning, so ignore other types of failures assuming they'll be
1133 # caught elsewhere. 1137 # caught elsewhere.
1134 return warnings 1138 return warnings
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698