1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-12 07:59:04 +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. command line arguments.
""" """
name = None
help = None help = None
usage = None usage = None
description = None description = None
@ -81,7 +82,7 @@ class SubCommand(object):
raise NotImplementedError() 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 Defines a Workload Automation command. This will be executed from the
command line as ``wa <command> [args ...]``. This defines the name to be command line as ``wa <command> [args ...]``. This defines the name to be

View File

@ -13,7 +13,6 @@
# limitations under the License. # limitations under the License.
import os import os
import re
from copy import copy, deepcopy from copy import copy, deepcopy
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
@ -494,8 +493,10 @@ class MetaConfiguration(Configuration):
def additional_packages_file(self): def additional_packages_file(self):
return os.path.join(self.user_directory, 'packages') return os.path.join(self.user_directory, 'packages')
def __init__(self, environ=os.environ): def __init__(self, environ=None):
super(MetaConfiguration, self).__init__() super(MetaConfiguration, self).__init__()
if environ is None:
environ = os.environ
user_directory = environ.pop('WA_USER_DIRECTORY', '') user_directory = environ.pop('WA_USER_DIRECTORY', '')
if user_directory: if user_directory:
self.set('user_directory', user_directory) self.set('user_directory', user_directory)
@ -730,6 +731,7 @@ class RunConfiguration(Configuration):
class JobSpec(Configuration): class JobSpec(Configuration):
# pylint: disable=access-member-before-definition,attribute-defined-outside-init
name = "Job Spec" name = "Job Spec"
@ -826,7 +828,7 @@ class JobSpec(Configuration):
pod['id'] = self.id pod['id'] = self.id
return pod 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) self._sources.append(source)
values = source.config values = source.config
for k, v in values.items(): 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 future.moves.itertools import zip_longest
from wa.framework.configuration.core import (MetaConfiguration, RunConfiguration, from wa.framework.configuration.core import (MetaConfiguration, RunConfiguration,
JobGenerator, Status, settings) JobGenerator, settings)
from wa.framework.configuration.parsers import ConfigParser from wa.framework.configuration.parsers import ConfigParser
from wa.framework.configuration.plugin_cache import PluginCache from wa.framework.configuration.plugin_cache import PluginCache
from wa.framework.exception import NotFoundError from wa.framework.exception import NotFoundError
@ -36,7 +36,7 @@ class CombinedConfig(object):
instance.run_config = RunConfiguration.from_pod(pod.get('run_config', {})) instance.run_config = RunConfiguration.from_pod(pod.get('run_config', {}))
return instance 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.settings = settings
self.run_config = run_config self.run_config = run_config
@ -78,7 +78,7 @@ class ConfigManager(object):
raise RuntimeError(msg) raise RuntimeError(msg)
return self._jobs return self._jobs
def __init__(self, settings=settings): def __init__(self, settings=settings): # pylint: disable=redefined-outer-name
self.settings = settings self.settings = settings
self.run_config = RunConfiguration() self.run_config = RunConfiguration()
self.plugin_cache = PluginCache() self.plugin_cache = PluginCache()
@ -93,7 +93,7 @@ class ConfigManager(object):
self._config_parser.load_from_path(self, filepath) self._config_parser.load_from_path(self, filepath)
self.loaded_config_sources.append(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._config_parser.load(self, values, source)
self.loaded_config_sources.append(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 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 = [] all_tuples = []
for spec in chain(*groups): 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 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 = [] all_tuples = []
for spec in chain(*groups): for spec in chain(*groups):

View File

@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# pylint: disable=no-self-use
import os import os
import logging import logging
from functools import reduce # pylint: disable=redefined-builtin
from wa.framework.configuration.core import JobSpec from wa.framework.configuration.core import JobSpec
from wa.framework.exception import ConfigError from wa.framework.exception import ConfigError
from wa.utils import log from wa.utils import log
from wa.utils.serializer import json, read_pod, SerializerSyntaxError from wa.utils.serializer import json, read_pod, SerializerSyntaxError
from wa.utils.types import toggle_set, counter from wa.utils.types import toggle_set, counter
from functools import reduce
logger = logging.getLogger('config') logger = logging.getLogger('config')
@ -135,7 +136,7 @@ class AgendaParser(object):
logger.debug('Setting run name to "{}"'.format(value)) logger.debug('Setting run name to "{}"'.format(value))
state.run_config.set('run_name', 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): def _pop_sections(self, raw):
sections = raw.pop("sections", []) sections = raw.pop("sections", [])
@ -264,8 +265,8 @@ def merge_augmentations(raw):
conflicts = check_entry.conflicts_with(e) conflicts = check_entry.conflicts_with(e)
if conflicts: if conflicts:
msg = '"{}" and "{}" have conflicting entries: {}' msg = '"{}" and "{}" have conflicting entries: {}'
conflict_string = ', '.join('"{}"'.format(c.strip("~")) conflict_string = ', '.join('"{}"'.format(c.strip("~"))
for c in conflicts) for c in conflicts)
raise ConfigError(msg.format(check_entry, e, conflict_string)) raise ConfigError(msg.format(check_entry, e, conflict_string))
if entries: if entries:
@ -354,4 +355,3 @@ def _process_workload_entry(workload, seen_workload_ids, jobs_config):
if "workload_name" not in workload: if "workload_name" not in workload:
raise ConfigError('No workload name specified in entry {}'.format(workload['id'])) raise ConfigError('No workload name specified in entry {}'.format(workload['id']))
return workload return workload

View File

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

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# pylint: disable=unused-import
from devlib.exception import (DevlibError, HostError, TimeoutError, from devlib.exception import (DevlibError, HostError, TimeoutError,
TargetError, TargetNotRespondingError) TargetError, TargetNotRespondingError)
@ -152,4 +153,3 @@ class WorkerThreadError(WAError):
message = text.format(orig_name, thread, get_traceback(self.exc_info), message = text.format(orig_name, thread, get_traceback(self.exc_info),
orig_name, orig) orig_name, orig)
super(WorkerThreadError, self).__init__(message) 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._error_signalled_callback, signal.ERROR_LOGGED)
signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED) signal.connect(self._warning_signalled_callback, signal.WARNING_LOGGED)
def execute(self, config_manager, output):
self.logger.info('Initializing run') self.logger.info('Initializing run')
self.logger.debug('Finalizing run configuration.') self.logger.debug('Finalizing run configuration.')
config = config_manager.finalize() config = config_manager.finalize()
@ -444,11 +443,11 @@ class Executor(object):
self.logger.warn('There were warnings during execution.') self.logger.warn('There were warnings during execution.')
self.logger.warn('Please see {}'.format(output.logfile)) self.logger.warn('Please see {}'.format(output.logfile))
def _error_signalled_callback(self, record): def _error_signalled_callback(self, _):
self.error_logged = True self.error_logged = True
signal.disconnect(self._error_signalled_callback, signal.ERROR_LOGGED) signal.disconnect(self._error_signalled_callback, signal.ERROR_LOGGED)
def _warning_signalled_callback(self, record): def _warning_signalled_callback(self, _):
self.warning_logged = True self.warning_logged = True
signal.disconnect(self._warning_signalled_callback, signal.WARNING_LOGGED) signal.disconnect(self._warning_signalled_callback, signal.WARNING_LOGGED)
@ -492,7 +491,7 @@ class Runner(object):
except Exception as e: except Exception as e:
message = e.args[0] if e.args else str(e) message = e.args[0] if e.args else str(e)
log.log_error(e, self.logger) 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() self.context.skip_remaining_jobs()
raise e raise e
finally: finally:
@ -563,6 +562,7 @@ class Runner(object):
self.check_job(job) self.check_job(job)
def do_run_job(self, job, context): def do_run_job(self, job, context):
# pylint: disable=too-many-branches,too-many-statements
rc = self.context.cm.run_config rc = self.context.cm.run_config
if job.workload.phones_home and not rc.allow_phone_home: if job.workload.phones_home and not rc.allow_phone_home:
self.logger.warning('Skipping job {} ({}) due to allow_phone_home=False' self.logger.warning('Skipping job {} ({}) due to allow_phone_home=False'
@ -583,7 +583,7 @@ class Runner(object):
except Exception as e: except Exception as e:
job.set_status(Status.FAILED) job.set_status(Status.FAILED)
log.log_error(e, self.logger) 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) context.tm.verify_target_responsive(context)
self.context.record_ui_state('setup-error') self.context.record_ui_state('setup-error')
raise e raise e
@ -599,7 +599,7 @@ class Runner(object):
except Exception as e: except Exception as e:
job.set_status(Status.FAILED) job.set_status(Status.FAILED)
log.log_error(e, self.logger) 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) context.tm.verify_target_responsive(context)
self.context.record_ui_state('run-error') self.context.record_ui_state('run-error')
raise e raise e
@ -611,7 +611,7 @@ class Runner(object):
self.pm.export_job_output(context) self.pm.export_job_output(context)
except Exception as e: except Exception as e:
job.set_status(Status.PARTIAL) job.set_status(Status.PARTIAL)
if isinstance(e, TargetError) or isinstance(e, TimeoutError): if isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context) context.tm.verify_target_responsive(context)
self.context.record_ui_state('output-error') self.context.record_ui_state('output-error')
raise raise

