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

Side by Side Diff: PRESUBMIT.py

Issue 2353393004: Use a whitelist for depot_tools pylint instead (Closed)
Patch Set: Skip cpplint.py, since it should be in third_party Created 4 years, 2 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 | cpplint.py » ('j') | 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 """Top-level presubmit script for depot tools. 5 """Top-level presubmit script for depot tools.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into depot_tools. 8 details on the presubmit API built into depot_tools.
9 """ 9 """
10 10
11 import fnmatch 11 import fnmatch
12 import os 12 import os
13 13
14 14
15 def CommonChecks(input_api, output_api, tests_to_black_list): 15 def DepotToolsPylint(input_api, output_api):
16 results = [] 16 """Gather all the pylint logic into one place to make it self-contained."""
17 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) 17 white_list = [
18 black_list = list(input_api.DEFAULT_BLACK_LIST) + [ 18 r'^[^/]*\.py$',
19 r'^\.recipe_deps[\/\\].*', 19 r'^testing_support/[^/]*\.py$',
20 r'^infra[\/\\]\.recipe_deps[\/\\].*', 20 r'^tests/[^/]*\.py$',
21 r'^cpplint\.py$', 21 r'^recipe_modules/.*\.py$', # Allow recursive search in recipe modules.
22 r'^cpplint_chromium\.py$',
23 r'^external_bin[\/\\].+',
24 r'^python[0-9]*_bin[\/\\].+',
25 r'^recipes\.py$',
26 r'^site-packages-py[0-9]\.[0-9][\/\\].+',
27 r'^svn_bin[\/\\].+',
28 r'^testing_support[\/\\]_rietveld[\/\\].+',
29 r'^testing_support[\/\\]_infra[\/\\].+',
30 ] 22 ]
23 black_list = list(input_api.DEFAULT_BLACK_LIST)
31 if os.path.exists('.gitignore'): 24 if os.path.exists('.gitignore'):
32 with open('.gitignore') as fh: 25 with open('.gitignore') as fh:
33 lines = [l.strip() for l in fh.readlines()] 26 lines = [l.strip() for l in fh.readlines()]
34 black_list.extend([fnmatch.translate(l) for l in lines if 27 black_list.extend([fnmatch.translate(l) for l in lines if
35 l and not l.startswith('#')]) 28 l and not l.startswith('#')])
36 if os.path.exists('.git/info/exclude'): 29 if os.path.exists('.git/info/exclude'):
37 with open('.git/info/exclude') as fh: 30 with open('.git/info/exclude') as fh:
38 lines = [l.strip() for l in fh.readlines()] 31 lines = [l.strip() for l in fh.readlines()]
39 black_list.extend([fnmatch.translate(l) for l in lines if 32 black_list.extend([fnmatch.translate(l) for l in lines if
40 l and not l.startswith('#')]) 33 l and not l.startswith('#')])
41 disabled_warnings = [ 34 disabled_warnings = [
42 'R0401', # Cyclic import 35 'R0401', # Cyclic import
43 'W0613', # Unused argument 36 'W0613', # Unused argument
44 ] 37 ]
45 pylint = input_api.canned_checks.GetPylint( 38 return input_api.canned_checks.GetPylint(
46 input_api, 39 input_api,
47 output_api, 40 output_api,
48 white_list=[r'.*\.py$'], 41 white_list=white_list,
49 black_list=black_list, 42 black_list=black_list,
50 disabled_warnings=disabled_warnings) 43 disabled_warnings=disabled_warnings)
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))
51 # TODO(maruel): Make sure at least one file is modified first. 49 # TODO(maruel): Make sure at least one file is modified first.
52 # TODO(maruel): If only tests are modified, only run them. 50 # TODO(maruel): If only tests are modified, only run them.
51 tests = DepotToolsPylint(input_api, output_api)
53 unit_tests = input_api.canned_checks.GetUnitTestsInDirectory( 52 unit_tests = input_api.canned_checks.GetUnitTestsInDirectory(
54 input_api, 53 input_api,
55 output_api, 54 output_api,
56 'tests', 55 'tests',
57 whitelist=[r'.*test\.py$'], 56 whitelist=[r'.*test\.py$'],
58 blacklist=tests_to_black_list) 57 blacklist=tests_to_black_list)
59 tests = pylint
60 if not input_api.platform.startswith(('cygwin', 'win32')): 58 if not input_api.platform.startswith(('cygwin', 'win32')):
61 tests.extend(unit_tests) 59 tests.extend(unit_tests)
62 else: 60 else:
63 print('Warning: not running unit tests on Windows') 61 print('Warning: not running unit tests on Windows')
64 results.extend(input_api.RunTests(tests)) 62 results.extend(input_api.RunTests(tests))
65 return results 63 return results
66 64
67 65
68 def RunGitClTests(input_api, output_api): 66 def RunGitClTests(input_api, output_api):
69 """Run all the shells scripts in the directory test. 67 """Run all the shells scripts in the directory test.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 124
127 125
128 def CheckChangeOnCommit(input_api, output_api): 126 def CheckChangeOnCommit(input_api, output_api):
129 output = [] 127 output = []
130 output.extend(CommonChecks(input_api, output_api, [])) 128 output.extend(CommonChecks(input_api, output_api, []))
131 output.extend(input_api.canned_checks.CheckDoNotSubmit( 129 output.extend(input_api.canned_checks.CheckDoNotSubmit(
132 input_api, 130 input_api,
133 output_api)) 131 output_api))
134 output.extend(RunGitClTests(input_api, output_api)) 132 output.extend(RunGitClTests(input_api, output_api))
135 return output 133 return output
OLDNEW
« no previous file with comments | « no previous file | cpplint.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698