1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

I lint, therefore I am

Implement fixes for the most recent pylint version.
This commit is contained in:
Sergei Trofimov 2018-07-09 15:28:22 +01:00 committed by Marc Bonnici
parent 0e0d4e0ff0
commit c410d2e1a1
22 changed files with 53 additions and 51 deletions

View File

@ -17,7 +17,7 @@ from wa.framework import pluginloader, signal
from wa.framework.command import Command, ComplexCommand, SubCommand from wa.framework.command import Command, ComplexCommand, SubCommand
from wa.framework.configuration import settings from wa.framework.configuration import settings
from wa.framework.configuration.core import Status 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, JobError, NotFoundError, OutputProcessorError,
PluginLoaderError, ResourceError, TargetError, PluginLoaderError, ResourceError, TargetError,
TargetNotRespondingError, TimeoutError, ToolError, TargetNotRespondingError, TimeoutError, ToolError,

View File

@ -64,7 +64,7 @@ class ProcessCommand(Command):
instead of just processing the root. 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) process_directory = os.path.expandvars(args.directory)
self.logger.debug('Using process directory: {}'.format(process_directory)) self.logger.debug('Using process directory: {}'.format(process_directory))
if not os.path.exists(process_directory): if not os.path.exists(process_directory):

View File

@ -84,7 +84,7 @@ class RunCommand(Command):
be specified multiple times. 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) output = self.set_up_output_directory(config, args)
log.add_file(output.logfile) log.add_file(output.logfile)
output.add_artifact('runlog', output.logfile, kind='log', output.add_artifact('runlog', output.logfile, kind='log',

View File

@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
# #
# pylint: disable=unused-import # pylint: disable=unused-import
from devlib.exception import (DevlibError, HostError, TimeoutError, from devlib.exception import (DevlibError, HostError, TimeoutError, # pylint: disable=redefined-builtin
TargetError, TargetNotRespondingError) TargetError, TargetNotRespondingError)
from wa.utils.misc import get_traceback from wa.utils.misc import get_traceback

View File

@ -26,7 +26,7 @@ import wa.framework.signal as signal
from wa.framework import instrument from wa.framework import instrument
from wa.framework.configuration.core import Status from wa.framework.configuration.core import Status
from wa.framework.exception import TargetError, HostError, WorkloadError 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.job import Job
from wa.framework.output import init_job_output from wa.framework.output import init_job_output
from wa.framework.output_processor import ProcessorManager 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)) self.logger.info('Results can be found in {}'.format(output.basepath))
if self.error_logged: if self.error_logged:
self.logger.warn('There were errors during execution.') self.logger.warning('There were errors during execution.')
self.logger.warn('Please see {}'.format(output.logfile)) self.logger.warning('Please see {}'.format(output.logfile))
elif self.warning_logged: elif self.warning_logged:
self.logger.warn('There were warnings during execution.') self.logger.warning('There were warnings during execution.')
self.logger.warn('Please see {}'.format(output.logfile)) self.logger.warning('Please see {}'.format(output.logfile))
def _error_signalled_callback(self, _): def _error_signalled_callback(self, _):
self.error_logged = True self.error_logged = True

View File

@ -104,7 +104,7 @@ from collections import OrderedDict
from wa.framework import signal from wa.framework import signal
from wa.framework.plugin import Plugin 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) WorkloadError, TargetError)
from wa.utils.log import log_error from wa.utils.log import log_error
from wa.utils.misc import isiterable from wa.utils.misc import isiterable
@ -324,7 +324,7 @@ def install(instrument, context):
if not callable(attr): if not callable(attr):
msg = 'Attribute {} not callable in {}.' msg = 'Attribute {} not callable in {}.'
raise ValueError(msg.format(attr_name, instrument)) raise ValueError(msg.format(attr_name, instrument))
argspec = inspect.getargspec(attr) argspec = inspect.getfullargspec(attr)
arg_num = len(argspec.args) arg_num = len(argspec.args)
# Instrument callbacks will be passed exactly two arguments: self # Instrument callbacks will be passed exactly two arguments: self
# (the instrument instance to which the callback is bound) and # (the instrument instance to which the callback is bound) and

View File

