Skip to content

Commit

Permalink
Make build/android presubmit checked with pylint-2.6.
Browse files Browse the repository at this point in the history
Changes:
- omit unnecessary object class.
- python2 superclass call.
- omit unnecessary superclass calls.
- removed obsoleted pylint flags.
- reraised exceptions to use from.
- fixed python2 methods to python3.

Bug: 1262303
Change-Id: I079955a43aa4a0632493a25e8db4b01a2028417d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3313767
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Cr-Commit-Position: refs/heads/main@{#949821}
  • Loading branch information
yoshisatoyanagisawa authored and Chromium LUCI CQ committed Dec 9, 2021
1 parent 6f349b0 commit 9f47779
Show file tree
Hide file tree
Showing 75 changed files with 210 additions and 229 deletions.
6 changes: 4 additions & 2 deletions build/android/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def J(*dirs):
J('..', '..', 'third_party', 'depot_tools'),
J('..', '..', 'third_party', 'colorama', 'src'),
J('..', '..', 'build'),
]))
],
version='2.6'))
tests.extend(
input_api.canned_checks.GetPylint(
input_api,
Expand All @@ -67,7 +68,8 @@ def J(*dirs):
r'.*create_unwind_table\.py',
r'.*create_unwind_table_tests\.py',
],
extra_paths_list=[J('gyp'), J('gn')]))
extra_paths_list=[J('gyp'), J('gn')],
version='2.6'))

tests.extend(
input_api.canned_checks.GetPylint(
Expand Down
12 changes: 6 additions & 6 deletions build/android/apk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ def disk_usage_helper(d):
code_path = re.search(r'codePath=(.*)', package_output).group(1)
lib_path = re.search(r'(?:legacyN|n)ativeLibrary(?:Dir|Path)=(.*)',
package_output).group(1)
except AttributeError:
raise Exception('Error parsing dumpsys output: ' + package_output)
except AttributeError as e:
raise Exception('Error parsing dumpsys output: ' + package_output) from e

if code_path.startswith('/system'):
logging.warning('Measurement of system image apks can be innacurate')
Expand Down Expand Up @@ -536,12 +536,12 @@ def print_sizes(desc, sizes):
print('Total: %s KiB (%.1f MiB)' % (total, total / 1024.0))


class _LogcatProcessor(object):
class _LogcatProcessor:
ParsedLine = collections.namedtuple(
'ParsedLine',
['date', 'invokation_time', 'pid', 'tid', 'priority', 'tag', 'message'])

class NativeStackSymbolizer(object):
class NativeStackSymbolizer:
"""Buffers lines from native stacks and symbolizes them when done."""
# E.g.: #06 pc 0x0000d519 /apex/com.android.runtime/lib/libart.so
# E.g.: #01 pc 00180c8d /data/data/.../lib/libbase.cr.so
Expand Down Expand Up @@ -914,7 +914,7 @@ def _RunProfile(device, package_name, host_build_directory, pprof_out_path,
""" % {'s': pprof_out_path}))


class _StackScriptContext(object):
class _StackScriptContext:
"""Maintains temporary files needed by stack.py."""

def __init__(self,
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def _SaveDeviceCaches(devices, output_directory):
logging.info('Wrote device cache: %s', cache_path)


class _Command(object):
class _Command:
name = None
description = None
long_description = None
Expand Down
10 changes: 5 additions & 5 deletions build/android/convert_dex_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@


@functools.total_ordering
class Method(object):
class Method:
def __init__(self, name, class_name, param_types=None, return_type=None):
self.name = name
self.class_name = class_name
Expand Down Expand Up @@ -100,7 +100,7 @@ def __hash__(self):
return hash((self.name, self.class_name))


class Class(object):
class Class:
def __init__(self, name):
self.name = name
self._methods = []
Expand Down Expand Up @@ -165,7 +165,7 @@ def FindMethodsAtLine(self, method_name, line_start, line_end=None):
return None


class Profile(object):
class Profile:
def __init__(self):
# {Method: set(char)}
self._methods = collections.defaultdict(set)
Expand All @@ -188,7 +188,7 @@ def WriteToFile(self, path):
output_profile.write(line)


class ProguardMapping(object):
class ProguardMapping:
def __init__(self):
# {Method: set(Method)}
self._method_mapping = collections.defaultdict(set)
Expand Down Expand Up @@ -224,7 +224,7 @@ def MapTypeDescriptorList(self, type_descriptor_list):

class MalformedLineException(Exception):
def __init__(self, message, line_number):
super(MalformedLineException, self).__init__(message)
super().__init__(message)
self.line_number = line_number

def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions build/android/dump_apk_resource_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def ReadStringMapFromRTxt(r_txt_path):
return result


class ResourceStringValues(object):
class ResourceStringValues:
"""Models all possible values for a named string."""

def __init__(self):
Expand Down Expand Up @@ -236,7 +236,7 @@ def ToStringList(self, res_id):
return result


class ResourceStringMap(object):
class ResourceStringMap:
"""Convenience class to hold the set of all localized strings in a table.
Usage is the following:
Expand Down
4 changes: 2 additions & 2 deletions build/android/emma_coverage_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
['lineno', 'source', 'covered_status', 'fractional_line_coverage'])


class _EmmaHtmlParser(object):
class _EmmaHtmlParser:
"""Encapsulates HTML file parsing operations.
This class contains all operations related to parsing HTML files that were
Expand Down Expand Up @@ -214,7 +214,7 @@ def _FindElements(self, file_path, xpath_selector):
return root.findall(xpath_selector)


class _EmmaCoverageStats(object):
class _EmmaCoverageStats:
"""Computes code coverage stats for Java code using the coverage tool EMMA.
This class provides an API that allows users to capture absolute code coverage
Expand Down
4 changes: 2 additions & 2 deletions build/android/gradle/generate_gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _QueryForAllGnTargets(output_dir):
return subprocess.check_output(cmd, encoding='UTF-8').splitlines()


class _ProjectEntry(object):
class _ProjectEntry:
"""Helper class for project entries."""

_cached_entries = {}
Expand Down Expand Up @@ -261,7 +261,7 @@ def AllEntries(self):
return self._all_entries


class _ProjectContextGenerator(object):
class _ProjectContextGenerator:
"""Helper class to generate gradle build files"""
def __init__(self, project_dir, build_vars, use_gradle_process_resources,
jinja_processor, split_projects, channel):
Expand Down
6 changes: 3 additions & 3 deletions build/android/gradle/gn_to_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def WriteVariable(output, variable_name, prepend=None):
}


class CMakeTargetType(object):
class CMakeTargetType:
def __init__(self, command, modifier, property_modifier, is_linkable):
self.command = command
self.modifier = modifier
Expand Down Expand Up @@ -186,7 +186,7 @@ def GetCMakeTargetName(gn_target_name):
return CMakeTargetEscape(cmake_target_name)


class Project(object):
class Project:
def __init__(self, project_json):
self.targets = project_json['targets']
build_settings = project_json['build_settings']
Expand Down Expand Up @@ -226,7 +226,7 @@ def GetObjectLibraryDependencies(self, gn_target_name, object_dependencies):
self.GetObjectLibraryDependencies(dependency, object_dependencies)


class Target(object):
class Target:
def __init__(self, gn_target_name, project):
self.gn_name = gn_target_name
self.properties = project.targets[self.gn_name]
Expand Down
4 changes: 2 additions & 2 deletions build/android/gyp/aar.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def main():
except IOError as e:
if not aar_output_present:
raise e
raise Exception('Could not update output file: %s\n%s\n' %
(args.output, e))
raise Exception('Could not update output file: %s\n' % args.output) from e


if __name__ == '__main__':
sys.exit(main())
2 changes: 1 addition & 1 deletion build/android/gyp/compile_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _ProcessJavaFileForInfo(java_file):
return java_file, package_name, class_names


class _InfoFileContext(object):
class _InfoFileContext:
"""Manages the creation of the class->source file .info file."""

def __init__(self, chromium_code, excluded_globs):
Expand Down
10 changes: 5 additions & 5 deletions build/android/gyp/java_cpp_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]


