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
3 # found in the LICENSE file.
5 """Presubmit script for changes affecting tools/perf/.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl (and git-cl).
15 PYLINT_DISABLED_WARNINGS
= [
16 'R0923', # Interface not implemented
17 'R0201', # Method could be a function
18 'E1101', # Non-existent member is accessed.
22 def _CommonChecks(input_api
, output_api
):
23 """Performs common checks, which includes running pylint."""
25 old_sys_path
= sys
.path
27 # Modules in tools/perf depend on telemetry.
28 sys
.path
= [os
.path
.join(os
.pardir
, 'telemetry')] + sys
.path
29 results
.extend(input_api
.canned_checks
.RunPylint(
30 input_api
, output_api
,
31 black_list
=PYLINT_BLACKLIST
,
32 disabled_warnings
=PYLINT_DISABLED_WARNINGS
))
33 results
.extend(_CheckJson(input_api
, output_api
))
35 sys
.path
= old_sys_path
39 def _CheckJson(input_api
, output_api
):
40 """Checks whether JSON files in this change can be parsed."""
41 affected_paths
= input_api
.change
.AbsoluteLocalPaths()
42 json_filenames
= [name
for name
in affected_paths
if name
.endswith('.json')]
43 for filename
in json_filenames
:
45 input_api
.json
.load(open(filename
))
47 return [output_api
.PresubmitError('Error parsing JSON in %s!' % filename
)]
51 def CheckChangeOnUpload(input_api
, output_api
):
53 report
.extend(_CommonChecks(input_api
, output_api
))
57 def CheckChangeOnCommit(input_api
, output_api
):
59 report
.extend(_CommonChecks(input_api
, output_api
))