Skip to content

Commit

Permalink
[CodeHealth] Bump some scripts to pylint 2.6
Browse files Browse the repository at this point in the history
And fix the lint warnings.

Bug: 1223892
Change-Id: Iadb7e59a6baf9c2f7abd92b1db81995d44cbf4fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3110310
Commit-Queue: Dirk Pranke <dpranke@google.com>
Auto-Submit: Victor Vianna <victorvianna@google.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/main@{#917422}
  • Loading branch information
Victor Hugo Vianna Silva authored and Chromium LUCI CQ committed Sep 1, 2021
1 parent bfe82c8 commit 0686307
Show file tree
Hide file tree
Showing 38 changed files with 184 additions and 137 deletions.
2 changes: 1 addition & 1 deletion build/chromeos/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def CommonChecks(input_api, output_api):
results = []
results += input_api.canned_checks.RunPylint(
input_api, output_api, pylintrc='pylintrc')
input_api, output_api, pylintrc='pylintrc', version='2.6')
tests = input_api.canned_checks.GetUnitTestsInDirectory(
input_api,
output_api,
Expand Down
2 changes: 1 addition & 1 deletion build/chromeos/gen_skylab_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys


class SkylabClientTestTest(object):
class SkylabClientTestTest:

# The basic shell script for client test run in Skylab. The arguments listed
# here will be fed by autotest at the run time.
Expand Down
23 changes: 10 additions & 13 deletions build/chromeos/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import socket
import sys
import tempfile
import six

# The following non-std imports are fetched via vpython. See the list at
# //.vpython
import dateutil.parser # pylint: disable=import-error
import jsonlines # pylint: disable=import-error
import psutil # pylint: disable=import-error
import six

CHROMIUM_SRC_PATH = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..'))
Expand Down Expand Up @@ -70,7 +70,7 @@ class TestFormatError(Exception):
pass


class RemoteTest(object):
class RemoteTest:

# This is a basic shell script that can be appended to in order to invoke the
# test on the device.
Expand Down Expand Up @@ -166,7 +166,7 @@ def write_test_script_to_disk(self, script_contents):
os.path.relpath(self._path_to_outdir, CHROMIUM_SRC_PATH),
]
logging.info('Running the following command on the device:')
logging.info('\n' + '\n'.join(script_contents))
logging.info('\n%s', '\n'.join(script_contents))
fd, tmp_path = tempfile.mkstemp(suffix='.sh', dir=self._path_to_outdir)
os.fchmod(fd, 0o755)
with os.fdopen(fd, 'w') as f:
Expand Down Expand Up @@ -219,11 +219,9 @@ def _kill_child_procs(trapped_signal, _):
if test_proc.returncode == 0:
break

ret = self.post_run(test_proc.returncode)
self.post_run(test_proc.returncode)
# Allow post_run to override test proc return code. (Useful when the host
# side Tast bin returns 0 even for failed tests.)
if ret is not None:
return ret
return test_proc.returncode

def post_run(self, return_code):
Expand Down Expand Up @@ -266,7 +264,7 @@ def get_artifacts(path):
class TastTest(RemoteTest):

def __init__(self, args, unknown_args):
super(TastTest, self).__init__(args, unknown_args)
super().__init__(args, unknown_args)

self._suite_name = args.suite_name
self._tast_vars = args.tast_vars
Expand Down Expand Up @@ -404,14 +402,14 @@ def post_run(self, return_code):
# If we don't need to parse the host-side Tast tool's results, fall back to
# the parent method's default behavior.
if self._llvm_profile_var:
return super(TastTest, self).post_run(return_code)
return super().post_run(return_code)

tast_results_path = os.path.join(self._logs_dir, 'streamed_results.jsonl')
if not os.path.exists(tast_results_path):
logging.error(
'Tast results not found at %s. Falling back to generic result '
'reporting.', tast_results_path)
return super(TastTest, self).post_run(return_code)
return super().post_run(return_code)

# See the link below for the format of the results:
# https://godoc.org/chromium.googlesource.com/chromiumos/platform/tast.git/src/chromiumos/cmd/tast/run#TestResult
Expand Down Expand Up @@ -479,7 +477,7 @@ def post_run(self, return_code):

if not suite_results.DidRunPass():
return 1
elif return_code:
if return_code:
logging.warning(
'No failed tests found, but exit code of %d was returned from '
'cros_run_test.', return_code)
Expand Down Expand Up @@ -535,7 +533,7 @@ class GTestTest(RemoteTest):
]

def __init__(self, args, unknown_args):
super(GTestTest, self).__init__(args, unknown_args)
super().__init__(args, unknown_args)

self._test_exe = args.test_exe
self._runtime_deps_path = args.runtime_deps_path
Expand Down Expand Up @@ -729,7 +727,6 @@ def device_test(args, unknown_args):
# so cd to src/, which should be the root of all data deps.
os.chdir(CHROMIUM_SRC_PATH)

