OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 | 5 |
6 """Top-level presubmit script for Skia. | 6 """Top-level presubmit script for Skia. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
9 for more details about the presubmit API built into gcl. | 9 for more details about the presubmit API built into gcl. |
10 """ | 10 """ |
(...skipping 28 matching lines...) Expand all Loading... |
39 if len(contents) > 1 and contents[-1:] != '\n': | 39 if len(contents) > 1 and contents[-1:] != '\n': |
40 eof_files.append(f.LocalPath()) | 40 eof_files.append(f.LocalPath()) |
41 | 41 |
42 if eof_files: | 42 if eof_files: |
43 return [output_api.PresubmitPromptWarning( | 43 return [output_api.PresubmitPromptWarning( |
44 'These files should end in a newline character:', | 44 'These files should end in a newline character:', |
45 items=eof_files)] | 45 items=eof_files)] |
46 return [] | 46 return [] |
47 | 47 |
48 | 48 |
| 49 def _PythonChecks(input_api, output_api): |
| 50 """Run checks on any modified Python files.""" |
| 51 pylint_disabled_warnings = ( |
| 52 'F0401', # Unable to import. |
| 53 'E0611', # No name in module. |
| 54 'W0232', # Class has no __init__ method. |
| 55 'E1002', # Use of super on an old style class. |
| 56 'W0403', # Relative import used. |
| 57 'R0201', # Method could be a function. |
| 58 'E1003', # Using class name in super. |
| 59 'W0613', # Unused argument. |
| 60 ) |
| 61 # Run Pylint on only the modified python files. Unfortunately it still runs |
| 62 # Pylint on the whole file instead of just the modified lines. |
| 63 affected_python_files = [] |
| 64 for affected_file in input_api.AffectedSourceFiles(None): |
| 65 affected_file_path = affected_file.LocalPath() |
| 66 if affected_file_path.endswith('.py'): |
| 67 affected_python_files.append(affected_file_path) |
| 68 return input_api.canned_checks.RunPylint( |
| 69 input_api, output_api, |
| 70 disabled_warnings=pylint_disabled_warnings, |
| 71 white_list=affected_python_files) |
| 72 |
| 73 |
49 def _CommonChecks(input_api, output_api): | 74 def _CommonChecks(input_api, output_api): |
50 """Presubmit checks common to upload and commit.""" | 75 """Presubmit checks common to upload and commit.""" |
51 results = [] | 76 results = [] |
52 sources = lambda x: (x.LocalPath().endswith('.h') or | 77 sources = lambda x: (x.LocalPath().endswith('.h') or |
53 x.LocalPath().endswith('.gypi') or | 78 x.LocalPath().endswith('.gypi') or |
54 x.LocalPath().endswith('.gyp') or | 79 x.LocalPath().endswith('.gyp') or |
55 x.LocalPath().endswith('.py') or | 80 x.LocalPath().endswith('.py') or |
56 x.LocalPath().endswith('.sh') or | 81 x.LocalPath().endswith('.sh') or |
57 x.LocalPath().endswith('.cpp')) | 82 x.LocalPath().endswith('.cpp')) |
58 results.extend( | 83 results.extend( |
59 _CheckChangeHasEol( | 84 _CheckChangeHasEol( |
60 input_api, output_api, source_file_filter=sources)) | 85 input_api, output_api, source_file_filter=sources)) |
| 86 results.extend(_PythonChecks(input_api, output_api)) |
61 return results | 87 return results |
62 | 88 |
63 | 89 |
64 def CheckChangeOnUpload(input_api, output_api): | 90 def CheckChangeOnUpload(input_api, output_api): |
65 """Presubmit checks for the change on upload. | 91 """Presubmit checks for the change on upload. |
66 | 92 |
67 The following are the presubmit checks: | 93 The following are the presubmit checks: |
68 * Check change has one and only one EOL. | 94 * Check change has one and only one EOL. |
69 """ | 95 """ |
70 results = [] | 96 results = [] |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 # An owner created the CL that is an automatic LGTM. | 208 # An owner created the CL that is an automatic LGTM. |
183 lgtm_from_owner = True | 209 lgtm_from_owner = True |
184 | 210 |
185 messages = issue_properties.get('messages') | 211 messages = issue_properties.get('messages') |
186 if messages: | 212 if messages: |
187 for message in messages: | 213 for message in messages: |
188 if (message['sender'] in PUBLIC_API_OWNERS and | 214 if (message['sender'] in PUBLIC_API_OWNERS and |
189 'lgtm' in message['text'].lower()): | 215 'lgtm' in message['text'].lower()): |
190 # Found an lgtm in a message from an owner. | 216 # Found an lgtm in a message from an owner. |
191 lgtm_from_owner = True | 217 lgtm_from_owner = True |
192 break; | 218 break |
193 | 219 |
194 if not lgtm_from_owner: | 220 if not lgtm_from_owner: |
195 results.append( | 221 results.append( |
196 output_api.PresubmitError( | 222 output_api.PresubmitError( |
197 'Since the CL is editing public API, you must have an LGTM from ' | 223 'Since the CL is editing public API, you must have an LGTM from ' |
198 'one of: %s' % str(PUBLIC_API_OWNERS))) | 224 'one of: %s' % str(PUBLIC_API_OWNERS))) |
199 return results | 225 return results |
200 | 226 |
201 | 227 |
202 def CheckChangeOnCommit(input_api, output_api): | 228 def CheckChangeOnCommit(input_api, output_api): |
203 """Presubmit checks for the change on commit. | 229 """Presubmit checks for the change on commit. |
204 | 230 |
205 The following are the presubmit checks: | 231 The following are the presubmit checks: |
206 * Check change has one and only one EOL. | 232 * Check change has one and only one EOL. |
207 * Ensures that the Skia tree is open in | 233 * Ensures that the Skia tree is open in |
208 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 234 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
209 state and an error if it is in 'Closed' state. | 235 state and an error if it is in 'Closed' state. |
210 """ | 236 """ |
211 results = [] | 237 results = [] |
212 results.extend(_CommonChecks(input_api, output_api)) | 238 results.extend(_CommonChecks(input_api, output_api)) |
213 results.extend( | 239 results.extend( |
214 _CheckTreeStatus(input_api, output_api, json_url=( | 240 _CheckTreeStatus(input_api, output_api, json_url=( |
215 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 241 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
216 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 242 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
217 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 243 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
218 return results | 244 return results |
OLD | NEW |