View File

@ -18,12 +18,11 @@ import shutil
from wa.framework import pluginloader from wa.framework import pluginloader
from wa.framework.configuration.core import (settings, ConfigurationPoint, from wa.framework.configuration.core import (settings, ConfigurationPoint,
MetaConfiguration, RunConfiguration, MetaConfiguration, RunConfiguration)
JobSpec)
from wa.framework.configuration.default import (generate_default_config, 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.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.serializer import yaml
from wa.utils.types import identifier from wa.utils.types import identifier
@ -138,7 +137,6 @@ def convert_wa2_agenda(filepath, output_path):
def format_parameter(param): def format_parameter(param):
if isinstance(param, dict): if isinstance(param, dict):
return {identifier(k) : v for k, v in param.items()} return {identifier(k) : v for k, v in param.items()}
else: else:
return param return param

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 (WAError, TargetNotRespondingError, TimeoutError, from wa.framework.exception import (TargetNotRespondingError, TimeoutError,
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
@ -165,7 +165,7 @@ def get_priority(func):
'priority', signal.CallbackPriority.normal) 'priority', signal.CallbackPriority.normal)
def priority(priority): def priority(priority): # pylint: disable=redefined-outer-name
def decorate(func): def decorate(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return func(*args, **kwargs) return func(*args, **kwargs)
@ -225,7 +225,7 @@ def is_installed(instrument):
def is_enabled(instrument): def is_enabled(instrument):
if isinstance(instrument, Instrument) or isinstance(instrument, type): if isinstance(instrument, (Instrument, type)):
name = instrument.name name = instrument.name
else: # assume string else: # assume string
name = instrument name = instrument
@ -279,7 +279,7 @@ class ManagedCallback(object):
context.add_event(e.args[0] if e.args else str(e)) context.add_event(e.args[0] if e.args else str(e))
if isinstance(e, WorkloadError): if isinstance(e, WorkloadError):
context.set_status('FAILED') context.set_status('FAILED')
elif isinstance(e, TargetError) or isinstance(e, TimeoutError): elif isinstance(e, (TargetError, TimeoutError)):
context.tm.verify_target_responsive(context) context.tm.verify_target_responsive(context)
else: else:
if context.current_job: if context.current_job:
@ -308,6 +308,7 @@ def install(instrument, context):
:param instrument: Instrument instance to install. :param instrument: Instrument instance to install.
""" """
# pylint: disable=redefined-outer-name
logger.debug('Installing instrument %s.', instrument) logger.debug('Installing instrument %s.', instrument)
if is_installed(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.target.info import TargetInfo
from wa.framework.version import get_wa_version_with_commit from wa.framework.version import get_wa_version_with_commit
from wa.utils.misc import touch, ensure_directory_exists, isiterable 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 from wa.utils.types import enum, numeric
@ -86,7 +86,7 @@ class Output(object):
@classifiers.setter @classifiers.setter
def classifiers(self, value): def classifiers(self, value):
if self.result is None: 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) raise RuntimeError(msg)
self.result.classifiers = value self.result.classifiers = value
@ -114,7 +114,7 @@ class Output(object):
else: else:
self.result = Result() self.result = Result()
self.result.status = Status.PENDING self.result.status = Status.PENDING
except Exception as e: except Exception as e: # pylint: disable=broad-except
self.result = Result() self.result = Result()
self.result.status = Status.UNKNOWN self.result.status = Status.UNKNOWN
self.add_event(str(e)) self.add_event(str(e))
@ -676,7 +676,7 @@ def init_job_output(run_output, job):
def discover_wa_outputs(path): def discover_wa_outputs(path):
for root, dirs, files in os.walk(path): for root, dirs, _ in os.walk(path):
if '__meta' in dirs: if '__meta' in dirs:
yield RunOutput(root) yield RunOutput(root)

View File

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

View File

@ -180,7 +180,8 @@ class PluginMeta(type):
return cls return cls
@classmethod @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 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 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)) raise NotFoundError(msg.format(name, get_article(kind), kind))
return store[name] 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 Return plugin of the specified kind with the specified name. Any
additional parameters will be passed to the plugin's __init__. additional parameters will be passed to the plugin's __init__.

