OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Presubmit script for devil. |
| 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 8 details on the presubmit API built into depot_tools. |
| 9 """ |
| 10 |
| 11 |
| 12 def _RunPylint(input_api, output_api): |
| 13 return input_api.canned_checks.RunPylint( |
| 14 input_api, |
| 15 output_api, |
| 16 pylintrc='pylintrc', |
| 17 extra_paths_list=[ |
| 18 input_api.os_path.join(input_api.PresubmitLocalPath(), '..'), |
| 19 ]) |
| 20 |
| 21 |
| 22 def _RunUnitTests(input_api, output_api): |
| 23 def J(*dirs): |
| 24 """Returns a path relative to presubmit directory.""" |
| 25 return input_api.os_path.join(input_api.PresubmitLocalPath(), *dirs) |
| 26 |
| 27 test_env = dict(input_api.environ) |
| 28 test_env.update({ |
| 29 'PYTHONDONTWRITEBYTECODE': '1', |
| 30 'PYTHONPATH': ':'.join([J(), J('..')]), |
| 31 }) |
| 32 |
| 33 return input_api.canned_checks.RunUnitTests( |
| 34 input_api, |
| 35 output_api, |
| 36 unit_tests=[ |
| 37 J('devil_env_test.py'), |
| 38 J('android', 'battery_utils_test.py'), |
| 39 J('android', 'device_utils_test.py'), |
| 40 J('android', 'fastboot_utils_test.py'), |
| 41 J('android', 'md5sum_test.py'), |
| 42 J('android', 'logcat_monitor_test.py'), |
| 43 J('utils', 'cmd_helper_test.py'), |
| 44 J('utils', 'timeout_retry_unittest.py'), |
| 45 ], |
| 46 env=test_env) |
| 47 |
| 48 |
| 49 def _EnsureNoPylibUse(input_api, output_api): |
| 50 def other_python_files(f): |
| 51 this_presubmit_file = input_api.os_path.join( |
| 52 input_api.PresubmitLocalPath(), 'PRESUBMIT.py') |
| 53 return (f.LocalPath().endswith('.py') |
| 54 and not f.AbsoluteLocalPath() == this_presubmit_file) |
| 55 |
| 56 changed_files = input_api.AffectedSourceFiles(other_python_files) |
| 57 import_error_re = input_api.re.compile( |
| 58 r'(from pylib.* import)|(import pylib)') |
| 59 |
| 60 errors = [] |
| 61 for f in changed_files: |
| 62 errors.extend( |
| 63 '%s:%d' % (f.LocalPath(), line_number) |
| 64 for line_number, line_text in f.ChangedContents() |
| 65 if import_error_re.search(line_text)) |
| 66 |
| 67 if errors: |
| 68 return [output_api.PresubmitError( |
| 69 'pylib modules should not be imported from devil modules.', |
| 70 items=errors)] |
| 71 return [] |
| 72 |
| 73 |
| 74 def CommonChecks(input_api, output_api): |
| 75 output = [] |
| 76 output += _RunPylint(input_api, output_api) |
| 77 output += _RunUnitTests(input_api, output_api) |
| 78 output += _EnsureNoPylibUse(input_api, output_api) |
| 79 return output |
| 80 |
| 81 |
| 82 def CheckChangeOnUpload(input_api, output_api): |
| 83 return CommonChecks(input_api, output_api) |
| 84 |
| 85 |
| 86 def CheckChangeOnCommit(input_api, output_api): |
| 87 return CommonChecks(input_api, output_api) |
OLD | NEW |