summaryrefslogtreecommitdiffstats
path: root/tools/telemetry/PRESUBMIT.py
blob: e7b66d64c922a86d2dc1febd6296914971fb685d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys

PYLINT_BLACKLIST = []
PYLINT_DISABLED_WARNINGS = ['R0923', 'R0201', 'E1101']

def _CommonChecks(input_api, output_api):
  results = []

  # TODO(nduca): This should call update_docs.IsUpdateDocsNeeded().
  # Disabled due to crbug.com/255326.
  if False:
    update_docs_path = os.path.join(
      input_api.PresubmitLocalPath(), 'update_docs')
    assert os.path.exists(update_docs_path)
    results.append(output_api.PresubmitError(
      'Docs are stale. Please run:\n' +
      '$ %s' % os.path.abspath(update_docs_path)))

  # Importing telemetry.web_components actually brings tvcm into the path.
  import telemetry.web_components # pylint: disable=W0612
  from tvcm import presubmit_checker
  checker = presubmit_checker.PresubmitChecker(input_api, output_api)
  results += checker.RunChecks()

  results.extend(input_api.canned_checks.RunPylint(
        input_api, output_api,
        black_list=PYLINT_BLACKLIST,
        disabled_warnings=PYLINT_DISABLED_WARNINGS))
  return results

def GetPathsToPrepend(input_api):
  return [input_api.PresubmitLocalPath()]

def RunWithPrependedPath(prepended_path, fn, *args):
  old_path = sys.path

  try:
    sys.path = prepended_path + old_path
    return fn(*args)
  finally:
    sys.path = old_path

def CheckChangeOnUpload(input_api, output_api):
  def go():
    results = []
    results.extend(_CommonChecks(input_api, output_api))
    return results
  return RunWithPrependedPath(GetPathsToPrepend(input_api), go)

def CheckChangeOnCommit(input_api, output_api):
  def go():
    results = []
    results.extend(_CommonChecks(input_api, output_api))
    return results
  return RunWithPrependedPath(GetPathsToPrepend(input_api), go)