From c410d2e1a1fdd8198e31ec0cd7fa4130368463c2 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Mon, 9 Jul 2018 15:28:22 +0100 Subject: [PATCH] I lint, therefore I am Implement fixes for the most recent pylint version. --- wa/__init__.py | 2 +- wa/commands/process.py | 2 +- wa/commands/run.py | 2 +- wa/framework/exception.py | 2 +- wa/framework/execution.py | 10 +++++----- wa/framework/instrument.py | 4 ++-- wa/framework/workload.py | 21 ++++++++++----------- wa/instruments/fps.py | 1 - wa/output_processors/cpustates.py | 2 +- wa/output_processors/csvproc.py | 7 ++++--- wa/output_processors/sqlite.py | 1 - wa/output_processors/status.py | 3 ++- wa/utils/android.py | 3 +-- wa/utils/cpustates.py | 7 +++---- wa/utils/log.py | 2 +- wa/utils/misc.py | 6 ++++-- wa/utils/serializer.py | 6 +++--- wa/utils/trace_cmd.py | 2 +- wa/utils/types.py | 4 ++-- wa/workloads/antutu/__init__.py | 2 +- wa/workloads/exoplayer/__init__.py | 8 ++++---- wa/workloads/vellamo/__init__.py | 7 +++++-- 22 files changed, 53 insertions(+), 51 deletions(-) diff --git a/wa/__init__.py b/wa/__init__.py index 455ab7c7..a47792ce 100644 --- a/wa/__init__.py +++ b/wa/__init__.py @@ -17,7 +17,7 @@ from wa.framework import pluginloader, signal from wa.framework.command import Command, ComplexCommand, SubCommand from wa.framework.configuration import settings from wa.framework.configuration.core import Status -from wa.framework.exception import (CommandError, ConfigError, HostError, InstrumentError, +from wa.framework.exception import (CommandError, ConfigError, HostError, InstrumentError, #pylint: disable=redefined-builtin JobError, NotFoundError, OutputProcessorError, PluginLoaderError, ResourceError, TargetError, TargetNotRespondingError, TimeoutError, ToolError, diff --git a/wa/commands/process.py b/wa/commands/process.py index b6d9e6f9..46bf31ea 100644 --- a/wa/commands/process.py +++ b/wa/commands/process.py @@ -64,7 +64,7 @@ class ProcessCommand(Command): instead of just processing the root. """) - def execute(self, config, args): + def execute(self, config, args): # pylint: disable=arguments-differ,too-many-branches,too-many-statements process_directory = os.path.expandvars(args.directory) self.logger.debug('Using process directory: {}'.format(process_directory)) if not os.path.exists(process_directory): diff --git a/wa/commands/run.py b/wa/commands/run.py index 4901b25e..6459ac91 100644 --- a/wa/commands/run.py +++ b/wa/commands/run.py @@ -84,7 +84,7 @@ class RunCommand(Command): be specified multiple times. """) - def execute(self, config, args): + def execute(self, config, args): # pylint: disable=arguments-differ output = self.set_up_output_directory(config, args) log.add_file(output.logfile) output.add_artifact('runlog', output.logfile, kind='log', diff --git a/wa/framework/exception.py b/wa/framework/exception.py index 4a6cff2e..ee17a50e 100644 --- a/wa/framework/exception.py +++ b/wa/framework/exception.py @@ -13,7 +13,7 @@ # limitations under the License. # # pylint: disable=unused-import -from devlib.exception import (DevlibError, HostError, TimeoutError, +from devlib.exception import (DevlibError, HostError, TimeoutError, # pylint: disable=redefined-builtin TargetError, TargetNotRespondingError) from wa.utils.misc import get_traceback diff --git a/wa/framework/execution.py b/wa/framework/execution.py index 9e1d99fb..1c80f181 100644 --- a/wa/framework/execution.py +++ b/wa/framework/execution.py @@ -26,7 +26,7 @@ import wa.framework.signal as signal from wa.framework import instrument from wa.framework.configuration.core import Status from wa.framework.exception import TargetError, HostError, WorkloadError -from wa.framework.exception import TargetNotRespondingError, TimeoutError +from wa.framework.exception import TargetNotRespondingError, TimeoutError # pylint: disable=redefined-builtin from wa.framework.job import Job from wa.framework.output import init_job_output from wa.framework.output_processor import ProcessorManager @@ -437,11 +437,11 @@ class Executor(object): self.logger.info('Results can be found in {}'.format(output.basepath)) if self.error_logged: - self.logger.warn('There were errors during execution.') - self.logger.warn('Please see {}'.format(output.logfile)) + self.logger.warning('There were errors during execution.') + self.logger.warning('Please see {}'.format(output.logfile)) elif self.warning_logged: - self.logger.warn('There were warnings during execution.') - self.logger.warn('Please see {}'.format(output.logfile)) + self.logger.warning('There were warnings during execution.') + self.logger.warning('Please see {}'.format(output.logfile)) def _error_signalled_callback(self, _): self.error_logged = True diff --git a/wa/framework/instrument.py b/wa/framework/instrument.py index f5e5e76a..d13f63e7 100644 --- a/wa/framework/instrument.py +++ b/wa/framework/instrument.py @@ -104,7 +104,7 @@ from collections import OrderedDict from wa.framework import signal from wa.framework.plugin import Plugin -from wa.framework.exception import (TargetNotRespondingError, TimeoutError, +from wa.framework.exception import (TargetNotRespondingError, TimeoutError, # pylint: disable=redefined-builtin WorkloadError, TargetError) from wa.utils.log import log_error from wa.utils.misc import isiterable @@ -324,7 +324,7 @@ def install(instrument, context): if not callable(attr): msg = 'Attribute {} not callable in {}.' raise ValueError(msg.format(attr_name, instrument)) - argspec = inspect.getargspec(attr) + argspec = inspect.getfullargspec(attr) arg_num = len(argspec.args) # Instrument callbacks will be passed exactly two arguments: self # (the instrument instance to which the callback is bound) and diff --git a/wa/framework/workload.py b/wa/framework/workload.py index f2c655b5..9e76738e 100644 --- a/wa/framework/workload.py +++ b/wa/framework/workload.py @@ -16,8 +16,7 @@ import logging import os import time -from wa import Parameter -from wa.framework.plugin import TargetedPlugin +from wa.framework.plugin import TargetedPlugin, Parameter from wa.framework.resource import (ApkFile, ReventFile, File, loose_version_matching) from wa.framework.exception import WorkloadError, ConfigError @@ -78,7 +77,7 @@ class Workload(TargetedPlugin): raise WorkloadError(msg.format(self.name, ' '.join(self.supported_platforms), self.target.os)) - def init_resources(self, resolver): + def init_resources(self, context): """ This method may be used to perform early resource discovery and initialization. This is invoked during the initial loading stage and @@ -88,7 +87,7 @@ class Workload(TargetedPlugin): """ for asset in self.deployable_assets: - self.asset_files.append(resolver.get(File(self, asset))) + self.asset_files.append(context.get(File(self, asset))) @once_per_instance def initialize(self, context): @@ -298,9 +297,9 @@ class ApkUIWorkload(ApkWorkload): super(ApkUIWorkload, self).__init__(target, **kwargs) self.gui = None - def init_resources(self, resolver): - super(ApkUIWorkload, self).init_resources(resolver) - self.gui.init_resources(resolver) + def init_resources(self, context): + super(ApkUIWorkload, self).init_resources(context) + self.gui.init_resources(context) @once_per_instance def initialize(self, context): @@ -378,9 +377,9 @@ class UIWorkload(Workload): super(UIWorkload, self).__init__(target, **kwargs) self.gui = None - def init_resources(self, resolver): - super(UIWorkload, self).init_resources(resolver) - self.gui.init_resources(resolver) + def init_resources(self, context): + super(UIWorkload, self).init_resources(context) + self.gui.init_resources(context) @once_per_instance def initialize(self, context): @@ -819,7 +818,7 @@ class PackageHandler(object): if 'Failure' in output: if 'ALREADY_EXISTS' in output: msg = 'Using already installed APK (did not uninstall properly?)' - self.logger.warn(msg) + self.logger.warning(msg) else: raise WorkloadError(output) else: diff --git a/wa/instruments/fps.py b/wa/instruments/fps.py index 2cc780b5..2c5dbc9a 100644 --- a/wa/instruments/fps.py +++ b/wa/instruments/fps.py @@ -119,7 +119,6 @@ class FpsInstrument(Instrument): return self._is_enabled = True - # pylint: disable=redefined-variable-type if use_gfxinfo: self.collector = GfxInfoFramesInstrument(self.target, collector_target, self.period) self.processor = DerivedGfxInfoStats(self.drop_threshold, filename='fps.csv') diff --git a/wa/output_processors/cpustates.py b/wa/output_processors/cpustates.py index 632c142b..7ab022df 100755 --- a/wa/output_processors/cpustates.py +++ b/wa/output_processors/cpustates.py @@ -86,7 +86,7 @@ class CpuStatesProcessor(OutputProcessor): ] def initialize(self): - self.iteration_reports = OrderedDict() + self.iteration_reports = OrderedDict() # pylint: disable=attribute-defined-outside-init def process_job_output(self, output, target_info, run_output): # pylint: disable=unused-argument trace_file = output.get_artifact_path('trace-cmd-txt') diff --git a/wa/output_processors/csvproc.py b/wa/output_processors/csvproc.py index 0d21cd51..884f6542 100644 --- a/wa/output_processors/csvproc.py +++ b/wa/output_processors/csvproc.py @@ -57,7 +57,8 @@ class CsvReportProcessor(OutputProcessor): raise ConfigError(msg) def initialize(self): - self.outputs_so_far = [] # pylint: disable=attribute-defined-outside-init + # pylint: disable=attribute-defined-outside-init + self.outputs_so_far = [] self.artifact_added = False # pylint: disable=unused-argument @@ -66,14 +67,14 @@ class CsvReportProcessor(OutputProcessor): self._write_outputs(self.outputs_so_far, run_output) if not self.artifact_added: run_output.add_artifact('run_result_csv', 'results.csv', 'export') - self.artifact_added = True + self.artifact_added = True # pylint: disable=attribute-defined-outside-init def process_run_output(self, output, target_info): # pylint: disable=unused-argument self.outputs_so_far.append(output) self._write_outputs(self.outputs_so_far, output) if not self.artifact_added: output.add_artifact('run_result_csv', 'results.csv', 'export') - self.artifact_added = True + self.artifact_added = True # pylint: disable=attribute-defined-outside-init def _write_outputs(self, outputs, output): if self.use_all_classifiers: diff --git a/wa/output_processors/sqlite.py b/wa/output_processors/sqlite.py index 6be3de77..1064a4a3 100644 --- a/wa/output_processors/sqlite.py +++ b/wa/output_processors/sqlite.py @@ -22,7 +22,6 @@ from datetime import datetime, timedelta from contextlib import contextmanager from wa import OutputProcessor, Parameter, OutputProcessorError -from wa.framework.exception import OutputProcessorError from wa.utils.serializer import json from wa.utils.types import boolean diff --git a/wa/output_processors/status.py b/wa/output_processors/status.py index 1e9ac816..cad39191 100644 --- a/wa/output_processors/status.py +++ b/wa/output_processors/status.py @@ -18,7 +18,8 @@ import time from collections import Counter -from wa import OutputProcessor, Status +from wa.framework.output import Status +from wa.framework.output_processor import OutputProcessor from wa.utils.misc import write_table diff --git a/wa/utils/android.py b/wa/utils/android.py index 7735e9f5..d6e3f829 100644 --- a/wa/utils/android.py +++ b/wa/utils/android.py @@ -72,10 +72,9 @@ class LogcatParser(object): tid = int(parts.pop(0)) level = LogcatLogLevel.levels[log_level_map.index(parts.pop(0))] tag = (parts.pop(0) if parts else '').strip() - except Exception as e: + except Exception as e: # pylint: disable=broad-except message = 'Invalid metadata for line:\n\t{}\n\tgot: "{}"' logger.warning(message.format(line, e)) return None return LogcatEvent(timestamp, pid, tid, level, tag, message) - diff --git a/wa/utils/cpustates.py b/wa/utils/cpustates.py index 2de3b471..e1275420 100755 --- a/wa/utils/cpustates.py +++ b/wa/utils/cpustates.py @@ -449,7 +449,7 @@ class ParallelStats(object): running_time_pc *= 100 else: running_time_pc = 0 - precision = self.use_ratios and 3 or 1 + precision = 3 if self.use_ratios else 1 fmt = '{{:.{}f}}'.format(precision) report.add([cluster, n, fmt.format(time), @@ -524,7 +524,7 @@ class PowerStateStats(object): time_pc *= 100 state_stats[state][cpu] = time_pc - precision = self.use_ratios and 3 or 1 + precision = 3 if self.use_ratios else 1 return PowerStateStatsReport(self.filepath, state_stats, self.core_names, precision) @@ -592,7 +592,7 @@ def build_idle_state_map(cpus): return idle_state_map -def report_power_stats(trace_file, cpus, output_basedir, use_ratios=False, no_idle=None, +def report_power_stats(trace_file, cpus, output_basedir, use_ratios=False, no_idle=None, # pylint: disable=too-many-locals split_wfi_states=False): """ Process trace-cmd output to generate timelines and statistics of CPU power @@ -704,4 +704,3 @@ def report_power_stats(trace_file, cpus, output_basedir, use_ratios=False, no_id report.write() reports[report.name] = report return reports - diff --git a/wa/utils/log.py b/wa/utils/log.py index 332a2974..5b4e18e0 100644 --- a/wa/utils/log.py +++ b/wa/utils/log.py @@ -193,7 +193,7 @@ def log_error(e, logger, critical=False): old_level = set_indent_level(0) logger.info('Got CTRL-C. Aborting.') set_indent_level(old_level) - elif isinstance(e, WAError) or isinstance(e, DevlibError): + elif isinstance(e, (WAError, DevlibError)): log_func(str(e)) elif isinstance(e, subprocess.CalledProcessError): tb = get_traceback() diff --git a/wa/utils/misc.py b/wa/utils/misc.py index df82ab19..4ca024ce 100644 --- a/wa/utils/misc.py +++ b/wa/utils/misc.py @@ -31,11 +31,13 @@ import subprocess import sys import traceback from datetime import datetime, timedelta +from functools import reduce from operator import mul if sys.version_info[0] == 3: from io import StringIO else: from io import BytesIO as StringIO +# pylint: disable=wrong-import-position,unused-import from itertools import chain, cycle from distutils.spawn import find_executable @@ -257,13 +259,13 @@ def format_duration(seconds, sep=' ', order=['day', 'hour', 'minute', 'second']) result = [] for item in order: value = getattr(dt, item, None) - if item is 'day': + if item == 'day': value -= 1 if not value: continue suffix = '' if value == 1 else 's' result.append('{} {}{}'.format(value, item, suffix)) - return result and sep.join(result) or 'N/A' + return sep.join(result) if result else 'N/A' def get_article(word): diff --git a/wa/utils/serializer.py b/wa/utils/serializer.py index 9e1da1c4..4fa7c510 100644 --- a/wa/utils/serializer.py +++ b/wa/utils/serializer.py @@ -66,7 +66,7 @@ import yaml as _yaml import dateutil.parser # pylint: disable=redefined-builtin -from past.builtins import basestring +from past.builtins import basestring # pylint: disable=wrong-import-order from wa.framework.exception import SerializerSyntaxError from wa.utils.misc import isiterable @@ -104,7 +104,7 @@ POD_TYPES = [ class WAJSONEncoder(_json.JSONEncoder): - def default(self, obj): # pylint: disable=method-hidden + def default(self, obj): # pylint: disable=method-hidden,arguments-differ if isinstance(obj, regex_type): return 'REGEX:{}:{}'.format(obj.flags, obj.pattern) elif isinstance(obj, datetime): @@ -119,7 +119,7 @@ class WAJSONEncoder(_json.JSONEncoder): class WAJSONDecoder(_json.JSONDecoder): - def decode(self, s, **kwargs): + def decode(self, s, **kwargs): # pylint: disable=arguments-differ d = _json.JSONDecoder.decode(self, s, **kwargs) def try_parse_object(v): diff --git a/wa/utils/trace_cmd.py b/wa/utils/trace_cmd.py index fc503615..121438a4 100644 --- a/wa/utils/trace_cmd.py +++ b/wa/utils/trace_cmd.py @@ -323,7 +323,7 @@ class TraceCmdParser(object): continue body_parser = EVENT_PARSER_MAP.get(event_name, default_body_parser) - if isinstance(body_parser, str) or isinstance(body_parser, re._pattern_type): # pylint: disable=protected-access + if isinstance(body_parser, (str, re._pattern_type)): # pylint: disable=protected-access body_parser = regex_body_parser(body_parser) yield TraceCmdEvent(parser=body_parser, **match.groupdict()) diff --git a/wa/utils/types.py b/wa/utils/types.py index 7495c9e3..8be8d107 100644 --- a/wa/utils/types.py +++ b/wa/utils/types.py @@ -36,7 +36,7 @@ if sys.version_info[0] == 3: from past.builtins import basestring # pylint: disable=redefined-builtin long = int else: - from urllib import quote, unquote + from urllib import quote, unquote # pylint: disable=no-name-in-module # pylint: disable=wrong-import-position from collections import defaultdict, MutableMapping from copy import copy @@ -325,7 +325,7 @@ class prioritylist(object): def _delete(self, priority, priority_index): del self.elements[priority][priority_index] self.size -= 1 - if len(self.elements[priority]) == 0: + if not self.elements[priority]: self.priorities.remove(priority) self._cached_elements = None diff --git a/wa/workloads/antutu/__init__.py b/wa/workloads/antutu/__init__.py index fd47e7b9..3a01a868 100755 --- a/wa/workloads/antutu/__init__.py +++ b/wa/workloads/antutu/__init__.py @@ -55,7 +55,7 @@ class Antutu(ApkUiautoWorkload): try: result = float(match.group(1)) except ValueError: - result = 'NaN' # pylint: disable=redefined-variable-type + result = float('NaN') entry = regex.pattern.rsplit(None, 1)[0] context.add_metric(entry, result, lower_is_better=False) expected_results -= 1 diff --git a/wa/workloads/exoplayer/__init__.py b/wa/workloads/exoplayer/__init__.py index 23436edb..64064b5c 100644 --- a/wa/workloads/exoplayer/__init__.py +++ b/wa/workloads/exoplayer/__init__.py @@ -150,10 +150,10 @@ class ExoPlayer(ApkWorkload): return filepath else: if len(files) > 1: - self.logger.warn('Multiple files found for {} format. Using {}.' - .format(self.format, files[0])) - self.logger.warn('Use "filename"parameter instead of ' - '"format" to specify a different file.') + self.logger.warning('Multiple files found for {} format. Using {}.' + .format(self.format, files[0])) + self.logger.warning('Use "filename"parameter instead of ' + '"format" to specify a different file.') return files[0] def init_resources(self, context): # pylint: disable=unused-argument diff --git a/wa/workloads/vellamo/__init__.py b/wa/workloads/vellamo/__init__.py index 2f7d1878..c8a4b76e 100644 --- a/wa/workloads/vellamo/__init__.py +++ b/wa/workloads/vellamo/__init__.py @@ -193,9 +193,9 @@ class VellamoResultParser(HTMLParser): self.failed = False self.benchmarks = [] - def feed(self, text): + def feed(self, data): try: - HTMLParser.feed(self, text) + HTMLParser.feed(self, data) except self.StopParsingException: pass @@ -230,3 +230,6 @@ class VellamoResultParser(HTMLParser): self.benchmarks[-1].add_metric(data) else: self.failed = True + + def error(self, message): + raise WorkloadError('Error parsing raw output: {}'.format(message))