mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-18 12:06:08 +00:00
utils: pep8 fixes
This commit is contained in:
parent
f74b7ae78c
commit
1a08b2a6c7
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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>')) +
|
||||
"Please specify it or modify the fmt parameter.")
|
||||
raise ValueError(message)
|
||||
"from file extension for \"{}\". "
|
||||
"Please specify it or modify the fmt parameter.")
|
||||
raise ValueError(message.format(getattr(fh, 'name', '<none>')))
|
||||
if fmt == 'yaml':
|
||||
return yaml.load(fh)
|
||||
elif fmt == 'json':
|
||||
@ -344,7 +350,7 @@ def _write_pod(pod, wfh, fmt=None):
|
||||
|
||||
|
||||
def is_pod(obj):
|
||||
if type(obj) not in POD_TYPES:
|
||||
if type(obj) not in POD_TYPES:
|
||||
return False
|
||||
if hasattr(obj, 'items'):
|
||||
for k, v in obj.items():
|
||||
|
@ -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 ::
|
||||
@ -231,7 +232,7 @@ EMPTY_CPU_REGEX = re.compile(r'CPU \d+ is empty')
|
||||
|
||||
class TraceCmdParser(object):
|
||||
"""
|
||||
A parser for textual representation of ftrace as reported by trace-cmd
|
||||
A parser for textual representation of ftrace as reported by trace-cmd
|
||||
|
||||
"""
|
||||
|
||||
@ -240,7 +241,7 @@ class TraceCmdParser(object):
|
||||
Initialize a new trace parser.
|
||||
|
||||
:param filter_markers: Specifies whether the trace before the start
|
||||
marker and after the stop marker should be
|
||||
marker and after the stop marker should be
|
||||
filtered out (so only events between the two
|
||||
markers will be reported). This maybe overriden
|
||||
based on `check_for_markers` parameter of
|
||||
|
@ -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).
|
||||
@ -534,7 +536,7 @@ class level(object):
|
||||
|
||||
@staticmethod
|
||||
def from_pod(pod):
|
||||
name, value_part = pod.split('(')
|
||||
name, value_part = pod.split('(')
|
||||
return level(name, numeric(value_part.rstrip(')')))
|
||||
|
||||
def __init__(self, name, value):
|
||||
@ -578,7 +580,6 @@ class level(object):
|
||||
return self.value != other
|
||||
|
||||
|
||||
|
||||
class _EnumMeta(type):
|
||||
|
||||
def __str__(cls):
|
||||
|
Loading…
x
Reference in New Issue
Block a user