Add JSON check in tools/perf presubmit script.
[chromium-blink-merge.git] / tools / perf / PRESUBMIT.py
blobe5ec0ec734fb458c348850ed5722057967353ca6
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).
9 """
11 import os
12 import sys
14 PYLINT_BLACKLIST = []
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."""
24 results = []
25 old_sys_path = sys.path
26 try:
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))
34 finally:
35 sys.path = old_sys_path
36 return results
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:
44 try:
45 input_api.json.load(open(filename))
46 except ValueError:
47 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
48 return []
51 def CheckChangeOnUpload(input_api, output_api):
52 report = []
53 report.extend(_CommonChecks(input_api, output_api))
54 return report
57 def CheckChangeOnCommit(input_api, output_api):
58 report = []
59 report.extend(_CommonChecks(input_api, output_api))
60 return report