class EnumDefinition(object):
class EnumDefinition:
def __init__(self, original_enum_name=None, class_name_override=None,
enum_package=None, entries=None, comments=None, fixed_type=None):
self.original_enum_name = original_enum_name
Expand Down Expand Up @@ -79,9 +79,9 @@ def _AssignEntryIndices(self):
else:
try:
self.entries[key] = int(value)
except ValueError:
except ValueError as e:
raise Exception('Could not interpret integer from enum value "%s" '
'for key %s.' % (value, key))
'for key %s.' % (value, key)) from e
prev_enum_value = self.entries[key]


Expand Down Expand Up @@ -141,7 +141,7 @@ def _TransformKeys(d, func):
return ret


class DirectiveSet(object):
class DirectiveSet:
class_name_override_key = 'CLASS_NAME_OVERRIDE'
enum_package_key = 'ENUM_PACKAGE'
prefix_to_strip_key = 'PREFIX_TO_STRIP'
Expand Down Expand Up @@ -169,7 +169,7 @@ def UpdateDefinition(self, definition):
DirectiveSet.prefix_to_strip_key)


class HeaderParser(object):
class HeaderParser:
single_line_comment_re = re.compile(r'\s*//\s*([^\n]*)')
multi_line_comment_start_re = re.compile(r'\s*/\*')
enum_line_re = re.compile(r'^\s*(\w+)(\s*\=\s*([^,\n]+))?,?')
Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/jinja_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_source(self, environment, template):
return contents, filename, uptodate