# pylint: disable=redefined-variable-type
# TODO: Remove the above when depot_tool's pylint is updated to include the
# fix to https://github.com/PyCQA/pylint/issues/710.
if args.test_type == 'tast':
Expand All @@ -747,7 +744,7 @@ def device_test(args, unknown_args):
def host_cmd(args, cmd_args):
if not cmd_args:
raise TestFormatError('Must specify command to run on the host.')
elif args.deploy_chrome and not args.path_to_outdir:
if args.deploy_chrome and not args.path_to_outdir:
raise TestFormatError(
'--path-to-outdir must be specified if --deploy-chrome is passed.')

Expand Down
4 changes: 2 additions & 2 deletions build/chromeos/test_runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import sys
import tempfile
import unittest
import six

# The following non-std imports are fetched via vpython. See the list at
# //.vpython
import mock # pylint: disable=import-error
from parameterized import parameterized # pylint: disable=import-error
import six

import test_runner

Expand Down Expand Up @@ -47,7 +47,7 @@ def safeAssertItemsEqual(self, list1, list2):
if six.PY3:
self.assertSetEqual(set(list1), set(list2))
else:
self.assertItemsEqual(list1, list2)
self.assertCountEqual(list1, list2)


class TastTests(TestRunnerTest):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

def CommonChecks(input_api, output_api):
output = []
output.extend(input_api.canned_checks.RunPylint(input_api, output_api))
output.extend(
input_api.canned_checks.RunPylint(input_api, output_api, version='2.6'))

