OLD | NEW |
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 Loading... |
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, extensions=None, | 697 disabled_warnings=None, extra_paths_list=None, pylintrc=None): |
698 pylintrc=None): | |
699 """Run pylint on python files. | 698 """Run pylint on python files. |
700 | 699 |
701 The default white_list enforces looking only at *.py files. | 700 The default white_list enforces looking only at *.py files. |
702 """ | 701 """ |
703 white_list = tuple(white_list or ('.*\.py$',)) | 702 white_list = tuple(white_list or ('.*\.py$',)) |
704 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 703 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
705 extra_paths_list = extra_paths_list or [] | 704 extra_paths_list = extra_paths_list or [] |
706 | 705 |
707 if input_api.is_committing: | 706 if input_api.is_committing: |
708 error_type = output_api.PresubmitError | 707 error_type = output_api.PresubmitError |
(...skipping 14 matching lines...) Expand all Loading... |
723 | 722 |
724 prefix = input_api.os_path.join(input_api.os_path.relpath( | 723 prefix = input_api.os_path.join(input_api.os_path.relpath( |
725 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '') | 724 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '') |
726 return input_api.re.escape(prefix) + regex | 725 return input_api.re.escape(prefix) + regex |
727 src_filter = lambda x: input_api.FilterSourceFile( | 726 src_filter = lambda x: input_api.FilterSourceFile( |
728 x, map(rel_path, white_list), map(rel_path, black_list)) | 727 x, map(rel_path, white_list), map(rel_path, black_list)) |
729 if not input_api.AffectedSourceFiles(src_filter): | 728 if not input_api.AffectedSourceFiles(src_filter): |
730 input_api.logging.info('Skipping pylint: no matching changes.') | 729 input_api.logging.info('Skipping pylint: no matching changes.') |
731 return [] | 730 return [] |
732 | 731 |
733 extra_args = [] | |
734 | |
735 if extensions: | |
736 extra_args.append('--extension-pkg-whitelist=' + ','.join(extensions)) | |
737 | |
738 if pylintrc is not None: | 732 if pylintrc is not None: |
739 pylintrc = input_api.os_path.join(input_api.PresubmitLocalPath(), pylintrc) | 733 pylintrc = input_api.os_path.join(input_api.PresubmitLocalPath(), pylintrc) |
740 else: | 734 else: |
741 pylintrc = input_api.os_path.join(_HERE, 'pylintrc') | 735 pylintrc = input_api.os_path.join(_HERE, 'pylintrc') |
742 extra_args.append('--rcfile=%s' % pylintrc) | 736 extra_args = ['--rcfile=%s' % pylintrc] |
743 if disabled_warnings: | 737 if disabled_warnings: |
744 extra_args.extend(['-d', ','.join(disabled_warnings)]) | 738 extra_args.extend(['-d', ','.join(disabled_warnings)]) |
745 | 739 |
746 files = _FetchAllFiles(input_api, white_list, black_list) | 740 files = _FetchAllFiles(input_api, white_list, black_list) |
747 if not files: | 741 if not files: |
748 return [] | 742 return [] |
749 files.sort() | 743 files.sort() |
750 | 744 |
751 input_api.logging.info('Running pylint on %d files', len(files)) | 745 input_api.logging.info('Running pylint on %d files', len(files)) |
752 input_api.logging.debug('Running pylint on: %s', files) | 746 input_api.logging.debug('Running pylint on: %s', files) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 for f in affected_files: | 1127 for f in affected_files: |
1134 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1128 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1135 rc = gn.main(cmd) | 1129 rc = gn.main(cmd) |
1136 if rc == 2: | 1130 if rc == 2: |
1137 warnings.append(output_api.PresubmitPromptWarning( | 1131 warnings.append(output_api.PresubmitPromptWarning( |
1138 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1132 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1139 f.AbsoluteLocalPath(), f.LocalPath()))) | 1133 f.AbsoluteLocalPath(), f.LocalPath()))) |
1140 # It's just a warning, so ignore other types of failures assuming they'll be | 1134 # It's just a warning, so ignore other types of failures assuming they'll be |
1141 # caught elsewhere. | 1135 # caught elsewhere. |
1142 return warnings | 1136 return warnings |
OLD | NEW |