@ -16,8 +16,7 @@ import logging
import os import os
import time import time
from wa import Parameter from wa.framework.plugin import TargetedPlugin, Parameter
from wa.framework.plugin import TargetedPlugin
from wa.framework.resource import (ApkFile, ReventFile, from wa.framework.resource import (ApkFile, ReventFile,
File, loose_version_matching) File, loose_version_matching)
from wa.framework.exception import WorkloadError, ConfigError from wa.framework.exception import WorkloadError, ConfigError
@ -78,7 +77,7 @@ class Workload(TargetedPlugin):
raise WorkloadError(msg.format(self.name, ' '.join(self.supported_platforms), raise WorkloadError(msg.format(self.name, ' '.join(self.supported_platforms),
self.target.os)) self.target.os))
def init_resources(self, resolver): def init_resources(self, context):
""" """
This method may be used to perform early resource discovery and This method may be used to perform early resource discovery and
initialization. This is invoked during the initial loading stage and initialization. This is invoked during the initial loading stage and
@ -88,7 +87,7 @@ class Workload(TargetedPlugin):
""" """
for asset in self.deployable_assets: 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 @once_per_instance
def initialize(self, context): def initialize(self, context):
@ -298,9 +297,9 @@ class ApkUIWorkload(ApkWorkload):
super(ApkUIWorkload, self).__init__(target, **kwargs) super(ApkUIWorkload, self).__init__(target, **kwargs)
self.gui = None self.gui = None
def init_resources(self, resolver): def init_resources(self, context):
super(ApkUIWorkload, self).init_resources(resolver) super(ApkUIWorkload, self).init_resources(context)
self.gui.init_resources(resolver) self.gui.init_resources(context)
@once_per_instance @once_per_instance
def initialize(self, context): def initialize(self, context):
@ -378,9 +377,9 @@ class UIWorkload(Workload):
super(UIWorkload, self).__init__(target, **kwargs) super(UIWorkload, self).__init__(target, **kwargs)
self.gui = None self.gui = None
def init_resources(self, resolver): def init_resources(self, context):
super(UIWorkload, self).init_resources(resolver) super(UIWorkload, self).init_resources(context)
self.gui.init_resources(resolver) self.gui.init_resources(context)
@once_per_instance @once_per_instance
def initialize(self, context): def initialize(self, context):
@ -819,7 +818,7 @@ class PackageHandler(object):
if 'Failure' in output: if 'Failure' in output:
if 'ALREADY_EXISTS' in output: if 'ALREADY_EXISTS' in output:
msg = 'Using already installed APK (did not uninstall properly?)' msg = 'Using already installed APK (did not uninstall properly?)'
self.logger.warn(msg) self.logger.warning(msg)
else: else:
raise WorkloadError(output) raise WorkloadError(output)
else: else:

View File

@ -119,7 +119,6 @@ class FpsInstrument(Instrument):
return return
self._is_enabled = True self._is_enabled = True
# pylint: disable=redefined-variable-type
if use_gfxinfo: if use_gfxinfo:
self.collector = GfxInfoFramesInstrument(self.target, collector_target, self.period) self.collector = GfxInfoFramesInstrument(self.target, collector_target, self.period)
self.processor = DerivedGfxInfoStats(self.drop_threshold, filename='fps.csv') self.processor = DerivedGfxInfoStats(self.drop_threshold, filename='fps.csv')

View File

@ -86,7 +86,7 @@ class CpuStatesProcessor(OutputProcessor):
] ]
def initialize(self): 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 def process_job_output(self, output, target_info, run_output): # pylint: disable=unused-argument
trace_file = output.get_artifact_path('trace-cmd-txt') trace_file = output.get_artifact_path('trace-cmd-txt')

View File

@ -57,7 +57,8 @@ class CsvReportProcessor(OutputProcessor):
raise ConfigError(msg) raise ConfigError(msg)
def initialize(self): 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 self.artifact_added = False
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -66,14 +67,14 @@ class CsvReportProcessor(OutputProcessor):
self._write_outputs(self.outputs_so_far, run_output) self._write_outputs(self.outputs_so_far, run_output)
if not self.artifact_added: if not self.artifact_added:
run_output.add_artifact('run_result_csv', 'results.csv', 'export') 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 def process_run_output(self, output, target_info): # pylint: disable=unused-argument
self.outputs_so_far.append(output) self.outputs_so_far.append(output)
self._write_outputs(self.outputs_so_far, output) self._write_outputs(self.outputs_so_far, output)
if not self.artifact_added: if not self.artifact_added:
output.add_artifact('run_result_csv', 'results.csv', 'export') 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): def _write_outputs(self, outputs, output):
if self.use_all_classifiers: if self.use_all_classifiers:

