1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 02:01:16 +00:00

framework: fix pylint issues

Fix/disable checks for issues reported by pylint under wa/framework.
This commit is contained in:
Sergei Trofimov 2018-07-04 13:40:21 +01:00 committed by Marc Bonnici
parent 9025ea32b1
commit f74b7ae78c
20 changed files with 88 additions and 76 deletions

View File

@ -40,6 +40,7 @@ class SubCommand(object):
command line arguments.
"""
name = None
help = None
usage = None
description = None
@ -81,7 +82,7 @@ class SubCommand(object):
raise NotImplementedError()
class Command(Plugin, SubCommand):
class Command(Plugin, SubCommand): # pylint: disable=abstract-method
"""
Defines a Workload Automation command. This will be executed from the
command line as ``wa <command> [args ...]``. This defines the name to be

View File

@ -13,7 +13,6 @@
# limitations under the License.
import os
import re
from copy import copy, deepcopy
from collections import OrderedDict, defaultdict
@ -494,8 +493,10 @@ class MetaConfiguration(Configuration):
def additional_packages_file(self):
return os.path.join(self.user_directory, 'packages')
def __init__(self, environ=os.environ):
def __init__(self, environ=None):
super(MetaConfiguration, self).__init__()
if environ is None:
environ = os.environ
user_directory = environ.pop('WA_USER_DIRECTORY', '')
if user_directory:
self.set('user_directory', user_directory)
@ -730,6 +731,7 @@ class RunConfiguration(Configuration):
class JobSpec(Configuration):
# pylint: disable=access-member-before-definition,attribute-defined-outside-init
name = "Job Spec"
@ -826,7 +828,7 @@ class JobSpec(Configuration):
pod['id'] = self.id
return pod
def update_config(self, source, check_mandatory=True):
def update_config(self, source, check_mandatory=True): # pylint: disable=arguments-differ
self._sources.append(source)
values = source.config
for k, v in values.items():

View File

@ -19,7 +19,7 @@ from itertools import groupby, chain
from future.moves.itertools import zip_longest
from wa.framework.configuration.core import (MetaConfiguration, RunConfiguration,
JobGenerator, Status, settings)
JobGenerator, settings)
from wa.framework.configuration.parsers import ConfigParser
from wa.framework.configuration.plugin_cache import PluginCache
from wa.framework.exception import NotFoundError
@ -36,7 +36,7 @@ class CombinedConfig(object):
instance.run_config = RunConfiguration.from_pod(pod.get('run_config', {}))
return instance
def __init__(self, settings=None, run_config=None):
def __init__(self, settings=None, run_config=None): # pylint: disable=redefined-outer-name
self.settings = settings
self.run_config = run_config
@ -78,7 +78,7 @@ class ConfigManager(object):
raise RuntimeError(msg)
return self._jobs
def __init__(self, settings=settings):
def __init__(self, settings=settings): # pylint: disable=redefined-outer-name
self.settings = settings
self.run_config = RunConfiguration()
self.plugin_cache = PluginCache()
@ -93,7 +93,7 @@ class ConfigManager(object):
self._config_parser.load_from_path(self, filepath)
self.loaded_config_sources.append(filepath)
def load_config(self, values, source, wrap_exceptions=True):
def load_config(self, values, source):
self._config_parser.load(self, values, source)
self.loaded_config_sources.append(source)
@ -169,7 +169,7 @@ def permute_by_iteration(specs):
X.A1, Y.A1, X.B1, Y.B1, X.A2, Y.A2, X.B2, Y.B2
"""
groups = [list(g) for k, g in groupby(specs, lambda s: s.workload_id)]
groups = [list(g) for _, g in groupby(specs, lambda s: s.workload_id)]
all_tuples = []
for spec in chain(*groups):
@ -195,7 +195,7 @@ def permute_by_section(specs):
X.A1, X.B1, Y.A1, Y.B1, X.A2, X.B2, Y.A2, Y.B2
"""
groups = [list(g) for k, g in groupby(specs, lambda s: s.section_id)]
groups = [list(g) for _, g in groupby(specs, lambda s: s.section_id)]
all_tuples = []
for spec in chain(*groups):

View File