class JinjaProcessor(object):
class JinjaProcessor:
"""Allows easy rendering of jinja templates with input file tracking."""
def __init__(self, loader_base_dir, variables=None):
self.loader_base_dir = loader_base_dir
Expand Down
6 changes: 3 additions & 3 deletions build/android/gyp/proguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _ParseOptions():
return options


class _SplitContext(object):
class _SplitContext:
def __init__(self, name, output_path, input_jars, work_dir, parent_name=None):
self.name = name
self.parent_name = parent_name
Expand Down Expand Up @@ -375,12 +375,12 @@ def _OptimizeWithR8(options,
print_stdout=print_stdout,
stderr_filter=stderr_filter,
fail_on_output=options.warnings_as_errors)
except build_utils.CalledProcessError:
except build_utils.CalledProcessError as e:
# Python will print the original exception as well.
raise Exception(
'R8 failed. Please see '
'https://chromium.googlesource.com/chromium/src/+/HEAD/build/'
'android/docs/java_optimization.md#Debugging-common-failures')
'android/docs/java_optimization.md#Debugging-common-failures') from e

base_has_imported_lib = False
if options.desugar_jdk_libs_json:
Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/util/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class CalledProcessError(Exception):
exits with a non-zero exit code."""

def __init__(self, cwd, args, output):
super(CalledProcessError, self).__init__()
super().__init__()
self.cwd = cwd
self.args = args
self.output = output
Expand Down
6 changes: 3 additions & 3 deletions build/android/gyp/util/java_cpp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def KCamelToShouty(s):
return s.upper()


class JavaString(object):
class JavaString:
def __init__(self, name, value, comments):
self.name = KCamelToShouty(name)
self.value = value
Expand Down Expand Up @@ -67,7 +67,7 @@ def ParseTemplateFile(lines):

# TODO(crbug.com/937282): Work will be needed if we want to annotate specific
# constants in the file to be parsed.
class CppConstantParser(object):
class CppConstantParser:
"""Parses C++ constants, retaining their comments.
The Delegate subclass is responsible for matching and extracting the
Expand All @@ -76,7 +76,7 @@ class CppConstantParser(object):
"""
SINGLE_LINE_COMMENT_RE = re.compile(r'\s*(// [^\n]*)')

class Delegate(object):
class Delegate:
def ExtractConstantName(self, line):
"""Extracts a constant's name from line or None if not a match."""
raise NotImplementedError()
Expand Down
4 changes: 2 additions & 2 deletions build/android/gyp/util/md5_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def CallAndRecordIfStale(function,
new_metadata.ToFile(f)


class Changes(object):
class Changes:
"""Provides and API for querying what changed between runs."""

def __init__(self, old_metadata, new_metadata, force, missing_outputs,
Expand Down Expand Up @@ -294,7 +294,7 @@ def DescribeDifference(self):
return 'I have no idea what changed (there is a bug).'


class _Metadata(object):
class _Metadata:
"""Data model for tracking change metadata.
Args:
Expand Down
8 changes: 4 additions & 4 deletions build/android/gyp/util/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
_fork_kwargs = None


class _ImmediateResult(object):
class _ImmediateResult:
def __init__(self, value):
self._value = value

Expand All @@ -44,7 +44,7 @@ def successful(self):
return True


class _ExceptionWrapper(object):
class _ExceptionWrapper:
"""Used to marshal exception messages back to main process."""

def __init__(self, msg, exception_type=None):
Expand All @@ -57,7 +57,7 @@ def MaybeThrow(self):
self.exception_type)('Originally caused by: ' + self.msg)


class _FuncWrapper(object):
class _FuncWrapper:
"""Runs on the fork()'ed side to catch exceptions and spread *args."""

def __init__(self, func):
Expand All @@ -84,7 +84,7 @@ def __call__(self, index, _=None):
return _ExceptionWrapper(traceback.format_exc())


class _WrappedResult(object):
class _WrappedResult:
"""Allows for host-side logic to be run after child process has terminated.
* Unregisters associated pool _all_pools.
Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/util/protoresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def process_func(filename, data):
_ProcessZip(zip_path, process_func)


class _ResourceStripper(object):
class _ResourceStripper:
def __init__(self, partial_path, keep_predicate):
self.partial_path = partial_path
self.keep_predicate = keep_predicate
Expand Down
4 changes: 2 additions & 2 deletions build/android/gyp/util/resource_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def IterResourceFilesInDirectories(directories,
yield path, archive_path


class ResourceInfoFile(object):
class ResourceInfoFile:
"""Helper for building up .res.info files."""

def __init__(self):
Expand Down Expand Up @@ -889,7 +889,7 @@ def ExtractDeps(dep_zips, deps_dir):
return dep_subdirs


class _ResourceBuildContext(object):
class _ResourceBuildContext:
"""A temporary directory for packaging and compiling Android resources.
Args:
Expand Down
Loading

0 comments on commit 9f47779

Please sign in to comment.