View File

@ -22,7 +22,6 @@ from datetime import datetime, timedelta
from contextlib import contextmanager from contextlib import contextmanager
from wa import OutputProcessor, Parameter, OutputProcessorError from wa import OutputProcessor, Parameter, OutputProcessorError
from wa.framework.exception import OutputProcessorError
from wa.utils.serializer import json from wa.utils.serializer import json
from wa.utils.types import boolean from wa.utils.types import boolean

View File

@ -18,7 +18,8 @@
import time import time
from collections import Counter 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 from wa.utils.misc import write_table

View File

@ -72,10 +72,9 @@ class LogcatParser(object):
tid = int(parts.pop(0)) tid = int(parts.pop(0))
level = LogcatLogLevel.levels[log_level_map.index(parts.pop(0))] level = LogcatLogLevel.levels[log_level_map.index(parts.pop(0))]
tag = (parts.pop(0) if parts else '').strip() 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: "{}"' message = 'Invalid metadata for line:\n\t{}\n\tgot: "{}"'
logger.warning(message.format(line, e)) logger.warning(message.format(line, e))
return None return None
return LogcatEvent(timestamp, pid, tid, level, tag, message) return LogcatEvent(timestamp, pid, tid, level, tag, message)

View File

@ -449,7 +449,7 @@ class ParallelStats(object):
running_time_pc *= 100 running_time_pc *= 100
else: else:
running_time_pc = 0 running_time_pc = 0
precision = self.use_ratios and 3 or 1 precision = 3 if self.use_ratios else 1
fmt = '{{:.{}f}}'.format(precision) fmt = '{{:.{}f}}'.format(precision)
report.add([cluster, n, report.add([cluster, n,
fmt.format(time), fmt.format(time),
@ -524,7 +524,7 @@ class PowerStateStats(object):
time_pc *= 100 time_pc *= 100
state_stats[state][cpu] = time_pc 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) return PowerStateStatsReport(self.filepath, state_stats, self.core_names, precision)
@ -592,7 +592,7 @@ def build_idle_state_map(cpus):
return idle_state_map 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): split_wfi_states=False):
""" """
Process trace-cmd output to generate timelines and statistics of CPU power 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() report.write()
reports[report.name] = report reports[report.name] = report
return reports return reports

View File

@ -193,7 +193,7 @@ def log_error(e, logger, critical=False):
old_level = set_indent_level(0) old_level = set_indent_level(0)
logger.info('Got CTRL-C. Aborting.') logger.info('Got CTRL-C. Aborting.')
set_indent_level(old_level) set_indent_level(old_level)
elif isinstance(e, WAError) or isinstance(e, DevlibError): elif isinstance(e, (WAError, DevlibError)):
log_func(str(e)) log_func(str(e))
elif isinstance(e, subprocess.CalledProcessError): elif isinstance(e, subprocess.CalledProcessError):
tb = get_traceback() tb = get_traceback()

View File

@ -31,11 +31,13 @@ import subprocess
import sys import sys
import traceback import traceback
from datetime import datetime, timedelta from datetime import datetime, timedelta
from functools import reduce
from operator import mul from operator import mul
if sys.version_info[0] == 3: if sys.version_info[0] == 3:
from io import StringIO from io import StringIO
else: else:
from io import BytesIO as StringIO from io import BytesIO as StringIO
# pylint: disable=wrong-import-position,unused-import
from itertools import chain, cycle from itertools import chain, cycle
from distutils.spawn import find_executable from distutils.spawn import find_executable
@ -257,13 +259,13 @@ def format_duration(seconds, sep=' ', order=['day', 'hour', 'minute', 'second'])
result = [] result = []
for item in order: for item in order:
value = getattr(dt, item, None) value = getattr(dt, item, None)
if item is 'day': if item == 'day':
value -= 1 value -= 1
if not value: if not value:
continue continue
suffix = '' if value == 1 else 's' suffix = '' if value == 1 else 's'
result.append('{} {}{}'.format(value, item, suffix)) 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): def get_article(word):