@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pylint: disable=no-self-use
import os
import logging
from functools import reduce # pylint: disable=redefined-builtin
from wa.framework.configuration.core import JobSpec
from wa.framework.exception import ConfigError
from wa.utils import log
from wa.utils.serializer import json, read_pod, SerializerSyntaxError
from wa.utils.types import toggle_set, counter
from functools import reduce
logger = logging.getLogger('config')
@ -135,7 +136,7 @@ class AgendaParser(object):
logger.debug('Setting run name to "{}"'.format(value))
state.run_config.set('run_name', value)
state.load_config(entry, '{}/{}'.format(source, name), wrap_exceptions=False)
state.load_config(entry, '{}/{}'.format(source, name))
def _pop_sections(self, raw):
sections = raw.pop("sections", [])
@ -354,4 +355,3 @@ def _process_workload_entry(workload, seen_workload_ids, jobs_config):
if "workload_name" not in workload:
raise ConfigError('No workload name specified in entry {}'.format(workload['id']))
return workload

View File

@ -292,9 +292,9 @@ def update_config_from_source(final_config, source, state):
'already been specified more specifically for '
'{specific_name} in:\n\t\t{sources}')
seen_sources = state.seen_specific_config[name]
msg = msg.format(generic_name=generic_name,
msg = msg.format(generic_name=state.generic_name,
config_name=name,
specific_name=specific_name,
specific_name=state.specific_name,
sources=", ".join(seen_sources))
raise ConfigError(msg)
value = state.generic_config[source].pop(name)

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pylint: disable=unused-import
from devlib.exception import (DevlibError, HostError, TimeoutError,
TargetError, TargetNotRespondingError)
@ -152,4 +153,3 @@ class WorkerThreadError(WAError):
message = text.format(orig_name, thread, get_traceback(self.exc_info),
orig_name, orig)
super(WorkerThreadError, self).__init__(message)

View File

@ -350,7 +350,6 @@ class Executor(object):
signal.connect(self._error_signalled_callback, signal.ERROR_LOGGED)
signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED)
def execute(self, config_manager, output):
self.logger.info('Initializing run')
self.logger.debug('Finalizing run configuration.')
config = config_manager.finalize()
@ -444,11 +443,11 @@ class Executor(object):
self.logger.warn('There were warnings during execution.')
self.logger.warn('Please see {}'.format(output.logfile))
def _error_signalled_callback(self, record):
def _error_signalled_callback(self, _):
self.error_logged = True
signal.disconnect(self._error_signalled_callback, signal.ERROR_LOGGED)
def _warning_signalled_callback(self, record):
def _warning_signalled_callback(self, _):
self.warning_logged = True
signal.disconnect(self._warning_signalled_callback, signal.WARNING_LOGGED)
@ -492,7 +491,7 @@ class Runner(object):
except Exception as e:
message = e.args[0] if e.args else str(e)
log.log_error(e, self.logger)
self.logger.error('Skipping remaining jobs due to "{}".'.format(e))
self.logger.error('Skipping remaining jobs due to "{}".'.format(message))
self.context.skip_remaining_jobs()
raise e
finally:
@ -563,6 +562,7 @@ class Runner(object):
self.check_job(job)
def do_run_job(self, job, context):
# pylint: disable=too-many-branches,too-many-statements
rc = self.context.cm.run_config
if job.workload.phones_home and not rc.allow_phone_home:
self.logger.warning('Skipping job {} ({}) due to allow_phone_home=False'
@ -583,7 +583,7 @@ class Runner(object):
except Exception as e:
job.set_status(Status.FAILED)
log.log_error(e, self.logger)
if isinstance(e, TargetError) or isinstance(e, TimeoutError):
if isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context)
self.context.record_ui_state('setup-error')
raise e
@ -599,7 +599,7 @@ class Runner(object):
except Exception as e:
job.set_status(Status.FAILED)
log.log_error(e, self.logger)
if isinstance(e, TargetError) or isinstance(e, TimeoutError):
if isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context)
self.context.record_ui_state('run-error')
raise e
@ -611,7 +611,7 @@ class Runner(object):
self.pm.export_job_output(context)
except Exception as e:
job.set_status(Status.PARTIAL)
if isinstance(e, TargetError) or isinstance(e, TimeoutError):
if isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context)
self.context.record_ui_state('output-error')
raise

View File

@ -18,12 +18,11 @@ import shutil
from wa.framework import pluginloader
from wa.framework.configuration.core import (settings, ConfigurationPoint,
MetaConfiguration, RunConfiguration,
JobSpec)
MetaConfiguration, RunConfiguration)
from wa.framework.configuration.default import (generate_default_config,
write_param_yaml, _format_yaml_comment)
write_param_yaml)
from wa.framework.configuration.plugin_cache import PluginCache
from wa.utils.misc import get_random_string, load_struct_from_python
from wa.utils.misc import load_struct_from_python
from wa.utils.serializer import yaml
from wa.utils.types import identifier
@ -141,4 +140,3 @@ def format_parameter(param):
return {identifier(k) : v for k, v in param.items()}
else:
return param

