1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2024-10-05 18:31:12 +01:00

Pylint Fixes

Update our version of pylint to use the latest version and update the
codebase to comply with the majority of the updates.

For now disable the additional checks for `super-with-arguments`,
`useless-object-inheritance`, `raise-missing-from`, `no-else-raise`,
`no-else-break`, `no-else-continue` to be consistent with the existing
codebase.
This commit is contained in:
Marc Bonnici 2020-10-19 18:07:21 +01:00 committed by setrofim
parent fbd6f4e90c
commit fbb84eca72
22 changed files with 33 additions and 31 deletions

View File

@ -22,8 +22,7 @@ install:
- pip install nose
- pip install nose2
- pip install flake8
- pip install isort==4.3.21
- pip install pylint==1.9.2
- pip install pylint==2.6.0
- git clone -v https://github.com/ARM-software/devlib.git /tmp/devlib && cd /tmp/devlib && python setup.py install
- cd $TRAVIS_BUILD_DIR && python setup.py install

View File

@ -43,7 +43,7 @@ ignore=external
# https://bitbucket.org/logilab/pylint/issue/232/wrong-hanging-indentation-false-positive
# TODO: disabling no-value-for-parameter and logging-format-interpolation, as they appear to be broken
# in version 1.4.1 and return a lot of false postives; should be re-enabled once fixed.
disable=C0301,C0103,C0111,W0142,R0903,R0904,R0922,W0511,W0141,I0011,R0921,W1401,C0330,no-value-for-parameter,logging-format-interpolation,no-else-return,inconsistent-return-statements,keyword-arg-before-vararg,consider-using-enumerate,no-member
disable=C0301,C0103,C0111,W0142,R0903,R0904,R0922,W0511,W0141,I0011,R0921,W1401,C0330,no-value-for-parameter,logging-format-interpolation,no-else-return,inconsistent-return-statements,keyword-arg-before-vararg,consider-using-enumerate,no-member,super-with-arguments,useless-object-inheritance,raise-missing-from,no-else-raise,no-else-break,no-else-continue
[FORMAT]
max-module-lines=4000

View File

@ -78,7 +78,7 @@ class ProcessCommand(Command):
if not args.recursive:
output_list = [RunOutput(process_directory)]
else:
output_list = [output for output in discover_wa_outputs(process_directory)]
output_list = list(discover_wa_outputs(process_directory))
pc = ProcessContext()
for run_output in output_list:

View File

@ -252,8 +252,7 @@ class ConfigurationPoint(object):
a warning to the user however will continue execution.
"""
self.name = identifier(name)
if kind in KIND_MAP:
kind = KIND_MAP[kind]
kind = KIND_MAP.get(kind, kind)
if kind is not None and not callable(kind):
raise ValueError('Kind must be callable.')
self.kind = kind

View File

@ -297,7 +297,7 @@ def merge_augmentations(raw):
raise ConfigError(msg.format(value, n, exc))
# Make sure none of the specified aliases conflict with each other
to_check = [e for e in entries]
to_check = list(entries)
while len(to_check) > 1:
check_entry = to_check.pop()
for e in to_check:

View File

@ -33,6 +33,7 @@ class JobSpecSource(object):
def id(self):
return self.config['id']
@property
def name(self):
raise NotImplementedError()

View File

@ -449,7 +449,7 @@ class Executor(object):
for status in reversed(Status.levels):
if status in counter:
parts.append('{} {}'.format(counter[status], status))
self.logger.info(status_summary + ', '.join(parts))
self.logger.info('{}{}'.format(status_summary, ', '.join(parts)))
self.logger.info('Results can be found in {}'.format(output.basepath))

View File

@ -50,6 +50,7 @@ def init_user_directory(overwrite_existing=False): # pylint: disable=R0914
# If running with sudo on POSIX, change the ownership to the real user.
real_user = os.getenv('SUDO_USER')
if real_user:
# pylint: disable=import-outside-toplevel
import pwd # done here as module won't import on win32
user_entry = pwd.getpwnam(real_user)
uid, gid = user_entry.pw_uid, user_entry.pw_gid

View File

@ -157,6 +157,7 @@ class Alias(object):
raise ConfigError(msg.format(param, self.name, ext.name))
# pylint: disable=bad-mcs-classmethod-argument
class PluginMeta(type):
"""
This basically adds some magic to plugins to make implementing new plugins,
@ -367,7 +368,7 @@ class Plugin(with_metaclass(PluginMeta, object)):
self._modules.append(module)
def __str__(self):
return self.name
return str(self.name)
def __repr__(self):
params = []

