chrisha@chromium.org | c920ad2 | 2012-02-02 18:26:04 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for depot tools. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 8 | details on the presubmit API built into depot_tools. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 9 | """ |
| 10 | |
szager@chromium.org | 3407103 | 2014-03-18 17:23:48 +0000 | [diff] [blame] | 11 | import fnmatch |
| 12 | import os |
| 13 | |
dpranke@chromium.org | 627ea67 | 2011-03-11 23:29:03 +0000 | [diff] [blame] | 14 | |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 15 | def DepotToolsPylint(input_api, output_api): |
| 16 | """Gather all the pylint logic into one place to make it self-contained.""" |
| 17 | white_list = [ |
| 18 | r'^[^/]*\.py$', |
| 19 | r'^testing_support/[^/]*\.py$', |
| 20 | r'^tests/[^/]*\.py$', |
| 21 | r'^recipe_modules/.*\.py$', # Allow recursive search in recipe modules. |
tandrii@chromium.org | 55cb27e | 2016-05-16 17:54:40 +0000 | [diff] [blame] | 22 | ] |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 23 | black_list = list(input_api.DEFAULT_BLACK_LIST) |
szager@chromium.org | 3407103 | 2014-03-18 17:23:48 +0000 | [diff] [blame] | 24 | if os.path.exists('.gitignore'): |
| 25 | with open('.gitignore') as fh: |
| 26 | lines = [l.strip() for l in fh.readlines()] |
| 27 | black_list.extend([fnmatch.translate(l) for l in lines if |
| 28 | l and not l.startswith('#')]) |
| 29 | if os.path.exists('.git/info/exclude'): |
| 30 | with open('.git/info/exclude') as fh: |
| 31 | lines = [l.strip() for l in fh.readlines()] |
| 32 | black_list.extend([fnmatch.translate(l) for l in lines if |
| 33 | l and not l.startswith('#')]) |
maruel@chromium.org | ff9a217 | 2012-04-24 16:55:32 +0000 | [diff] [blame] | 34 | disabled_warnings = [ |
| 35 | 'R0401', # Cyclic import |
| 36 | 'W0613', # Unused argument |
| 37 | ] |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 38 | return input_api.canned_checks.GetPylint( |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 39 | input_api, |
| 40 | output_api, |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 41 | white_list=white_list, |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 42 | black_list=black_list, |
| 43 | disabled_warnings=disabled_warnings) |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def CommonChecks(input_api, output_api, tests_to_black_list): |
| 47 | results = [] |
| 48 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 49 | # TODO(maruel): Make sure at least one file is modified first. |
| 50 | # TODO(maruel): If only tests are modified, only run them. |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 51 | tests = DepotToolsPylint(input_api, output_api) |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 52 | unit_tests = input_api.canned_checks.GetUnitTestsInDirectory( |
| 53 | input_api, |
| 54 | output_api, |
| 55 | 'tests', |
| 56 | whitelist=[r'.*test\.py$'], |
| 57 | blacklist=tests_to_black_list) |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 58 | if not input_api.platform.startswith(('cygwin', 'win32')): |
| 59 | tests.extend(unit_tests) |
| 60 | else: |
| 61 | print('Warning: not running unit tests on Windows') |
| 62 | results.extend(input_api.RunTests(tests)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 63 | return results |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 64 | |
| 65 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 66 | def CheckChangeOnUpload(input_api, output_api): |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 67 | # Do not run integration tests on upload since they are way too slow. |
| 68 | tests_to_black_list = [ |
| 69 | r'^checkout_test\.py$', |
| 70 | r'^gclient_smoketest\.py$', |
| 71 | r'^scm_unittest\.py$', |
ilevy@chromium.org | 5856562 | 2013-03-17 23:18:37 +0000 | [diff] [blame] | 72 | r'^subprocess2_test\.py$', |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 73 | ] |
| 74 | return CommonChecks(input_api, output_api, tests_to_black_list) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 75 | |
| 76 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 77 | def CheckChangeOnCommit(input_api, output_api): |
| 78 | output = [] |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 79 | output.extend(CommonChecks(input_api, output_api, [])) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 80 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 81 | input_api, |
| 82 | output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 83 | return output |