View File

@ -104,7 +104,7 @@ from collections import OrderedDict
from wa.framework import signal
from wa.framework.plugin import Plugin
from wa.framework.exception import (WAError, TargetNotRespondingError, TimeoutError,
from wa.framework.exception import (TargetNotRespondingError, TimeoutError,
WorkloadError, TargetError)
from wa.utils.log import log_error
from wa.utils.misc import isiterable
@ -165,7 +165,7 @@ def get_priority(func):
'priority', signal.CallbackPriority.normal)
def priority(priority):
def priority(priority): # pylint: disable=redefined-outer-name
def decorate(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
@ -225,7 +225,7 @@ def is_installed(instrument):
def is_enabled(instrument):
if isinstance(instrument, Instrument) or isinstance(instrument, type):
if isinstance(instrument, (Instrument, type)):
name = instrument.name
else: # assume string
name = instrument
@ -279,7 +279,7 @@ class ManagedCallback(object):
context.add_event(e.args[0] if e.args else str(e))
if isinstance(e, WorkloadError):
context.set_status('FAILED')
elif isinstance(e, TargetError) or isinstance(e, TimeoutError):
elif isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context)
else:
if context.current_job:
@ -308,6 +308,7 @@ def install(instrument, context):
:param instrument: Instrument instance to install.
"""
# pylint: disable=redefined-outer-name
logger.debug('Installing instrument %s.', instrument)
if is_installed(instrument):

View File

@ -29,7 +29,7 @@ from wa.framework.run import RunState, RunInfo
from wa.framework.target.info import TargetInfo
from wa.framework.version import get_wa_version_with_commit
from wa.utils.misc import touch, ensure_directory_exists, isiterable
from wa.utils.serializer import write_pod, read_pod, is_pod
from wa.utils.serializer import write_pod, read_pod
from wa.utils.types import enum, numeric
@ -86,7 +86,7 @@ class Output(object):
@classifiers.setter
def classifiers(self, value):
if self.result is None:
msg ='Attempting to set classifiers before output has been set'
msg = 'Attempting to set classifiers before output has been set'
raise RuntimeError(msg)
self.result.classifiers = value
@ -114,7 +114,7 @@ class Output(object):
else:
self.result = Result()
self.result.status = Status.PENDING
except Exception as e:
except Exception as e: # pylint: disable=broad-except
self.result = Result()
self.result.status = Status.UNKNOWN
self.add_event(str(e))
@ -676,7 +676,7 @@ def init_job_output(run_output, job):
def discover_wa_outputs(path):
for root, dirs, files in os.walk(path):
for root, dirs, _ in os.walk(path):
if '__meta' in dirs:
yield RunOutput(root)

View File

@ -139,7 +139,7 @@ class ProcessorManager(object):
try:
self.logger.info(message.format(proc.name))
proc_func(*args)
except Exception as e:
except Exception as e: # pylint: disable=broad-except
if isinstance(e, KeyboardInterrupt):
raise
log_error(e, self.logger)
@ -155,4 +155,3 @@ class ProcessorManager(object):
self.logger.debug('Disabling output processor {}'.format(inst.name))
if inst.is_enabled:
inst.is_enabled = False

View File

@ -180,7 +180,8 @@ class PluginMeta(type):
return cls
@classmethod
def _propagate_attributes(mcs, bases, attrs, clsname):
def _propagate_attributes(mcs, bases, attrs, clsname): # pylint: disable=too-many-locals
# pylint: disable=protected-access
"""
For attributes specified by to_propagate, their values will be a union of
that specified for cls and its bases (cls values overriding those of bases
@ -488,7 +489,7 @@ class PluginLoader(object):
raise NotFoundError(msg.format(name, get_article(kind), kind))
return store[name]
def get_plugin(self, name=None, kind=None, *args, **kwargs):
def get_plugin(self, name=None, kind=None, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg
"""
Return plugin of the specified kind with the specified name. Any
additional parameters will be passed to the plugin's __init__.

View File

@ -65,7 +65,7 @@ class __LoaderWrapper(object):
self.reset()
return self._loader.get_plugin_class(name, kind)
def get_plugin(self, name=None, kind=None, *args, **kwargs):
def get_plugin(self, name=None, kind=None, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg
if not self._loader:
self.reset()
return self._loader.get_plugin(name=name, kind=kind, *args, **kwargs)

View File

@ -24,7 +24,7 @@ import logging
from contextlib import contextmanager
import wrapt
from louie import dispatcher
from louie import dispatcher # pylint: disable=wrong-import-order
from wa.utils.types import prioritylist, enum
@ -73,7 +73,7 @@ class Signal(object):
RUN_STARTED = Signal('run-started', 'sent at the beginning of the run')
RUN_INITIALIZED = Signal('run-initialized', 'set after the run has been initialized')
RUN_ABORTED = Signal('run-aborted', 'set when the run has been aborted due to a keyboard interrupt')
RUN_FAILED = Signal('run-failed', 'set if the run has failed to complete all jobs.' )
RUN_FAILED = Signal('run-failed', 'set if the run has failed to complete all jobs.')
RUN_FINALIZED = Signal('run-finalized', 'set after the run has been finalized')
RUN_COMPLETED = Signal('run-completed', 'set upon completion of the run (regardless of whether or not it has failed')
@ -291,23 +291,25 @@ log_error_func = logger.error
def safe_send(signal, sender=dispatcher.Anonymous,
propagate=[KeyboardInterrupt], *args, **kwargs):
propagate=None, *args, **kwargs):
"""
Same as ``send``, except this will catch and log all exceptions raised
by handlers, except those specified in ``propagate`` argument (defaults
to just ``[KeyboardInterrupt]``).
"""
if propagate is None:
propagate = [KeyboardInterrupt]
try:
logger.debug('Safe-sending {} from {}'.format(signal, sender))
send(signal, sender, *args, **kwargs)
except Exception as e:
except Exception as e: # pylint: disable=broad-except
if any(isinstance(e, p) for p in propagate):
raise e
log_error_func(e)
@contextmanager
def wrap(signal_name, sender=dispatcher.Anonymous,*args, **kwargs):
def wrap(signal_name, sender=dispatcher.Anonymous, *args, **kwargs): # pylint: disable=keyword-arg-before-vararg
"""Wraps the suite in before/after signals, ensuring
that after signal is always sent."""
safe = kwargs.pop('safe', False)
@ -324,7 +326,7 @@ def wrap(signal_name, sender=dispatcher.Anonymous,*args, **kwargs):
yield
send_func(success_signal, sender, *args, **kwargs)
finally:
exc_type, exc, tb = sys.exc_info()
_, exc, _ = sys.exc_info()
if exc:
log_error_func(exc)
send_func(after_signal, sender, *args, **kwargs)
@ -333,10 +335,10 @@ def wrap(signal_name, sender=dispatcher.Anonymous,*args, **kwargs):
def wrapped(signal_name, sender=dispatcher.Anonymous, safe=False):
"""A decorator for wrapping function in signal dispatch."""
@wrapt.decorator
def signal_wrapped(wrapped, instance, args, kwargs):
def signal_wrapped(wrapped_func, _, args, kwargs):
def signal_wrapper(*args, **kwargs):
with wrap(signal_name, sender, safe):
return wrapped(*args, **kwargs)
return wrapped_func(*args, **kwargs)
return signal_wrapper(*args, **kwargs)

View File

@ -23,6 +23,7 @@ class TargetConfig(dict):
"""
def __init__(self, config=None):
dict.__init__(self)
if isinstance(config, TargetConfig):
self.__dict__ = copy(config.__dict__)
elif hasattr(config, 'iteritems'):

View File

@ -54,6 +54,7 @@ def get_target_description(name, loader=pluginloader):
def instantiate_target(tdesc, params, connect=None, extra_platform_params=None):
# pylint: disable=too-many-locals,too-many-branches
target_params = get_config_point_map(tdesc.target_params)
platform_params = get_config_point_map(tdesc.platform_params)
conn_params = get_config_point_map(tdesc.conn_params)
@ -136,7 +137,7 @@ class TargetDescription(object):
vals = []
elif isiterable(vals):
if hasattr(vals, 'values'):
vals = list(v.values())
vals = list(vals.values())
else:
msg = '{} must be iterable; got "{}"'
raise ValueError(msg.format(attr, vals))
@ -147,7 +148,7 @@ class TargetDescriptor(Plugin):
kind = 'target_descriptor'
def get_descriptions(self):
def get_descriptions(self): # pylint: disable=no-self-use
return []
@ -472,6 +473,7 @@ class DefaultTargetDescriptor(TargetDescriptor):
"""
def get_descriptions(self):
# pylint: disable=attribute-defined-outside-init,too-many-locals
result = []
for target_name, target_tuple in TARGETS.items():
(target, conn), target_params = self._get_item(target_tuple)
@ -503,7 +505,7 @@ class DefaultTargetDescriptor(TargetDescriptor):
result.append(td)
return result
def _apply_param_defaults(self, params, defaults):
def _apply_param_defaults(self, params, defaults): # pylint: disable=no-self-use
'''Adds parameters in the defaults dict to params list.
Return updated params as a list (idempotent function).'''
if not defaults:
@ -563,7 +565,7 @@ def _get_target_defaults(target):
def add_description_for_target(target, description=None, **kwargs):
(base_name, ((base_target, base_conn), base_params, base_defaults)) = _get_target_defaults(target)
(base_name, ((_, base_conn), base_params, _)) = _get_target_defaults(target)
if 'target_params' not in kwargs:
kwargs['target_params'] = base_params
@ -593,7 +595,7 @@ class SimpleTargetDescriptor(TargetDescriptor):
name = 'adhoc_targets'
description="""
description = """
Returns target descriptions added with ``create_target_description``.
"""

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pylint: disable=protected-access
from copy import copy
@ -261,6 +262,9 @@ class TargetInfo(object):
self.kernel_version = None
self.kernel_config = None
self.sched_features = None
self.screen_resolution = None
self.prop = None
self.android_id = None
def to_pod(self):
pod = {}

View File

@ -122,7 +122,7 @@ class TargetManager(object):
def _init_target(self):
tdesc = get_target_description(self.target_name)
extra_plat_params={}
extra_plat_params = {}
if tdesc.platform is Gem5SimulationPlatform:
extra_plat_params['host_output_dir'] = self.outdir

View File

@ -204,8 +204,8 @@ class SysfileValuesRuntimeConfig(RuntimeConfig):
#pylint: disable=unused-argument
@staticmethod
def set_sysfile(obj, value, core):
for path, value in value.items():
def set_sysfile(obj, values, core):
for path, value in values.items():
verify = True
if path.endswith('!'):
verify = False
@ -323,14 +323,15 @@ class CpufreqRuntimeConfig(RuntimeConfig):
super(CpufreqRuntimeConfig, self).__init__(target)
def initialize(self):
# pylint: disable=too-many-statements
if not self.target.has('cpufreq'):
return
self._retrive_cpufreq_info()
all_freqs, common_freqs, common_gov = self._get_common_values()
_, common_freqs, common_gov = self._get_common_values()
# Add common parameters if available.
freq_val = FreqValue(all_freqs)
freq_val = FreqValue(common_freqs)
param_name = 'frequency'
self._runtime_params[param_name] = \
RuntimeParameter(param_name, kind=freq_val,
@ -873,7 +874,7 @@ class AndroidRuntimeConfig(RuntimeConfig):
the device
""")
if self.target.os is 'android':
if self.target.os == 'android':
param_name = 'airplane_mode'
self._runtime_params[param_name] = \
RuntimeParameter(param_name, kind=bool,

View File

@ -14,7 +14,6 @@
#
import logging
import os
import re
import time
from wa import Parameter
@ -658,11 +657,12 @@ class PackageHandler(object):
self.uninstall = uninstall
self.exact_abi = exact_abi
self.prefer_host_package = prefer_host_package
self.supported_abi = self.target.supported_abi
self.apk_file = None
self.apk_info = None
self.apk_version = None
self.logcat_log = None
self.supported_abi = self.target.supported_abi
self.error_msg = None
def initialize(self, context):
self.resolve_package(context)
@ -683,9 +683,9 @@ class PackageHandler(object):
if self.prefer_host_package:
self.resolve_package_from_host(context)
if not self.apk_file:
self.resolve_package_from_target(context)
self.resolve_package_from_target()
else:
self.resolve_package_from_target(context)
self.resolve_package_from_target()
if not self.apk_file:
self.resolve_package_from_host(context)
@ -734,7 +734,7 @@ class PackageHandler(object):
msg = 'Multiple matching packages found for "{}" on host: {}'
self.error_msg = msg.format(self.owner, available_packages)
def resolve_package_from_target(self, context):
def resolve_package_from_target(self): # pylint: disable=too-many-branches
self.logger.debug('Resolving package on target')
if self.package_name:
if not self.target.package_is_installed(self.package_name):