mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-04-20 09:40:50 +01: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
|
elif hasattr(lit, 'pattern'): # regex
|
||||||
return '``r\'{}\'``'.format(lit.pattern)
|
return '``r\'{}\'``'.format(lit.pattern)
|
||||||
elif isinstance(lit, dict):
|
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)))
|
return '::\n\n{}'.format(indent('{{\n{}\n}}'.format(content)))
|
||||||
else:
|
else:
|
||||||
return '``{}``'.format(lit)
|
return '``{}``'.format(lit)
|
||||||
|
@ -31,6 +31,7 @@ def activate_environment(name):
|
|||||||
init_environment(name)
|
init_environment(name)
|
||||||
__active_environment = name
|
__active_environment = name
|
||||||
|
|
||||||
|
|
||||||
def init_environment(name):
|
def init_environment(name):
|
||||||
"""
|
"""
|
||||||
Create a new environment called ``name``, but do not set it as the
|
Create a new environment called ``name``, but do not set it as the
|
||||||
@ -44,6 +45,7 @@ def init_environment(name):
|
|||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
__environments[name] = []
|
__environments[name] = []
|
||||||
|
|
||||||
|
|
||||||
def reset_environment(name=None):
|
def reset_environment(name=None):
|
||||||
"""
|
"""
|
||||||
Reset method call tracking for environment ``name``. If ``name`` is
|
Reset method call tracking for environment ``name``. If ``name`` is
|
||||||
@ -63,6 +65,7 @@ def reset_environment(name=None):
|
|||||||
activate_environment('default')
|
activate_environment('default')
|
||||||
__environments[__active_environment] = []
|
__environments[__active_environment] = []
|
||||||
|
|
||||||
|
|
||||||
# The decorators:
|
# The decorators:
|
||||||
def once_per_instance(method):
|
def once_per_instance(method):
|
||||||
"""
|
"""
|
||||||
@ -81,6 +84,7 @@ def once_per_instance(method):
|
|||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def once_per_class(method):
|
def once_per_class(method):
|
||||||
"""
|
"""
|
||||||
The specified method will be invoked only once for all instances
|
The specified method will be invoked only once for all instances
|
||||||
@ -100,6 +104,7 @@ def once_per_class(method):
|
|||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def once(method):
|
def once(method):
|
||||||
"""
|
"""
|
||||||
The specified method will be invoked only once within the
|
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)))
|
return type(s2)(unique(chain(s1, s2)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def merge_maps(m1, m2):
|
def merge_maps(m1, m2):
|
||||||
return type(m2)(chain(iter(m1.items()), iter(m2.items())))
|
return type(m2)(chain(iter(m1.items()), iter(m2.items())))
|
||||||
|
|
||||||
@ -604,6 +603,7 @@ def resolve_cpus(name, target):
|
|||||||
msg = 'Unexpected core name "{}"'
|
msg = 'Unexpected core name "{}"'
|
||||||
raise ValueError(msg.format(name))
|
raise ValueError(msg.format(name))
|
||||||
|
|
||||||
|
|
||||||
@memoized
|
@memoized
|
||||||
def resolve_unique_domain_cpus(name, target):
|
def resolve_unique_domain_cpus(name, target):
|
||||||
"""
|
"""
|
||||||
|
@ -100,6 +100,7 @@ POD_TYPES = [
|
|||||||
cpu_mask,
|
cpu_mask,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class WAJSONEncoder(_json.JSONEncoder):
|
class WAJSONEncoder(_json.JSONEncoder):
|
||||||
|
|
||||||
def default(self, obj): # pylint: disable=method-hidden
|
def default(self, obj): # pylint: disable=method-hidden
|
||||||
@ -190,13 +191,16 @@ def _wa_regex_representer(dumper, data):
|
|||||||
text = '{}:{}'.format(data.flags, data.pattern)
|
text = '{}:{}'.format(data.flags, data.pattern)
|
||||||
return dumper.represent_scalar(_regex_tag, text)
|
return dumper.represent_scalar(_regex_tag, text)
|
||||||
|
|
||||||
|
|
||||||
def _wa_level_representer(dumper, data):
|
def _wa_level_representer(dumper, data):
|
||||||
text = '{}:{}'.format(data.name, data.level)
|
text = '{}:{}'.format(data.name, data.level)
|
||||||
return dumper.represent_scalar(_level_tag, text)
|
return dumper.represent_scalar(_level_tag, text)
|
||||||
|
|
||||||
|
|
||||||
def _wa_cpu_mask_representer(dumper, data):
|
def _wa_cpu_mask_representer(dumper, data):
|
||||||
return dumper.represent_scalar(_cpu_mask_tag, data.mask())
|
return dumper.represent_scalar(_cpu_mask_tag, data.mask())
|
||||||
|
|
||||||
|
|
||||||
def _wa_dict_constructor(loader, node):
|
def _wa_dict_constructor(loader, node):
|
||||||
pairs = loader.construct_pairs(node)
|
pairs = loader.construct_pairs(node)
|
||||||
seen_keys = set()
|
seen_keys = set()
|
||||||
@ -212,11 +216,13 @@ def _wa_regex_constructor(loader, node):
|
|||||||
flags, pattern = value.split(':', 1)
|
flags, pattern = value.split(':', 1)
|
||||||
return re.compile(pattern, int(flags or 0))
|
return re.compile(pattern, int(flags or 0))
|
||||||
|
|
||||||
|
|
||||||
def _wa_level_constructor(loader, node):
|
def _wa_level_constructor(loader, node):
|
||||||
value = loader.construct_scalar(node)
|
value = loader.construct_scalar(node)
|
||||||
name, value = value.split(':', 1)
|
name, value = value.split(':', 1)
|
||||||
return level(name, value)
|
return level(name, value)
|
||||||
|
|
||||||
|
|
||||||
def _wa_cpu_mask_constructor(loader, node):
|
def _wa_cpu_mask_constructor(loader, node):
|
||||||
value = loader.construct_scalar(node)
|
value = loader.construct_scalar(node)
|
||||||
return cpu_mask(value)
|
return cpu_mask(value)
|
||||||
@ -317,9 +323,9 @@ def _read_pod(fh, fmt=None):
|
|||||||
if fmt == '':
|
if fmt == '':
|
||||||
# Special case of no given file extension
|
# Special case of no given file extension
|
||||||
message = ("Could not determine format " +
|
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.")
|
"Please specify it or modify the fmt parameter.")
|
||||||
raise ValueError(message)
|
raise ValueError(message.format(getattr(fh, 'name', '<none>')))
|
||||||
if fmt == 'yaml':
|
if fmt == 'yaml':
|
||||||
return yaml.load(fh)
|
return yaml.load(fh)
|
||||||
elif fmt == 'json':
|
elif fmt == 'json':
|
||||||
@ -344,7 +350,7 @@ def _write_pod(pod, wfh, fmt=None):
|
|||||||
|
|
||||||
|
|
||||||
def is_pod(obj):
|
def is_pod(obj):
|
||||||
if type(obj) not in POD_TYPES:
|
if type(obj) not in POD_TYPES:
|
||||||
return False
|
return False
|
||||||
if hasattr(obj, 'items'):
|
if hasattr(obj, 'items'):
|
||||||
for k, v in obj.items():
|
for k, v in obj.items():
|
||||||
|
@ -25,6 +25,7 @@ from wa.utils.types import numeric
|
|||||||
|
|
||||||
logger = logging.getLogger('trace-cmd')
|
logger = logging.getLogger('trace-cmd')
|
||||||
|
|
||||||
|
|
||||||
class TraceCmdEvent(object):
|
class TraceCmdEvent(object):
|
||||||
"""
|
"""
|
||||||
A single trace-cmd event. This will appear in the trace cmd report in the format ::
|
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):
|
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.
|
Initialize a new trace parser.
|
||||||
|
|
||||||
:param filter_markers: Specifies whether the trace before the start
|
: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
|
filtered out (so only events between the two
|
||||||
markers will be reported). This maybe overriden
|
markers will be reported). This maybe overriden
|
||||||
based on `check_for_markers` parameter of
|
based on `check_for_markers` parameter of
|
||||||
|
@ -212,10 +212,12 @@ __counters = defaultdict(int)
|
|||||||
def reset_counter(name=None, value=0):
|
def reset_counter(name=None, value=0):
|
||||||
__counters[name] = value
|
__counters[name] = value
|
||||||
|
|
||||||
|
|
||||||
def reset_all_counters(value=0):
|
def reset_all_counters(value=0):
|
||||||
for k in __counters:
|
for k in __counters:
|
||||||
reset_counter(k, value)
|
reset_counter(k, value)
|
||||||
|
|
||||||
|
|
||||||
def counter(name=None):
|
def counter(name=None):
|
||||||
"""
|
"""
|
||||||
An auto incrementing value (kind of like an AUTO INCREMENT field in SQL).
|
An auto incrementing value (kind of like an AUTO INCREMENT field in SQL).
|
||||||
@ -534,7 +536,7 @@ class level(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_pod(pod):
|
def from_pod(pod):
|
||||||
name, value_part = pod.split('(')
|
name, value_part = pod.split('(')
|
||||||
return level(name, numeric(value_part.rstrip(')')))
|
return level(name, numeric(value_part.rstrip(')')))
|
||||||
|
|
||||||
def __init__(self, name, value):
|
def __init__(self, name, value):
|
||||||
@ -578,7 +580,6 @@ class level(object):
|
|||||||
return self.value != other
|
return self.value != other
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _EnumMeta(type):
|
class _EnumMeta(type):
|
||||||
|
|
||||||
def __str__(cls):
|
def __str__(cls):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user