View File

@ -35,6 +35,7 @@ class __LoaderWrapper(object):
def reset(self):
# These imports cannot be done at top level, because of
# sys.modules manipulation below
# pylint: disable=import-outside-toplevel
from wa.framework.plugin import PluginLoader
from wa.framework.configuration.core import settings
self._loader = PluginLoader(settings.plugin_packages,

View File

@ -281,7 +281,7 @@ def apk_version_matches(path, version):
version = list_or_string(version)
info = get_cacheable_apk_info(path)
for v in version:
if info.version_name == v or info.version_code == v:
if v in (info.version_name, info.version_code):
return True
if loose_version_matching(v, info.version_name):
return True

View File

@ -732,7 +732,7 @@ class IdleStateValue(object):
'''Checks passed state and converts to its ID'''
value = caseless_string(value)
for s_id, s_name, s_desc in self.values:
if value == s_id or value == s_name or value == s_desc:
if value in (s_id, s_name, s_desc):
return s_id
msg = 'Invalid IdleState: "{}"; Must be in {}'
raise ValueError(msg.format(value, self.values))

View File

@ -151,7 +151,7 @@ class PowerStateProcessor(object):
def __init__(self, cpus, wait_for_marker=True, no_idle=None):
if no_idle is None:
no_idle = False if cpus[0].cpuidle and cpus[0].cpuidle.states else True
no_idle = not (cpus[0].cpuidle and cpus[0].cpuidle.states)
self.power_state = SystemPowerState(len(cpus), no_idle=no_idle)
self.requested_states = {} # cpu_id -> requeseted state
self.wait_for_marker = wait_for_marker
@ -405,7 +405,7 @@ class ParallelStats(object):
for i, clust in enumerate(clusters):
self.clusters[str(i)] = set(clust)
self.clusters['all'] = set([cpu.id for cpu in cpus])
self.clusters['all'] = {cpu.id for cpu in cpus}
self.first_timestamp = None
self.last_timestamp = None

View File

@ -78,8 +78,8 @@ def init(verbosity=logging.INFO, color=True, indent_with=4,
_console_handler.setFormatter(formatter(regular_fmt))
root_logger.addHandler(_console_handler)
buffer_capacity = os.getenv('WA_LOG_BUFFER_CAPACITY',
DEFAULT_INIT_BUFFER_CAPACITY)
buffer_capacity = int(os.getenv('WA_LOG_BUFFER_CAPACITY',
str(DEFAULT_INIT_BUFFER_CAPACITY)))
_init_handler = InitHandler(buffer_capacity)
_init_handler.setLevel(logging.DEBUG)
root_logger.addHandler(_init_handler)

View File

@ -335,7 +335,7 @@ def load_struct_from_yaml(filepath=None, text=None):
of basic Python types (strings, ints, lists, dicts, etc.)."""
# Import here to avoid circular imports
# pylint: disable=wrong-import-position,cyclic-import
# pylint: disable=wrong-import-position,cyclic-import, import-outside-toplevel
from wa.utils.serializer import yaml
if not (filepath or text) or (filepath and text):
@ -361,7 +361,7 @@ def load_struct_from_file(filepath):
"""
extn = os.path.splitext(filepath)[1].lower()
if (extn == '.py') or (extn == '.pyc') or (extn == '.pyo'):
if extn in ('.py', '.pyc', '.pyo'):
return load_struct_from_python(filepath)
elif extn == '.yaml':
return load_struct_from_yaml(filepath)
@ -718,7 +718,7 @@ def lock_file(path, timeout=30):
"""
# Import here to avoid circular imports
# pylint: disable=wrong-import-position,cyclic-import
# pylint: disable=wrong-import-position,cyclic-import, import-outside-toplevel
from wa.framework.exception import ResourceError
locked = False

View File

@ -188,7 +188,7 @@ class ReventRecording(object):
self._parse_header_and_devices(self.fh)
self._events_start = self.fh.tell()
if not self.stream:
self._events = [e for e in self._iter_events()]
self._events = list(self._iter_events())
finally:
if self._close_when_done:
self.close()

View File

@ -45,7 +45,7 @@ def get_terminal_size():
def _get_terminal_size_windows():
# pylint: disable=unused-variable,redefined-outer-name,too-many-locals
# pylint: disable=unused-variable,redefined-outer-name,too-many-locals, import-outside-toplevel
try:
from ctypes import windll, create_string_buffer
# stdin handle is -10
@ -77,6 +77,7 @@ def _get_terminal_size_tput():
def _get_terminal_size_linux():
# pylint: disable=import-outside-toplevel
def ioctl_GWINSZ(fd):
try:
import fcntl

View File

@ -226,7 +226,7 @@ def module_name_set(l): # noqa: E741
modules = set()
for m in l:
if m and isinstance(m, dict):
modules.update({k for k in m.keys()})
modules.update(m.keys())
else:
modules.add(m)
return modules
@ -374,9 +374,8 @@ class prioritylist(object):
else:
raise ValueError('Invalid index {}'.format(index))
current_global_offset = 0
priority_counts = {priority: count for (priority, count) in
zip(self.priorities, [len(self.elements[p])
for p in self.priorities])}
priority_counts = dict(zip(self.priorities, [len(self.elements[p])
for p in self.priorities]))
for priority in self.priorities:
if not index_range:
break
@ -462,7 +461,7 @@ class toggle_set(set):
"""
returns a list of enabled items.
"""
return set([item for item in self if not item.startswith('~')])
return {item for item in self if not item.startswith('~')}
def conflicts_with(self, other):
"""
@ -581,7 +580,7 @@ class level(object):
return repr(self)
def __str__(self):
return self.name
return str(self.name)
def __repr__(self):
return '{}({})'.format(self.name, self.value)
@ -806,7 +805,7 @@ class ParameterDict(dict):
def update(self, *args, **kwargs):
for d in list(args) + [kwargs]:
for k, v in d:
for k, v in d.items():
self[k] = v

View File

@ -91,4 +91,4 @@ class Chrome(ApkUiautoWorkload):
owner = self.target.execute("{} stat -c '%u' {}".format(self.target.busybox, offline_pages), as_root=True).strip()
self.target.execute('{} tar -xvf {} -C {}'.format(self.target.busybox, archives_src, archives_dst), as_root=True)
self.target.execute('{} cp {} {}'.format(self.target.busybox, metadata_src, metadata_dst), as_root=True)
self.target.execute('{} chown -R {}:{} {}'.format(self.target.busybox, owner, owner, offline_pages), as_root=True)
self.target.execute('{0} chown -R {1}:{1} {2}'.format(self.target.busybox, owner, offline_pages), as_root=True)

View File

@ -257,7 +257,7 @@ class GBScoreCalculator(object):
'memory': 0.1926489,
'stream': 0.1054738,
}
# pylint: disable=C0326
workloads = [
# ID Name Power Mac ST Power Mac MT
GBWorkload(101, 'Blowfish', 43971, 40979), # NOQA

View File

@ -109,4 +109,4 @@ class Gmail(ApkUiautoWorkload):
owner = self.target.execute("{} stat -c '%u' {}".format(self.target.busybox, database_dst), as_root=True).strip()
self.target.execute('{} rm {}'.format(self.target.busybox, existing_mailstores), as_root=True)
self.target.execute('{} tar -xvf {} -C {}'.format(self.target.busybox, database_src, database_dst), as_root=True)
self.target.execute('{} chown -R {}:{} {}'.format(self.target.busybox, owner, owner, database_dst), as_root=True)
self.target.execute('{0} chown -R {1}:{1} {2}'.format(self.target.busybox, owner, database_dst), as_root=True)

View File

@ -85,4 +85,4 @@ class GoogleMaps(ApkUiautoWorkload):
owner = self.target.execute("{} stat -c '%u' {}".format(self.target.busybox, package_data_dir), as_root=True).strip()
self.target.execute('{} tar -xvf {} -C {}'.format(self.target.busybox, databases_src, databases_dst), as_root=True)
self.target.execute('{} tar -xvf {} -C {}'.format(self.target.busybox, files_src, files_dst), as_root=True)
self.target.execute('{} chown -R {}:{} {}'.format(self.target.busybox, owner, owner, package_data_dir), as_root=True)
self.target.execute('{0} chown -R {1}:{1} {2}'.format(self.target.busybox, owner, package_data_dir), as_root=True)