Commit a5137930 authored by Tamer Tas's avatar Tamer Tas Committed by V8 LUCI CQ

[infra] migrate simple PRESUBMIT scripts to py3

R=machenbach@chromium.org,alexschulze@chromium.org

Bug: chromium:1298869
Change-Id: I1ef1ac1d48ccbea81cfebcc360194f5003da17d0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3474672
Commit-Queue: Tamer Tas <tmrts@chromium.org>
Auto-Submit: Tamer Tas <tmrts@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79171}
parent c1078b5e
......@@ -7,6 +7,10 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _CommonChecks(input_api, output_api):
results = []
......
......@@ -11,10 +11,9 @@ For simplicity, we check all pyl files on any changes in this folder.
import ast
import os
try:
basestring # Python 2
except NameError: # Python 3
basestring = str
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
SUPPORTED_BUILDER_SPEC_KEYS = [
'swarming_dimensions',
......@@ -120,7 +119,7 @@ def _check_test(error_msg, test):
test_args = test.get('test_args', [])
if not isinstance(test_args, list):
errors += error_msg('If specified, test_args must be a list of arguments')
if not all(isinstance(x, basestring) for x in test_args):
if not all(isinstance(x, str) for x in test_args):
errors += error_msg('If specified, all test_args must be strings')
# Limit shards to 14 to avoid erroneous resource exhaustion.
......@@ -128,7 +127,7 @@ def _check_test(error_msg, test):
error_msg, test, 'shards', lower_bound=1, upper_bound=14)
variant = test.get('variant', 'default')
if not variant or not isinstance(variant, basestring):
if not variant or not isinstance(variant, str):
errors += error_msg('If specified, variant must be a non-empty string')
return errors
......@@ -148,11 +147,11 @@ def _check_test_spec(file_path, raw_pyl):
return error_msg('Test spec must be a dict')
errors = []
for buildername, builder_spec in full_test_spec.iteritems():
for buildername, builder_spec in full_test_spec.items():
def error_msg(msg):
return ['Error in %s for builder %s:\n%s' % (file_path, buildername, msg)]
if not isinstance(buildername, basestring) or not buildername:
if not isinstance(buildername, str) or not buildername:
errors += error_msg('Buildername must be a non-empty string')
if not isinstance(builder_spec, dict) or not builder_spec:
......
......@@ -2,6 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def CheckChangeOnCommit(input_api, output_api):
tests = input_api.canned_checks.GetUnitTestsInDirectory(
input_api, output_api, 'unittests', files_to_check=[r'.+_test\.py$'])
......
......@@ -4,6 +4,10 @@
import json
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _RunTests(input_api, output_api):
return input_api.RunTests(input_api.canned_checks.GetUnitTestsInDirectory(
......
......@@ -4,10 +4,9 @@
import json
try:
basestring # Python 2
except NameError: # Python 3
basestring = str
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _CheckTrialsConfig(input_api, output_api):
......@@ -23,16 +22,20 @@ def _CheckTrialsConfig(input_api, output_api):
try:
trials = json.load(j)
for trial in trials:
if not all (k in trial for k in ('app_args', 'app_name', 'probability')):
results.append('trial %s is not configured correctly' % trial)
if not all(
k in trial for k in ('app_args', 'app_name', 'probability')):
results.append('trial {} is not configured correctly'.format(trial))
if trial['app_name'] != 'd8':
results.append('trial %s has an incorrect app_name' % trial)
results.append('trial {} has an incorrect app_name'.format(trial))
if not isinstance(trial['probability'], float):
results.append('trial %s probability is not a float' % trial)
results.append('trial {} probability is not a float'.format(trial))
if not (0 <= trial['probability'] <= 1):
results.append('trial %s has invalid probability value' % trial)
if not isinstance(trial['app_args'], basestring) or not trial['app_args']:
results.append('trial %s should have a non-empty string for app_args' % trial)
results.append(
'trial {} has invalid probability value'.format(trial))
if not isinstance(trial['app_args'], str) or not trial['app_args']:
results.append(
'trial {} should have a non-empty string for app_args'.format(
trial))
except Exception as e:
results.append(
'JSON validation failed for %s. Error:\n%s' % (f.LocalPath(), e))
......
......@@ -3,6 +3,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _CommonChecks(input_api, output_api):
results = []
......@@ -12,8 +16,10 @@ def _CommonChecks(input_api, output_api):
results.extend(input_api.RunTests(pylint_checks))
# Run the MB unittests.
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
input_api, output_api, '.', [ r'^.+_unittest\.py$']))
results.extend(
input_api.canned_checks.RunUnitTestsInDirectory(input_api, output_api,
'.',
[r'^.+_unittest\.py$']))
# Validate the format of the mb_config.pyl file.
cmd = [input_api.python_executable, 'mb.py', 'validate']
......@@ -23,12 +29,10 @@ def _CommonChecks(input_api, output_api):
cmd=cmd, kwargs=kwargs,
message=output_api.PresubmitError)]))
is_mb_config = (lambda filepath: 'mb_config.pyl' in filepath.LocalPath())
results.extend(
input_api.canned_checks.CheckLongLines(
input_api,
output_api,
maxlen=80,
source_file_filter=lambda x: 'mb_config.pyl' in x.LocalPath()))
input_api, output_api, maxlen=80, source_file_filter=is_mb_config))
return results
......
......@@ -2,6 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _CommonChecks(input_api, output_api):
tests = input_api.canned_checks.GetUnitTestsInDirectory(
input_api, output_api, '.', files_to_check=['test_scripts.py$'])
......
......@@ -2,6 +2,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This line is 'magic' in that git-cl looks for it to decide whether to
# use Python3 instead of Python2 when running the code in this file.
USE_PYTHON3 = True
def _CommonChecks(input_api, output_api):
return input_api.RunTests(input_api.canned_checks.GetUnitTestsRecursively(
input_api,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment