OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 | 7 |
8 ### Description checks | 8 ### Description checks |
9 | 9 |
10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 if Find(filepath, white_list) and not Find(filepath, black_list): | 569 if Find(filepath, white_list) and not Find(filepath, black_list): |
570 files.append(filepath) | 570 files.append(filepath) |
571 return files | 571 return files |
572 | 572 |
573 | 573 |
574 def RunPylint(input_api, output_api, white_list=None, black_list=None): | 574 def RunPylint(input_api, output_api, white_list=None, black_list=None): |
575 """Run pylint on python files. | 575 """Run pylint on python files. |
576 | 576 |
577 The default white_list enforces looking only a *.py files. | 577 The default white_list enforces looking only a *.py files. |
578 """ | 578 """ |
579 white_list = white_list or ['.*\.py$'] | 579 white_list = tuple(white_list or ('.*\.py$',)) |
580 black_list = black_list or input_api.DEFAULT_BLACK_LIST | 580 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) |
581 if input_api.is_committing: | 581 if input_api.is_committing: |
582 error_type = output_api.PresubmitError | 582 error_type = output_api.PresubmitError |
583 else: | 583 else: |
584 error_type = output_api.PresubmitPromptWarning | 584 error_type = output_api.PresubmitPromptWarning |
585 | 585 |
586 # Only trigger if there is at least one python file affected. | 586 # Only trigger if there is at least one python file affected. |
587 src_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list) | 587 src_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list) |
588 if not input_api.AffectedSourceFiles(src_filter): | 588 if not input_api.AffectedSourceFiles(src_filter): |
589 return [] | 589 return [] |
590 | 590 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 Args: | 839 Args: |
840 input_api: Bag of input related interfaces. | 840 input_api: Bag of input related interfaces. |
841 output_api: Bag of output related interfaces. | 841 output_api: Bag of output related interfaces. |
842 excluded_paths: Don't include these paths in common checks. | 842 excluded_paths: Don't include these paths in common checks. |
843 text_files: Which file are to be treated as documentation text files. | 843 text_files: Which file are to be treated as documentation text files. |
844 license_header: What license header should be on files. | 844 license_header: What license header should be on files. |
845 project_name: What is the name of the project as it appears in the license. | 845 project_name: What is the name of the project as it appears in the license. |
846 Returns: | 846 Returns: |
847 A list of warning or error objects. | 847 A list of warning or error objects. |
848 """ | 848 """ |
849 excluded_paths = excluded_paths or tuple() | 849 excluded_paths = tuple(excluded_paths or []) |
850 text_files = text_files or ( | 850 text_files = tuple(text_files or ( |
851 r'.+\.txt$', | 851 r'.+\.txt$', |
852 r'.+\.json$', | 852 r'.+\.json$', |
853 ) | 853 )) |
854 project_name = project_name or 'Chromium' | 854 project_name = project_name or 'Chromium' |
855 license_header = license_header or ( | 855 license_header = license_header or ( |
856 r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' | 856 r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' |
857 r'All rights reserved\.\n' | 857 r'All rights reserved\.\n' |
858 r'.*? Use of this source code is governed by a BSD-style license that ' | 858 r'.*? Use of this source code is governed by a BSD-style license that ' |
859 r'can be\n' | 859 r'can be\n' |
860 r'.*? found in the LICENSE file\.\n' | 860 r'.*? found in the LICENSE file\.\n' |
861 ) % { | 861 ) % { |
862 'year': input_api.time.strftime('%Y'), | 862 'year': input_api.time.strftime('%Y'), |
863 'project': project_name, | 863 'project': project_name, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( | 912 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( |
913 input_api, output_api, source_file_filter=text_files)) | 913 input_api, output_api, source_file_filter=text_files)) |
914 snapshot("checking svn mime types") | 914 snapshot("checking svn mime types") |
915 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 915 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
916 input_api, output_api)) | 916 input_api, output_api)) |
917 snapshot("checking license") | 917 snapshot("checking license") |
918 results.extend(input_api.canned_checks.CheckLicense( | 918 results.extend(input_api.canned_checks.CheckLicense( |
919 input_api, output_api, license_header, source_file_filter=sources)) | 919 input_api, output_api, license_header, source_file_filter=sources)) |
920 snapshot("done") | 920 snapshot("done") |
921 return results | 921 return results |
OLD | NEW |