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

utils: pep8 fixes

This commit is contained in:
Marc Bonnici 2018-07-02 12:24:10 +01:00
parent f74b7ae78c
commit 1a08b2a6c7
6 changed files with 23 additions and 10 deletions

View File

@ -264,7 +264,7 @@ def format_literal(lit):
elif hasattr(lit, 'pattern'): # regex
return '``r\'{}\'``'.format(lit.pattern)
elif isinstance(lit, dict):
content = indent(',\n'.join("{}: {}".format(key,val) for (key,val) in lit.items()))
content = indent(',\n'.join("{}: {}".format(key, val) for (key, val) in lit.items()))
return '::\n\n{}'.format(indent('{{\n{}\n}}'.format(content)))
else:
return '``{}``'.format(lit)

View File

@ -31,6 +31,7 @@ def activate_environment(name):
init_environment(name)
__active_environment = name
def init_environment(name):
"""
Create a new environment called ``name``, but do not set it as the
@ -44,6 +45,7 @@ def init_environment(name):
raise ValueError(msg)
__environments[name] = []
def reset_environment(name=None):
"""
Reset method call tracking for environment ``name``. If ``name`` is
@ -63,6 +65,7 @@ def reset_environment(name=None):
activate_environment('default')
__environments[__active_environment] = []
# The decorators:
def once_per_instance(method):
"""
@ -81,6 +84,7 @@ def once_per_instance(method):
return wrapper
def once_per_class(method):
"""
The specified method will be invoked only once for all instances
@ -100,6 +104,7 @@ def once_per_class(method):
return wrapper
def once(method):
"""
The specified method will be invoked only once within the

View File

@ -521,7 +521,6 @@ def merge_sequencies(s1, s2):
return type(s2)(unique(chain(s1, s2)))
def merge_maps(m1, m2):
return type(m2)(chain(iter(m1.items()), iter(m2.items())))
@ -604,6 +603,7 @@ def resolve_cpus(name, target):
msg = 'Unexpected core name "{}"'
raise ValueError(msg.format(name))
@memoized
def resolve_unique_domain_cpus(name, target):
"""

View File

@ -100,6 +100,7 @@ POD_TYPES = [
cpu_mask,
]
class WAJSONEncoder(_json.JSONEncoder):
def default(self, obj): # pylint: disable=method-hidden
@ -190,13 +191,16 @@ def _wa_regex_representer(dumper, data):
text = '{}:{}'.format(data.flags, data.pattern)
return dumper.represent_scalar(_regex_tag, text)
def _wa_level_representer(dumper, data):
text = '{}:{}'.format(data.name, data.level)
return dumper.represent_scalar(_level_tag, text)
def _wa_cpu_mask_representer(dumper, data):
return dumper.represent_scalar(_cpu_mask_tag, data.mask())
def _wa_dict_constructor(loader, node):
pairs = loader.construct_pairs(node)
seen_keys = set()
@ -212,11 +216,13 @@ def _wa_regex_constructor(loader, node):
flags, pattern = value.split(':', 1)
return re.compile(pattern, int(flags or 0))
def _wa_level_constructor(loader, node):
value = loader.construct_scalar(node)
name, value = value.split(':', 1)
return level(name, value)
def _wa_cpu_mask_constructor(loader, node):
value = loader.construct_scalar(node)
return cpu_mask(value)
@ -317,9 +323,9 @@ def _read_pod(fh, fmt=None):
if fmt == '':
# Special case of no given file extension
message = ("Could not determine format " +
"from file extension for \"{}\". ".format(getattr(fh, 'name', '<none>')) +
"from file extension for \"{}\". "
"Please specify it or modify the fmt parameter.")
raise ValueError(message)
raise ValueError(message.format(getattr(fh, 'name', '<none>')))
if fmt == 'yaml':
return yaml.load(fh)
elif fmt == 'json':

View File

@ -25,6 +25,7 @@ from wa.utils.types import numeric
logger = logging.getLogger('trace-cmd')
class TraceCmdEvent(object):
"""
A single trace-cmd event. This will appear in the trace cmd report in the format ::

View File

@ -212,10 +212,12 @@ __counters = defaultdict(int)
def reset_counter(name=None, value=0):
__counters[name] = value
def reset_all_counters(value=0):
for k in __counters:
reset_counter(k, value)
def counter(name=None):
"""
An auto incrementing value (kind of like an AUTO INCREMENT field in SQL).
@ -578,7 +580,6 @@ class level(object):
return self.value != other
class _EnumMeta(type):
def __str__(cls):