View File

@ -66,7 +66,7 @@ import yaml as _yaml
import dateutil.parser import dateutil.parser
# pylint: disable=redefined-builtin # 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.framework.exception import SerializerSyntaxError
from wa.utils.misc import isiterable from wa.utils.misc import isiterable
@ -104,7 +104,7 @@ POD_TYPES = [
class WAJSONEncoder(_json.JSONEncoder): 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): if isinstance(obj, regex_type):
return 'REGEX:{}:{}'.format(obj.flags, obj.pattern) return 'REGEX:{}:{}'.format(obj.flags, obj.pattern)
elif isinstance(obj, datetime): elif isinstance(obj, datetime):
@ -119,7 +119,7 @@ class WAJSONEncoder(_json.JSONEncoder):
class WAJSONDecoder(_json.JSONDecoder): 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) d = _json.JSONDecoder.decode(self, s, **kwargs)
def try_parse_object(v): def try_parse_object(v):

View File

@ -323,7 +323,7 @@ class TraceCmdParser(object):
continue continue
body_parser = EVENT_PARSER_MAP.get(event_name, default_body_parser) 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) body_parser = regex_body_parser(body_parser)
yield TraceCmdEvent(parser=body_parser, **match.groupdict()) yield TraceCmdEvent(parser=body_parser, **match.groupdict())

View File

@ -36,7 +36,7 @@ if sys.version_info[0] == 3:
from past.builtins import basestring # pylint: disable=redefined-builtin from past.builtins import basestring # pylint: disable=redefined-builtin
long = int long = int
else: else:
from urllib import quote, unquote from urllib import quote, unquote # pylint: disable=no-name-in-module
# pylint: disable=wrong-import-position # pylint: disable=wrong-import-position
from collections import defaultdict, MutableMapping from collections import defaultdict, MutableMapping
from copy import copy from copy import copy
@ -325,7 +325,7 @@ class prioritylist(object):
def _delete(self, priority, priority_index): def _delete(self, priority, priority_index):
del self.elements[priority][priority_index] del self.elements[priority][priority_index]
self.size -= 1 self.size -= 1
if len(self.elements[priority]) == 0: if not self.elements[priority]:
self.priorities.remove(priority) self.priorities.remove(priority)
self._cached_elements = None self._cached_elements = None

View File

@ -55,7 +55,7 @@ class Antutu(ApkUiautoWorkload):
try: try:
result = float(match.group(1)) result = float(match.group(1))
except ValueError: except ValueError:
result = 'NaN' # pylint: disable=redefined-variable-type result = float('NaN')
entry = regex.pattern.rsplit(None, 1)[0] entry = regex.pattern.rsplit(None, 1)[0]
context.add_metric(entry, result, lower_is_better=False) context.add_metric(entry, result, lower_is_better=False)
expected_results -= 1 expected_results -= 1

View File

@ -150,10 +150,10 @@ class ExoPlayer(ApkWorkload):
return filepath return filepath
else: else:
if len(files) > 1: if len(files) > 1:
self.logger.warn('Multiple files found for {} format. Using {}.' self.logger.warning('Multiple files found for {} format. Using {}.'
.format(self.format, files[0])) .format(self.format, files[0]))
self.logger.warn('Use "filename"parameter instead of ' self.logger.warning('Use "filename"parameter instead of '
'"format" to specify a different file.') '"format" to specify a different file.')
return files[0] return files[0]
def init_resources(self, context): # pylint: disable=unused-argument def init_resources(self, context): # pylint: disable=unused-argument

View File

@ -193,9 +193,9 @@ class VellamoResultParser(HTMLParser):
self.failed = False self.failed = False
self.benchmarks = [] self.benchmarks = []
def feed(self, text): def feed(self, data):
try: try:
HTMLParser.feed(self, text) HTMLParser.feed(self, data)
except self.StopParsingException: except self.StopParsingException:
pass pass
@ -230,3 +230,6 @@ class VellamoResultParser(HTMLParser):
self.benchmarks[-1].add_metric(data) self.benchmarks[-1].add_metric(data)
else: else:
self.failed = True self.failed = True
def error(self, message):
raise WorkloadError('Error parsing raw output: {}'.format(message))