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

Side by Side Diff: presubmit_canned_checks.py

Issue 1639493003: Add extensions parameter to Pylint presubmit check. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 10 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
« 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if Find(filepath, black_list): 687 if Find(filepath, black_list):
688 dirnames.remove(item) 688 dirnames.remove(item)
689 for item in filenames: 689 for item in filenames:
690 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:] 690 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:]
691 if Find(filepath, white_list) and not Find(filepath, black_list): 691 if Find(filepath, white_list) and not Find(filepath, black_list):
692 files.append(filepath) 692 files.append(filepath)
693 return files 693 return files
694 694
695 695
696 def GetPylint(input_api, output_api, white_list=None, black_list=None, 696 def GetPylint(input_api, output_api, white_list=None, black_list=None,
697 disabled_warnings=None, extra_paths_list=None, pylintrc=None): 697 disabled_warnings=None, extra_paths_list=None, extensions=None,
698 pylintrc=None):
698 """Run pylint on python files. 699 """Run pylint on python files.
699 700
700 The default white_list enforces looking only at *.py files. 701 The default white_list enforces looking only at *.py files.
701 """ 702 """
702 white_list = tuple(white_list or ('.*\.py$',)) 703 white_list = tuple(white_list or ('.*\.py$',))
703 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) 704 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
704 extra_paths_list = extra_paths_list or [] 705 extra_paths_list = extra_paths_list or []
705 706
706 if input_api.is_committing: 707 if input_api.is_committing:
707 error_type = output_api.PresubmitError 708 error_type = output_api.PresubmitError
(...skipping 14 matching lines...) Expand all
722 723
723 prefix = input_api.os_path.join(input_api.os_path.relpath( 724 prefix = input_api.os_path.join(input_api.os_path.relpath(
724 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '') 725 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '')
725 return input_api.re.escape(prefix) + regex 726 return input_api.re.escape(prefix) + regex
726 src_filter = lambda x: input_api.FilterSourceFile( 727 src_filter = lambda x: input_api.FilterSourceFile(
727 x, map(rel_path, white_list), map(rel_path, black_list)) 728 x, map(rel_path, white_list), map(rel_path, black_list))
728 if not input_api.AffectedSourceFiles(src_filter): 729 if not input_api.AffectedSourceFiles(src_filter):
729 input_api.logging.info('Skipping pylint: no matching changes.') 730 input_api.logging.info('Skipping pylint: no matching changes.')
730 return [] 731 return []
731 732
733 extra_args = []
734
735 if extensions:
736 extra_args.append('--extension-pkg-whitelist=' + ','.join(extensions))
737
732 if pylintrc is not None: 738 if pylintrc is not None:
733 pylintrc = input_api.os_path.join(input_api.PresubmitLocalPath(), pylintrc) 739 pylintrc = input_api.os_path.join(input_api.PresubmitLocalPath(), pylintrc)
734 else: 740 else:
735 pylintrc = input_api.os_path.join(_HERE, 'pylintrc') 741 pylintrc = input_api.os_path.join(_HERE, 'pylintrc')
736 extra_args = ['--rcfile=%s' % pylintrc] 742 extra_args.append('--rcfile=%s' % pylintrc)
737 if disabled_warnings: 743 if disabled_warnings:
738 extra_args.extend(['-d', ','.join(disabled_warnings)]) 744 extra_args.extend(['-d', ','.join(disabled_warnings)])
739 745
740 files = _FetchAllFiles(input_api, white_list, black_list) 746 files = _FetchAllFiles(input_api, white_list, black_list)
741 if not files: 747 if not files:
742 return [] 748 return []
743 files.sort() 749 files.sort()
744 750
745 input_api.logging.info('Running pylint on %d files', len(files)) 751 input_api.logging.info('Running pylint on %d files', len(files))
746 input_api.logging.debug('Running pylint on: %s', files) 752 input_api.logging.debug('Running pylint on: %s', files)
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 for f in affected_files: 1133 for f in affected_files:
1128 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] 1134 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1129 rc = gn.main(cmd) 1135 rc = gn.main(cmd)
1130 if rc == 2: 1136 if rc == 2:
1131 warnings.append(output_api.PresubmitPromptWarning( 1137 warnings.append(output_api.PresubmitPromptWarning(
1132 '%s requires formatting. Please run `gn format --in-place %s`.' % ( 1138 '%s requires formatting. Please run `gn format --in-place %s`.' % (
1133 f.AbsoluteLocalPath(), f.LocalPath()))) 1139 f.AbsoluteLocalPath(), f.LocalPath())))
1134 # It's just a warning, so ignore other types of failures assuming they'll be 1140 # It's just a warning, so ignore other types of failures assuming they'll be
1135 # caught elsewhere. 1141 # caught elsewhere.
1136 return warnings 1142 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