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 | 10 |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 white_list = tuple(white_list or ('.*\.py$',)) | 634 white_list = tuple(white_list or ('.*\.py$',)) |
635 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 635 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
636 extra_paths_list = extra_paths_list or [] | 636 extra_paths_list = extra_paths_list or [] |
637 | 637 |
638 if input_api.is_committing: | 638 if input_api.is_committing: |
639 error_type = output_api.PresubmitError | 639 error_type = output_api.PresubmitError |
640 else: | 640 else: |
641 error_type = output_api.PresubmitPromptWarning | 641 error_type = output_api.PresubmitPromptWarning |
642 | 642 |
643 # Only trigger if there is at least one python file affected. | 643 # Only trigger if there is at least one python file affected. |
644 rel_path = lambda x : input_api.os_path.join(input_api.os_path.relpath( | 644 def rel_path(regex): |
645 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), x) | 645 """Modifies a regex for a subject to accept paths relative to root.""" |
| 646 prefix = input_api.os_path.join(input_api.os_path.relpath( |
| 647 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), '') |
| 648 return input_api.re.escape(prefix) + regex |
646 src_filter = lambda x: input_api.FilterSourceFile( | 649 src_filter = lambda x: input_api.FilterSourceFile( |
647 x, map(rel_path, white_list), map(rel_path, black_list)) | 650 x, map(rel_path, white_list), map(rel_path, black_list)) |
648 if not input_api.AffectedSourceFiles(src_filter): | 651 if not input_api.AffectedSourceFiles(src_filter): |
649 input_api.logging.info('Skipping pylint: no matching changes.') | 652 input_api.logging.info('Skipping pylint: no matching changes.') |
650 return [] | 653 return [] |
651 | 654 |
652 extra_args = ['--rcfile=%s' % input_api.os_path.join(_HERE, 'pylintrc')] | 655 extra_args = ['--rcfile=%s' % input_api.os_path.join(_HERE, 'pylintrc')] |
653 if disabled_warnings: | 656 if disabled_warnings: |
654 extra_args.extend(['-d', ','.join(disabled_warnings)]) | 657 extra_args.extend(['-d', ','.join(disabled_warnings)]) |
655 | 658 |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 snapshot("checking description") | 996 snapshot("checking description") |
994 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 997 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
995 input_api, output_api)) | 998 input_api, output_api)) |
996 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( | 999 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( |
997 input_api, output_api)) | 1000 input_api, output_api)) |
998 snapshot("checking do not submit in files") | 1001 snapshot("checking do not submit in files") |
999 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( | 1002 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( |
1000 input_api, output_api)) | 1003 input_api, output_api)) |
1001 snapshot("done") | 1004 snapshot("done") |
1002 return results | 1005 return results |
OLD | NEW |