py_tests = input_api.canned_checks.GetUnitTestsRecursively(
input_api,
Expand Down
10 changes: 5 additions & 5 deletions third_party/android_platform/development/scripts/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def UnzipSymbols(symbolfile, symdir=None):
android_symbols = glob.glob("%s/out/target/product/*/symbols" % symdir)
if android_symbols:
return (symdir, android_symbols[0])
else:
# This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be
# updated to point here.
symbol.CHROME_SYMBOLS_DIR = symdir
return (symdir, symdir)

# This is a zip of Chrome symbols, so symbol.CHROME_SYMBOLS_DIR needs to be
# updated to point here.
symbol.CHROME_SYMBOLS_DIR = symdir
return (symdir, symdir)


def main(argv, test_symbolizer=None):
Expand Down
20 changes: 9 additions & 11 deletions third_party/android_platform/development/scripts/stack_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def PrintTraceLines(trace_lines):
normalized = os.path.normpath(location)
print(' %8s %s %s' % (addr, symbol_with_offset.ljust(maxlen),
normalized))
return


def PrintValueLines(value_lines):
Expand All @@ -132,7 +131,6 @@ def PrintValueLines(value_lines):
(addr, value, symbol_with_offset, location) = vl
print(' %8s %8s %s %s' % (addr, value, symbol_with_offset.ljust(maxlen),
location))
return


def PrintJavaLines(java_lines):
Expand Down Expand Up @@ -274,7 +272,7 @@ def _DetectSharedLibrary(self, lib, symbol_present):
"""
offset_match = _SHARED_LIB_OFFSET_IN_APK.match(symbol_present)
if not offset_match:
return
return None
offset = offset_match.group('offset')
key = '%s:%s' % (lib, offset)
if key in self._shared_libraries_mapping:
Expand Down Expand Up @@ -453,7 +451,7 @@ def ResolveCrashSymbol(lines, more_info, llvm_symbolizer):
pid = -1
last_frame = frame

if area == UNKNOWN or area == HEAP or area == STACK:
if area in (UNKNOWN, HEAP, STACK):
trace_lines.append((code_addr, '', area))
else:
logging.debug('Identified lib: %s' % area)
Expand Down Expand Up @@ -505,11 +503,10 @@ def UpdateLibrarySearchPath(so_dirs):
so_dir_len = len(so_dir)
if so_dir_len > 0:
if so_dir_len > 1:
raise Exception("Found different so dirs, they are %s", repr(so_dir))
else:
search_path = so_dir.pop()
logging.info("Search libraries in %s", search_path)
symbol.SetSecondaryAbiOutputPath(search_path)
raise Exception("Found different so dirs, they are %s" % repr(so_dir))
search_path = so_dir.pop()
logging.info("Search libraries in %s", search_path)
symbol.SetSecondaryAbiOutputPath(search_path)


def GetUncompressedSharedLibraryFromAPK(apkname, offset):
Expand Down Expand Up @@ -594,7 +591,7 @@ def _FindSharedLibraryFromAPKs(output_directory, apks_directory, offset):

if apks_directory:
if not os.path.isdir(apks_directory):
raise Exception('Explicit APKs directory does not exist: %s',
raise Exception('Explicit APKs directory does not exist: %s' %
repr(apks_directory))
else:
apks_directory = os.path.join(output_directory, 'apks')
Expand Down Expand Up @@ -626,7 +623,7 @@ def _FindSharedLibraryFromAPKs(output_directory, apks_directory, offset):
number_of_library = len(shared_libraries)
if number_of_library == 1:
return shared_libraries[0]
elif number_of_library > 1:
if number_of_library > 1:
logging.warning("More than one libraries could be loaded from APK.")
return (None, None)

Expand All @@ -636,3 +633,4 @@ def _FindAbi(lines):
match = _ABI_LINE.search(line)
if match:
return match.group('abi')
return None
9 changes: 6 additions & 3 deletions third_party/android_platform/development/scripts/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def GetCrazyLib(apk_filename):
if match:
return match.group(1)

return None

def GetApkFromLibrary(device_library_path):
match = re.match(r'.*/([^/]*)-[0-9]+(\/[^/]*)?\.apk$', device_library_path)
if not match:
Expand Down Expand Up @@ -192,6 +194,8 @@ def MapDeviceApkToLibrary(device_apk_name):
if crazy_lib:
return crazy_lib

return None


def GetLibrarySearchPaths():
"""Return a list of directories where to find native shared libraries."""
Expand Down Expand Up @@ -280,8 +284,7 @@ def SetSecondaryAbiOutputPath(path):
raise Exception ('SetSecondaryAbiOutputPath() was already called with a ' +
'different value, previous: %s new: %s' % (
_SECONDARY_ABI_OUTPUT_PATH, path))
else:
_SECONDARY_ABI_OUTPUT_PATH = path
_SECONDARY_ABI_OUTPUT_PATH = path


def SymbolInformationForSet(lib, unique_addrs, get_detailed_info,
Expand Down Expand Up @@ -338,7 +341,7 @@ def SymbolInformationForSet(lib, unique_addrs, get_detailed_info,
return result


class _MemoizedForSet(object):
class _MemoizedForSet:
"""Decorator class used to memoize CallXXXForSet() results."""
def __init__(self, fn):
self.fn = fn
Expand Down
3 changes: 2 additions & 1 deletion tools/binary_size/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

def CommonChecks(input_api, output_api):
output = []
output.extend(input_api.canned_checks.RunPylint(input_api, output_api))
output.extend(
input_api.canned_checks.RunPylint(input_api, output_api, version='2.6'))
py_tests = input_api.canned_checks.GetUnitTestsRecursively(
input_api,
output_api,
Expand Down
16 changes: 9 additions & 7 deletions tools/binary_size/diagnose_bloat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
_DiffResult = collections.namedtuple('DiffResult', ['name', 'value', 'units'])


class BaseDiff(object):
class BaseDiff:
"""Base class capturing binary size diffs."""
def __init__(self, name):
self.name = name
Expand Down Expand Up @@ -96,7 +96,7 @@ def __init__(self, size_name, supersize_path):
self._size_name = size_name
self._supersize_path = supersize_path
self._diff = []
super(NativeDiff, self).__init__('Native Diff')
super().__init__('Native Diff')

@property
def summary_stat(self):
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self, filename='results-chart.json', include_sections=None):
self._diff = None # Set by |ProduceDiff()|
self._filename = filename
self._include_sections = include_sections
super(ResourceSizesDiff, self).__init__('Resource Sizes Diff')
super().__init__('Resource Sizes Diff')

@property
def summary_stat(self):
Expand Down Expand Up @@ -230,7 +230,7 @@ def _LoadResults(self, archive_dir):
return ret


class _BuildHelper(object):
class _BuildHelper:
"""Helper class for generating and building targets."""
def __init__(self, args):
self.clean = args.clean
Expand Down Expand Up @@ -401,7 +401,7 @@ def IsLinux(self):
return self.target_os == 'linux'


class _BuildArchive(object):
class _BuildArchive:
"""Class for managing a directory with build results and build metadata."""

def __init__(self, rev, base_archive_dir, build, subrepo, save_unstripped):
Expand Down Expand Up @@ -478,7 +478,7 @@ def _ArchiveSizeFile(self, supersize_path, tool_prefix):
_RunCmd(supersize_cmd)


class _DiffArchiveManager(object):
class _DiffArchiveManager:
"""Class for maintaining BuildArchives and their related diff artifacts."""

def __init__(self, revs, archive_dir, diffs, build, subrepo, save_unstripped):
Expand Down Expand Up @@ -622,7 +622,7 @@ def _DiffDir(self, before, after):
return diff_path


class _Metadata(object):
class _Metadata:

def __init__(self, archives, build, path, subrepo):
self.data = {
Expand Down Expand Up @@ -982,6 +982,8 @@ def main():
0, i, is_internal=args.enable_chrome_android_internal)
diff_mngr.Summarize()

return 0


if __name__ == '__main__':
sys.exit(main())
1 change: 1 addition & 0 deletions tools/binary_size/libsupersize/apkanalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def Normalize(self, class_path, full_name):
'No valid match for new lambda name format: ' + class_path + '\n'
'Please update https://crbug.com/1208385 with this error so we can '
'update the lambda normalization code.')
return None


# Visible for testing.
Expand Down
Loading

0 comments on commit 0686307

Please sign in to comment.