View File

@ -65,7 +65,7 @@ class __LoaderWrapper(object):
self.reset() self.reset()
return self._loader.get_plugin_class(name, kind) 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: if not self._loader:
self.reset() self.reset()
return self._loader.get_plugin(name=name, kind=kind, *args, **kwargs) return self._loader.get_plugin(name=name, kind=kind, *args, **kwargs)

View File

@ -24,7 +24,7 @@ import logging
from contextlib import contextmanager from contextlib import contextmanager
import wrapt import wrapt
from louie import dispatcher from louie import dispatcher # pylint: disable=wrong-import-order
from wa.utils.types import prioritylist, enum 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_STARTED = Signal('run-started', 'sent at the beginning of the run')
RUN_INITIALIZED = Signal('run-initialized', 'set after the run has been initialized') 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_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_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') 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, 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 Same as ``send``, except this will catch and log all exceptions raised
by handlers, except those specified in ``propagate`` argument (defaults by handlers, except those specified in ``propagate`` argument (defaults
to just ``[KeyboardInterrupt]``). to just ``[KeyboardInterrupt]``).
""" """
if propagate is None:
propagate = [KeyboardInterrupt]
try: try:
logger.debug('Safe-sending {} from {}'.format(signal, sender)) logger.debug('Safe-sending {} from {}'.format(signal, sender))
send(signal, sender, *args, **kwargs) 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): if any(isinstance(e, p) for p in propagate):
raise e raise e
log_error_func(e) log_error_func(e)
@contextmanager @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 """Wraps the suite in before/after signals, ensuring
that after signal is always sent.""" that after signal is always sent."""
safe = kwargs.pop('safe', False) safe = kwargs.pop('safe', False)
@ -324,7 +326,7 @@ def wrap(signal_name, sender=dispatcher.Anonymous,*args, **kwargs):
yield yield
send_func(success_signal, sender, *args, **kwargs) send_func(success_signal, sender, *args, **kwargs)
finally: finally:
exc_type, exc, tb = sys.exc_info() _, exc, _ = sys.exc_info()
if exc: if exc:
log_error_func(exc) log_error_func(exc)
send_func(after_signal, sender, *args, **kwargs) 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): def wrapped(signal_name, sender=dispatcher.Anonymous, safe=False):
"""A decorator for wrapping function in signal dispatch.""" """A decorator for wrapping function in signal dispatch."""
@wrapt.decorator @wrapt.decorator
def signal_wrapped(wrapped, instance, args, kwargs): def signal_wrapped(wrapped_func, _, args, kwargs):
def signal_wrapper(*args, **kwargs): def signal_wrapper(*args, **kwargs):
with wrap(signal_name, sender, safe): with wrap(signal_name, sender, safe):
return wrapped(*args, **kwargs) return wrapped_func(*args, **kwargs)
return signal_wrapper(*args, **kwargs) return signal_wrapper(*args, **kwargs)

View File

@ -23,6 +23,7 @@ class TargetConfig(dict):
""" """
def __init__(self, config=None): def __init__(self, config=None):
dict.__init__(self)
if isinstance(config, TargetConfig): if isinstance(config, TargetConfig):
self.__dict__ = copy(config.__dict__) self.__dict__ = copy(config.__dict__)
elif hasattr(config, 'iteritems'): 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): 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) target_params = get_config_point_map(tdesc.target_params)
platform_params = get_config_point_map(tdesc.platform_params) platform_params = get_config_point_map(tdesc.platform_params)
conn_params = get_config_point_map(tdesc.conn_params) conn_params = get_config_point_map(tdesc.conn_params)
@ -136,7 +137,7 @@ class TargetDescription(object):
vals = [] vals = []
elif isiterable(vals): elif isiterable(vals):
if hasattr(vals, 'values'): if hasattr(vals, 'values'):
vals = list(v.values()) vals = list(vals.values())
else: else:
msg = '{} must be iterable; got "{}"' msg = '{} must be iterable; got "{}"'
raise ValueError(msg.format(attr, vals)) raise ValueError(msg.format(attr, vals))
@ -147,7 +148,7 @@ class TargetDescriptor(Plugin):
kind = 'target_descriptor' kind = 'target_descriptor'
def get_descriptions(self): def get_descriptions(self): # pylint: disable=no-self-use
return [] return []
@ -472,11 +473,12 @@ class DefaultTargetDescriptor(TargetDescriptor):
""" """
def get_descriptions(self): def get_descriptions(self):
# pylint: disable=attribute-defined-outside-init,too-many-locals
result = [] result = []
for target_name, target_tuple in TARGETS.items(): for target_name, target_tuple in TARGETS.items():
(target, conn), target_params = self._get_item(target_tuple) (target, conn), target_params = self._get_item(target_tuple)
assistant = ASSISTANTS[target_name] assistant = ASSISTANTS[target_name]
conn_params = CONNECTION_PARAMS[conn] conn_params = CONNECTION_PARAMS[conn]
for platform_name, platform_tuple in PLATFORMS.items(): for platform_name, platform_tuple in PLATFORMS.items():
platform_target_defaults = platform_tuple[-1] platform_target_defaults = platform_tuple[-1]
platform_tuple = platform_tuple[0:-1] platform_tuple = platform_tuple[0:-1]
@ -495,7 +497,7 @@ class DefaultTargetDescriptor(TargetDescriptor):
if plat_conn: if plat_conn:
td.conn = plat_conn td.conn = plat_conn
td.conn_params = CONNECTION_PARAMS[plat_conn] td.conn_params = CONNECTION_PARAMS[plat_conn]
else: else:
td.conn = conn td.conn = conn
td.conn_params = conn_params td.conn_params = conn_params
@ -503,7 +505,7 @@ class DefaultTargetDescriptor(TargetDescriptor):
result.append(td) result.append(td)
return result 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. '''Adds parameters in the defaults dict to params list.
Return updated params as a list (idempotent function).''' Return updated params as a list (idempotent function).'''
if not defaults: if not defaults:
@ -555,15 +557,15 @@ def _get_target_defaults(target):
res = ('linux', TARGETS['linux']) # fallback to a generic linux target res = ('linux', TARGETS['linux']) # fallback to a generic linux target
for name, ttup in TARGETS.items(): for name, ttup in TARGETS.items():
if issubclass(target, ttup[0][0]): if issubclass(target, ttup[0][0]):
new_spec = len(inspect.getmro(ttup[0][0])) new_spec = len(inspect.getmro(ttup[0][0]))
if new_spec > specificity: if new_spec > specificity:
res = (name, ttup) res = (name, ttup)
specificity = new_spec specificity = new_spec
return res return res
def add_description_for_target(target, description=None, **kwargs): 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: if 'target_params' not in kwargs:
kwargs['target_params'] = base_params kwargs['target_params'] = base_params
@ -593,7 +595,7 @@ class SimpleTargetDescriptor(TargetDescriptor):
name = 'adhoc_targets' name = 'adhoc_targets'
description=""" description = """
Returns target descriptions added with ``create_target_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 # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# pylint: disable=protected-access
from copy import copy from copy import copy
@ -261,6 +262,9 @@ class TargetInfo(object):
self.kernel_version = None self.kernel_version = None
self.kernel_config = None self.kernel_config = None
self.sched_features = None self.sched_features = None
self.screen_resolution = None
self.prop = None
self.android_id = None
def to_pod(self): def to_pod(self):
pod = {} pod = {}

View File

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

View File

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

View File

@ -14,7 +14,6 @@
# #
import logging import logging
import os import os
import re
import time import time
from wa import Parameter from wa import Parameter
@ -658,11 +657,12 @@ class PackageHandler(object):
self.uninstall = uninstall self.uninstall = uninstall
self.exact_abi = exact_abi self.exact_abi = exact_abi
self.prefer_host_package = prefer_host_package self.prefer_host_package = prefer_host_package
self.supported_abi = self.target.supported_abi
self.apk_file = None self.apk_file = None
self.apk_info = None self.apk_info = None
self.apk_version = None self.apk_version = None
self.logcat_log = None self.logcat_log = None
self.supported_abi = self.target.supported_abi self.error_msg = None
def initialize(self, context): def initialize(self, context):
self.resolve_package(context) self.resolve_package(context)
@ -683,9 +683,9 @@ class PackageHandler(object):
if self.prefer_host_package: if self.prefer_host_package:
self.resolve_package_from_host(context) self.resolve_package_from_host(context)
if not self.apk_file: if not self.apk_file:
self.resolve_package_from_target(context) self.resolve_package_from_target()
else: else:
self.resolve_package_from_target(context) self.resolve_package_from_target()
if not self.apk_file: if not self.apk_file:
self.resolve_package_from_host(context) self.resolve_package_from_host(context)
@ -734,7 +734,7 @@ class PackageHandler(object):
msg = 'Multiple matching packages found for "{}" on host: {}' msg = 'Multiple matching packages found for "{}" on host: {}'
self.error_msg = msg.format(self.owner, available_packages) 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') self.logger.debug('Resolving package on target')
if self.package_name: if self.package_name:
if not self.target.package_is_installed(self.package_name): if not self.target.package_is_installed(self.package_name):
@ -754,13 +754,13 @@ class PackageHandler(object):
if len(matching_packages) == 1: if len(matching_packages) == 1:
self.package_name = matching_packages[0] self.package_name = matching_packages[0]
elif len(matching_packages) > 1: elif len(matching_packages) > 1:
msg = 'Multiple matches for version "{}" found on device.' msg = 'Multiple matches for version "{}" found on device.'
self.error_msg = msg.format(self.version) self.error_msg = msg.format(self.version)
else: else:
if len(installed_versions) == 1: if len(installed_versions) == 1:
self.package_name = installed_versions[0] self.package_name = installed_versions[0]
elif len(installed_versions) > 1: elif len(installed_versions) > 1:
self.error_msg = 'Package version not set and multiple versions found on device.' self.error_msg = 'Package version not set and multiple versions found on device.'
if self.package_name: if self.package_name:
self.logger.debug('Found matching package on target; Pulling to host.') self.logger.debug('Found matching package on target; Pulling to host.')