OLD | NEW |
---|---|
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2009 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 gcl. | 8 details on the presubmit API built into gcl. |
9 """ | 9 """ |
10 | 10 |
11 UNIT_TESTS = [ | 11 UNIT_TESTS = [ |
12 'tests.gcl_unittest', | 12 'tests.gcl_unittest', |
13 'tests.gclient_scm_test', | 13 'tests.gclient_scm_test', |
14 'tests.gclient_smoketest', | 14 'tests.gclient_smoketest', |
15 'tests.gclient_utils_test', | 15 'tests.gclient_utils_test', |
16 'tests.presubmit_unittest', | 16 'tests.presubmit_unittest', |
17 'tests.scm_unittest', | 17 'tests.scm_unittest', |
18 'tests.trychange_unittest', | 18 'tests.trychange_unittest', |
19 'tests.watchlists_unittest', | 19 'tests.watchlists_unittest', |
20 ] | 20 ] |
21 | 21 |
22 def CommonChecks(input_api, output_api): | |
23 output = [] | |
24 output.extend(input_api.canned_checks.RunPythonUnitTests( | |
25 input_api, | |
26 output_api, | |
27 UNIT_TESTS)) | |
28 output.extend(WasGitClUploadHookModified(input_api, output_api)) | |
29 | |
30 def filter_python_sources(x): | |
31 l = x.LocalPath() | |
Evan Martin
2010/12/13 20:54:10
Consider not using one-letter variable names here
| |
32 return ((l.endswith('.py') and l != 'cpplint.py' and | |
33 not l.startswith('tests')) or | |
34 l == 'git-try') | |
35 | |
36 output.extend(input_api.canned_checks.RunPylint( | |
37 input_api, | |
38 output_api, | |
39 source_file_filter=filter_python_sources)) | |
40 return output | |
41 | |
42 | |
22 def CheckChangeOnUpload(input_api, output_api): | 43 def CheckChangeOnUpload(input_api, output_api): |
23 output = [] | 44 return CommonChecks(input_api, output_api) |
24 output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, | |
25 output_api, | |
26 UNIT_TESTS)) | |
27 output.extend(WasGitClUploadHookModified(input_api, output_api)) | |
28 output.extend(RunPylint(input_api, output_api)) | |
29 return output | |
30 | 45 |
31 | 46 |
32 def CheckChangeOnCommit(input_api, output_api): | 47 def CheckChangeOnCommit(input_api, output_api): |
33 output = [] | 48 output = [] |
34 output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, | 49 output.extend(CommonChecks(input_api, output_api)) |
35 output_api, | 50 output.extend(input_api.canned_checks.CheckDoNotSubmit( |
36 UNIT_TESTS)) | 51 input_api, |
37 output.extend(input_api.canned_checks.CheckDoNotSubmit(input_api, | 52 output_api)) |
38 output_api)) | |
39 output.extend(WasGitClUploadHookModified(input_api, output_api)) | |
40 output.extend(RunPylint(input_api, output_api)) | |
41 return output | 53 return output |
42 | 54 |
55 | |
43 def WasGitClUploadHookModified(input_api, output_api): | 56 def WasGitClUploadHookModified(input_api, output_api): |
44 for affected_file in input_api.AffectedSourceFiles(None): | 57 for affected_file in input_api.AffectedSourceFiles(None): |
45 if (input_api.os_path.basename(affected_file.LocalPath()) == | 58 if (input_api.os_path.basename(affected_file.LocalPath()) == |
46 'git-cl-upload-hook'): | 59 'git-cl-upload-hook'): |
47 return [output_api.PresubmitPromptWarning( | 60 return [output_api.PresubmitPromptWarning( |
48 'Don\'t forget to fix git-cl to download the newest version of ' | 61 'Don\'t forget to fix git-cl to download the newest version of ' |
49 'git-cl-upload-hook')] | 62 'git-cl-upload-hook')] |
50 return [] | 63 return [] |
51 | |
52 def RunPylint(input_api, output_api): | |
53 import glob | |
54 files = glob.glob('*.py') | |
55 # It's a python script | |
56 files.append('git-try') | |
57 # It uses non-standard pylint exceptions that makes pylint always fail. | |
58 files.remove('cpplint.py') | |
59 try: | |
60 proc = input_api.subprocess.Popen(['pylint'] + sorted(files)) | |
61 proc.communicate() | |
62 if proc.returncode: | |
63 return [output_api.PresubmitError('Fix pylint errors first.')] | |
64 return [] | |
65 except OSError: | |
66 if input_api.platform == 'win32': | |
67 return [output_api.PresubmitNotifyResult( | |
68 'Warning: Can\'t run pylint because it is not installed. Please ' | |
69 'install manually\n' | |
70 'Cannot do static analysis of python files.')] | |
71 return [output_api.PresubmitError( | |
72 'Please install pylint with "sudo apt-get install python-setuptools; ' | |
73 'sudo easy_install pylint"\n' | |
74 'Cannot do static analysis of python files.')] | |
OLD | NEW |