format: reformat with black
CI seems to be failing due to a new version of pycodestyle
with errors such as:
```
./tools/elog-gen.py:26:11: E275 missing whitespace after keyword
if(i_parents[error] is not None):
```
Attempt to reformat the whole codebase with `black`.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I2fb63670cf4828d4dee19a9c7f247e9ffecdb398
diff --git a/callouts/callouts.py b/callouts/callouts.py
index 18aa610..76afb9e 100755
--- a/callouts/callouts.py
+++ b/callouts/callouts.py
@@ -7,32 +7,35 @@
def main():
- parser = argparse.ArgumentParser(
- description="Callout code generator")
+ parser = argparse.ArgumentParser(description="Callout code generator")
parser.add_argument(
- '-i', '--callouts_yaml', dest='callouts_yaml',
- default=os.path.join(script_dir, 'callouts-example.yaml'),
- help='input callouts yaml')
+ "-i",
+ "--callouts_yaml",
+ dest="callouts_yaml",
+ default=os.path.join(script_dir, "callouts-example.yaml"),
+ help="input callouts yaml",
+ )
parser.add_argument(
- '-o', '--output', dest='output',
- default='callouts-gen.hpp',
- help='output file name (default: callouts-gen.hpp)')
+ "-o",
+ "--output",
+ dest="output",
+ default="callouts-gen.hpp",
+ help="output file name (default: callouts-gen.hpp)",
+ )
args = parser.parse_args()
- with open(args.callouts_yaml, 'r') as fd:
+ with open(args.callouts_yaml, "r") as fd:
calloutsMap = yaml.safe_load(fd)
# Render the mako template
- template = os.path.join(script_dir, 'callouts-gen.mako.hpp')
+ template = os.path.join(script_dir, "callouts-gen.mako.hpp")
t = Template(filename=template)
- with open(args.output, 'w') as fd:
- fd.write(
- t.render(
- calloutsMap=calloutsMap))
+ with open(args.output, "w") as fd:
+ fd.write(t.render(calloutsMap=calloutsMap))
-if __name__ == '__main__':
+if __name__ == "__main__":
script_dir = os.path.dirname(os.path.realpath(__file__))
main()
diff --git a/extensions/openpower-pels/pel_registry/__init__.py b/extensions/openpower-pels/pel_registry/__init__.py
index 32585bd..21f916b 100644
--- a/extensions/openpower-pels/pel_registry/__init__.py
+++ b/extensions/openpower-pels/pel_registry/__init__.py
@@ -2,10 +2,10 @@
def get_registry_path() -> str:
- return os.path.join(os.path.dirname(__file__),
- 'message_registry.json')
+ return os.path.join(os.path.dirname(__file__), "message_registry.json")
def get_comp_id_file_path(creatorID: str) -> str:
- return os.path.join(os.path.dirname(__file__),
- creatorID + '_component_ids.json')
+ return os.path.join(
+ os.path.dirname(__file__), creatorID + "_component_ids.json"
+ )
diff --git a/extensions/openpower-pels/registry/tools/process_registry.py b/extensions/openpower-pels/registry/tools/process_registry.py
index 8f8eb78..229f551 100755
--- a/extensions/openpower-pels/registry/tools/process_registry.py
+++ b/extensions/openpower-pels/registry/tools/process_registry.py
@@ -21,11 +21,11 @@
"""
names = []
- for entry in registry_json['PELs']:
- if entry['Name'] in names:
- sys.exit("Found multiple uses of error {}".format(entry['Name']))
+ for entry in registry_json["PELs"]:
+ if entry["Name"] in names:
+ sys.exit("Found multiple uses of error {}".format(entry["Name"]))
else:
- names.append(entry['Name'])
+ names.append(entry["Name"])
def check_duplicate_reason_codes(registry_json):
@@ -37,12 +37,15 @@
"""
reasonCodes = []
- for entry in registry_json['PELs']:
- if entry['SRC']['ReasonCode'] in reasonCodes:
- sys.exit("Found duplicate SRC reason code {}".format(
- entry['SRC']['ReasonCode']))
+ for entry in registry_json["PELs"]:
+ if entry["SRC"]["ReasonCode"] in reasonCodes:
+ sys.exit(
+ "Found duplicate SRC reason code {}".format(
+ entry["SRC"]["ReasonCode"]
+ )
+ )
else:
- reasonCodes.append(entry['SRC']['ReasonCode'])
+ reasonCodes.append(entry["SRC"]["ReasonCode"])
def check_component_id(registry_json):
@@ -54,23 +57,26 @@
registry_json: The message registry JSON
"""
- for entry in registry_json['PELs']:
+ for entry in registry_json["PELs"]:
# Don't check on "11" SRCs as those reason codes aren't supposed to
# match the component ID.
- if entry['SRC'].get('Type', '') == "11":
+ if entry["SRC"].get("Type", "") == "11":
continue
- if 'ComponentID' in entry:
- id = int(entry['ComponentID'], 16)
- reason_code = int(entry['SRC']['ReasonCode'], 16)
+ if "ComponentID" in entry:
+ id = int(entry["ComponentID"], 16)
+ reason_code = int(entry["SRC"]["ReasonCode"], 16)
if (id & 0xFF00) != (reason_code & 0xFF00):
- sys.exit("Found mismatching component ID {} vs reason "
- "code {} for error {}".format(
- entry['ComponentID'],
- entry['SRC']['ReasonCode'],
- entry['Name']))
+ sys.exit(
+ "Found mismatching component ID {} vs reason "
+ "code {} for error {}".format(
+ entry["ComponentID"],
+ entry["SRC"]["ReasonCode"],
+ entry["Name"],
+ )
+ )
def check_message_args(registry_json):
@@ -82,20 +88,27 @@
registry_json: The message registry JSON
"""
- for entry in registry_json['PELs']:
- num_placeholders = entry['Documentation']['Message'].count('%')
+ for entry in registry_json["PELs"]:
+ num_placeholders = entry["Documentation"]["Message"].count("%")
if num_placeholders == 0:
continue
- if 'MessageArgSources' not in entry['Documentation']:
- sys.exit("Missing MessageArgSources property for error {}".
- format(entry['Name']))
+ if "MessageArgSources" not in entry["Documentation"]:
+ sys.exit(
+ "Missing MessageArgSources property for error {}".format(
+ entry["Name"]
+ )
+ )
- if num_placeholders != \
- len(entry['Documentation']['MessageArgSources']):
- sys.exit("Different number of placeholders found in "
- "Message vs MessageArgSources for error {}".
- format(entry['Name']))
+ if num_placeholders != len(
+ entry["Documentation"]["MessageArgSources"]
+ ):
+ sys.exit(
+ "Different number of placeholders found in "
+ "Message vs MessageArgSources for error {}".format(
+ entry["Name"]
+ )
+ )
def validate_schema(registry, schema):
@@ -132,24 +145,40 @@
check_message_args(registry_json)
-if __name__ == '__main__':
+if __name__ == "__main__":
parser = argparse.ArgumentParser(
- description='PEL message registry processor')
+ description="PEL message registry processor"
+ )
- parser.add_argument('-v', '--validate', action='store_true',
- dest='validate',
- help='Validate the JSON using the schema')
+ parser.add_argument(
+ "-v",
+ "--validate",
+ action="store_true",
+ dest="validate",
+ help="Validate the JSON using the schema",
+ )
- parser.add_argument('-s', '--schema-file', dest='schema_file',
- help='The message registry JSON schema file')
+ parser.add_argument(
+ "-s",
+ "--schema-file",
+ dest="schema_file",
+ help="The message registry JSON schema file",
+ )
- parser.add_argument('-r', '--registry-file', dest='registry_file',
- help='The message registry JSON file')
- parser.add_argument('-k', '--skip-schema-validation', action='store_true',
- dest='skip_schema',
- help='Skip running schema validation. '
- 'Only do the extra checks.')
+ parser.add_argument(
+ "-r",
+ "--registry-file",
+ dest="registry_file",
+ help="The message registry JSON file",
+ )
+ parser.add_argument(
+ "-k",
+ "--skip-schema-validation",
+ action="store_true",
+ dest="skip_schema",
+ help="Skip running schema validation. " "Only do the extra checks.",
+ )
args = parser.parse_args()
diff --git a/extensions/openpower-pels/setup.py b/extensions/openpower-pels/setup.py
index 1ed8fa9..8939146 100644
--- a/extensions/openpower-pels/setup.py
+++ b/extensions/openpower-pels/setup.py
@@ -8,20 +8,27 @@
# the __init__.py before building the package so they can reside in
# ../site-packages/pel_registry/ instead of site-packages/registry.
this_dir = os.path.dirname(__file__)
-target_dir = os.path.join(this_dir, 'pel_registry')
-shutil.copy(os.path.join(
- this_dir, 'registry/message_registry.json'), target_dir)
-shutil.copy(os.path.join(this_dir, 'registry/O_component_ids.json'),
- target_dir)
-shutil.copy(os.path.join(this_dir, 'registry/B_component_ids.json'),
- target_dir)
+target_dir = os.path.join(this_dir, "pel_registry")
+shutil.copy(
+ os.path.join(this_dir, "registry/message_registry.json"), target_dir
+)
+shutil.copy(
+ os.path.join(this_dir, "registry/O_component_ids.json"), target_dir
+)
+shutil.copy(
+ os.path.join(this_dir, "registry/B_component_ids.json"), target_dir
+)
setup(
name="pel_message_registry",
- version=os.getenv('PELTOOL_VERSION', '1.0'),
+ version=os.getenv("PELTOOL_VERSION", "1.0"),
classifiers=["License :: OSI Approved :: Apache Software License"],
- packages=['pel_registry'],
- package_data={'': ['message_registry.json',
- 'O_component_ids.json',
- 'B_component_ids.json']},
+ packages=["pel_registry"],
+ package_data={
+ "": [
+ "message_registry.json",
+ "O_component_ids.json",
+ "B_component_ids.json",
+ ]
+ },
)
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index dd4e04e..b969a82 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -23,20 +23,20 @@
errors = list()
has_inheritance = False
for error in i_errors:
- if(i_parents[error] is not None):
+ if i_parents[error] is not None:
has_inheritance = True
break
- if(has_inheritance):
+ if has_inheritance:
# Order the error codes list such that an error is never placed
# before it's parent. This way generated code can ensure parent
# definitions precede child error definitions.
- while(len(errors) < len(i_errors)):
+ while len(errors) < len(i_errors):
for error in i_errors:
- if(error in errors):
+ if error in errors:
# already ordererd
continue
- if((not i_parents[error]) or (i_parents[error] in errors)):
+ if (not i_parents[error]) or (i_parents[error] in errors):
# parent present, or has no parent, either way this error
# can be added
errors.append(error)
@@ -49,9 +49,13 @@
def check_error_inheritance(i_errors, i_parents):
for error in i_errors:
- if(i_parents[error] and (i_parents[error] not in i_errors)):
- print(error + " inherits " + i_parents[error] +
- " but the latter is not defined")
+ if i_parents[error] and (i_parents[error] not in i_errors):
+ print(
+ error
+ + " inherits "
+ + i_parents[error]
+ + " but the latter is not defined"
+ )
return False
return True
@@ -64,14 +68,15 @@
yaml_files = dict()
if i_yaml_dir != "None":
for root, dirs, files in os.walk(i_yaml_dir):
- for files in \
- [file for file in files if file.endswith('.errors.yaml')]:
+ for files in [
+ file for file in files if file.endswith(".errors.yaml")
+ ]:
splitdir = root.split(i_yaml_dir)[1] + "/" + files[:-12]
if splitdir.startswith("/"):
splitdir = splitdir[1:]
yaml_files[(os.path.join(root, files))] = splitdir
for root, dirs, files in os.walk(i_test_dir):
- for files in [file for file in files if file.endswith('.errors.yaml')]:
+ for files in [file for file in files if file.endswith(".errors.yaml")]:
splitdir = root.split(i_test_dir)[1] + "/" + files[:-12]
yaml_files[(os.path.join(root, files))] = splitdir
return yaml_files
@@ -86,24 +91,26 @@
def get_cpp_type(i_type):
typeMap = {
- 'boolean': 'bool',
- 'int8': 'int8_t',
- 'int16': 'int16_t',
- 'int32': 'int32_t',
- 'int64': 'int64_t',
- 'uint8': 'uint8_t',
- 'uint16': 'uint16_t',
- 'uint32': 'uint32_t',
- 'uint64': 'uint64_t',
- 'double': 'double',
+ "boolean": "bool",
+ "int8": "int8_t",
+ "int16": "int16_t",
+ "int32": "int32_t",
+ "int64": "int64_t",
+ "uint8": "uint8_t",
+ "uint16": "uint16_t",
+ "uint32": "uint32_t",
+ "uint64": "uint64_t",
+ "double": "double",
# const char* aids usage of constexpr
- 'string': 'const char*'}
+ "string": "const char*",
+ }
return typeMap[i_type]
-def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
- i_template_dir, i_elog_mako):
+def gen_elog_hpp(
+ i_yaml_dir, i_test_dir, i_output_hpp, i_template_dir, i_elog_mako
+):
r"""
Read yaml file(s) under input yaml dir, grab the relevant data and call
the mako template to generate the output header file.
@@ -127,7 +134,7 @@
# Verify the input mako file
template_path = os.path.join(i_template_dir, i_elog_mako)
- if (not (os.path.isfile(template_path))):
+ if not (os.path.isfile(template_path)):
print("Cannot find input template file " + template_path)
exit(1)
template_path = os.path.abspath(template_path)
@@ -136,26 +143,30 @@
for error_yaml in error_yamls:
# Verify the error yaml file
- if (not (os.path.isfile(error_yaml))):
+ if not (os.path.isfile(error_yaml)):
print("Cannot find input yaml file " + error_yaml)
exit(1)
# Verify the metadata yaml file
meta_yaml = get_meta_yaml_file(error_yaml)
- get_elog_data(error_yaml,
- meta_yaml,
- error_yamls[error_yaml],
- # Last arg is a tuple
- (errors,
- error_msg,
- error_lvl,
- meta,
- meta_data,
- parents,
- metadata_process))
+ get_elog_data(
+ error_yaml,
+ meta_yaml,
+ error_yamls[error_yaml],
+ # Last arg is a tuple
+ (
+ errors,
+ error_msg,
+ error_lvl,
+ meta,
+ meta_data,
+ parents,
+ metadata_process,
+ ),
+ )
- if(not check_error_inheritance(errors, parents)):
+ if not check_error_inheritance(errors, parents):
print("Error - failed to validate error inheritance")
exit(1)
@@ -165,22 +176,22 @@
yaml_dir = i_yaml_dir.strip("./")
yaml_dir = yaml_dir.strip("../")
template = Template(filename=template_path)
- f = open(i_output_hpp, 'w')
- f.write(template.render(
+ f = open(i_output_hpp, "w")
+ f.write(
+ template.render(
errors=errors,
error_msg=error_msg,
error_lvl=error_lvl,
meta=meta,
meta_data=meta_data,
parents=parents,
- metadata_process=metadata_process))
+ metadata_process=metadata_process,
+ )
+ )
f.close()
-def get_elog_data(i_elog_yaml,
- i_elog_meta_yaml,
- i_namespace,
- o_elog_data):
+def get_elog_data(i_elog_yaml, i_elog_meta_yaml, i_namespace, o_elog_data):
r"""
Parse the error and metadata yaml files in order to pull out
error metadata.
@@ -193,21 +204,30 @@
i_namespace namespace data
o_elog_data error metadata
"""
- (errors, error_msg, error_lvl, meta,
- meta_data, parents, metadata_process) = o_elog_data
+ (
+ errors,
+ error_msg,
+ error_lvl,
+ meta,
+ meta_data,
+ parents,
+ metadata_process,
+ ) = o_elog_data
ifile = yaml.safe_load(open(i_elog_yaml))
# for all the errors in error yaml file
for error in ifile:
- if 'name' not in error:
- print("Error - Did not find name in entry %s in file %s " % (
- str(error), i_elog_yaml))
+ if "name" not in error:
+ print(
+ "Error - Did not find name in entry %s in file %s "
+ % (str(error), i_elog_yaml)
+ )
exit(1)
- fullname = i_namespace.replace('/', '.') + ('.') + error['name']
+ fullname = i_namespace.replace("/", ".") + (".") + error["name"]
errors.append(fullname)
- if 'description' in error:
- error_msg[fullname] = error['description'].strip()
+ if "description" in error:
+ error_msg[fullname] = error["description"].strip()
# set default values
error_lvl[fullname] = "ERR"
@@ -221,32 +241,32 @@
# Find the meta data entry
match = None
for meta_entry in mfile:
- if meta_entry['name'] == error['name']:
+ if meta_entry["name"] == error["name"]:
match = meta_entry
break
if match is None:
continue
- error_lvl[fullname] = match.get('level', 'ERR')
+ error_lvl[fullname] = match.get("level", "ERR")
# Get 0th inherited error (current support - single inheritance)
- if 'inherits' in match:
- parents[fullname] = match['inherits'][0]
+ if "inherits" in match:
+ parents[fullname] = match["inherits"][0]
# Put all errors in meta[] even the meta is empty
# so that child errors could inherits such error without meta
tmp_meta = []
- if 'meta' in match:
+ if "meta" in match:
# grab all the meta data fields and info
- for i in match['meta']:
- str_short = i['str'].split('=')[0]
+ for i in match["meta"]:
+ str_short = i["str"].split("=")[0]
tmp_meta.append(str_short)
meta_data[str_short] = {}
- meta_data[str_short]['str'] = i['str']
- meta_data[str_short]['str_short'] = str_short
- meta_data[str_short]['type'] = get_cpp_type(i['type'])
- if ('process' in i) and (i['process'] is True):
+ meta_data[str_short]["str"] = i["str"]
+ meta_data[str_short]["str_short"] = str_short
+ meta_data[str_short]["type"] = get_cpp_type(i["type"])
+ if ("process" in i) and (i["process"] is True):
metadata_process[str_short] = fullname + "." + str_short
meta[fullname] = tmp_meta
@@ -262,35 +282,57 @@
def main(i_args):
parser = OptionParser()
- parser.add_option("-m", "--mako", dest="elog_mako",
- default="elog-gen-template.mako.hpp",
- help="input mako template file to use")
+ parser.add_option(
+ "-m",
+ "--mako",
+ dest="elog_mako",
+ default="elog-gen-template.mako.hpp",
+ help="input mako template file to use",
+ )
- parser.add_option("-o", "--output", dest="output_hpp",
- default="elog-errors.hpp",
- help="output hpp to generate, elog-errors.hpp default")
+ parser.add_option(
+ "-o",
+ "--output",
+ dest="output_hpp",
+ default="elog-errors.hpp",
+ help="output hpp to generate, elog-errors.hpp default",
+ )
- parser.add_option("-y", "--yamldir", dest="yamldir",
- default="None",
- help="Base directory of yaml files to process")
+ parser.add_option(
+ "-y",
+ "--yamldir",
+ dest="yamldir",
+ default="None",
+ help="Base directory of yaml files to process",
+ )
- parser.add_option("-u", "--testdir", dest="testdir",
- default="./tools/example/",
- help="Unit test directory of yaml files to process")
+ parser.add_option(
+ "-u",
+ "--testdir",
+ dest="testdir",
+ default="./tools/example/",
+ help="Unit test directory of yaml files to process",
+ )
- parser.add_option("-t", "--templatedir", dest="templatedir",
- default="phosphor-logging/templates/",
- help="Base directory of files to process")
+ parser.add_option(
+ "-t",
+ "--templatedir",
+ dest="templatedir",
+ default="phosphor-logging/templates/",
+ help="Base directory of files to process",
+ )
(options, args) = parser.parse_args(i_args)
- gen_elog_hpp(options.yamldir,
- options.testdir,
- options.output_hpp,
- options.templatedir,
- options.elog_mako)
+ gen_elog_hpp(
+ options.yamldir,
+ options.testdir,
+ options.output_hpp,
+ options.templatedir,
+ options.elog_mako,
+ )
# Only run if it's a script
-if __name__ == '__main__':
+if __name__ == "__main__":
main(sys.argv[1:])