Skip to content

Commit

Permalink
Fix flake8 warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <[email protected]>
  • Loading branch information
stv0g committed Jun 21, 2024
1 parent d274ce5 commit d5e80d7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 49 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
max-line-length = 120
extend-ignore = E203
44 changes: 23 additions & 21 deletions cimgen/cimgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ def __init__(self, jsonObject):

def asJson(self, lang_pack):
jsonObject = {}
if self.about() != None:
if self.about() is not None:
jsonObject["about"] = self.about()
if self.comment() != None:
if self.comment() is not None:
jsonObject["comment"] = self.comment()
if self.dataType() != None:
if self.dataType() is not None:
jsonObject["dataType"] = self.dataType()
if self.domain() != None:
if self.domain() is not None:
jsonObject["domain"] = self.domain()
if self.fixed() != None:
if self.fixed() is not None:
jsonObject["isFixed"] = self.fixed()
if self.label() != None:
if self.label() is not None:
jsonObject["label"] = self.label()
if self.multiplicity() != None:
if self.multiplicity() is not None:
jsonObject["multiplicity"] = self.multiplicity()
if self.range() != None:
if self.range() is not None:
jsonObject["range"] = self.range()
if self.stereotype() != None:
if self.stereotype() is not None:
jsonObject["stereotype"] = self.stereotype()
if self.type() != None:
if self.type() is not None:
jsonObject["type"] = self.type()
if self.subClassOf() != None:
if self.subClassOf() is not None:
jsonObject["subClassOf"] = self.subClassOf()
if self.inverseRole() != None:
if self.inverseRole() is not None:
jsonObject["inverseRole"] = self.inverseRole()
if self.associationUsed() != None:
if self.associationUsed() is not None:
jsonObject["associationUsed"] = self.associationUsed()
if "modernpython" in lang_pack.__name__:
jsonObject["isAssociationUsed"] = self.isAssociationUsed()
Expand All @@ -59,7 +59,8 @@ def associationUsed(self):
else:
return None

# Capitalized True/False is valid in python but not in json. Do not use this function in combination with json.load()
# Capitalized True/False is valid in python but not in json.
# Do not use this function in combination with json.load()
def isAssociationUsed(self) -> bool:
if "cims:AssociationUsed" in self.jsonDefinition:
return "yes" == RDFSEntry._extract_string(self.jsonDefinition["cims:AssociationUsed"]).lower()
Expand Down Expand Up @@ -180,7 +181,7 @@ def _extract_text(object_dic):
def _extract_string(object_dic):
if isinstance(object_dic, list):
if len(object_dic) > 0:
if type(object_dic[0]) == "string" or isinstance(object_dic[0], str):
if isinstance(object_dic[0], str):
return object_dic[0]
return RDFSEntry._get_about_or_resource(object_dic[0])
return RDFSEntry._get_about_or_resource(object_dic)
Expand Down Expand Up @@ -287,7 +288,7 @@ def is_a_float(self):
else:
return False
for key in candidate_array:
if candidate_array[key] == False:
if not candidate_array[key]:
return False
return True

Expand Down Expand Up @@ -340,7 +341,7 @@ def _rdfs_entry_types(rdfs_entry: RDFSEntry, version) -> list:
Determine the types of RDFS entry. In some case an RDFS entry can be of more than 1 type.
"""
entry_types = []
if rdfs_entry.type() != None:
if rdfs_entry.type() is not None:
if rdfs_entry.type() == "http://www.w3.org/2000/01/rdf-schema#Class": # NOSONAR
entry_types.append("class")
if rdfs_entry.type() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property": # NOSONAR
Expand All @@ -360,7 +361,7 @@ def _rdfs_entry_types(rdfs_entry: RDFSEntry, version) -> list:

def _entry_types_version_2(rdfs_entry: RDFSEntry) -> list:
entry_types = []
if rdfs_entry.stereotype() != None:
if rdfs_entry.stereotype() is not None:
if rdfs_entry.stereotype() == "Entsoe" and rdfs_entry.about()[-7:] == "Version":
entry_types.append("profile_name_v2_4")
if (
Expand Down Expand Up @@ -541,7 +542,7 @@ def format_class(_range, _dataType):
def _write_files(class_details, output_path, version):
class_details["langPack"].setup(output_path, package_listed_by_short_name)

if class_details["sub_class_of"] == None:
if class_details["sub_class_of"] is None:
# If class has no subClassOf key it is a subclass of the Base class
class_details["sub_class_of"] = class_details["langPack"].base["base_class"]
class_details["class_location"] = class_details["langPack"].base["class_location"](version)
Expand Down Expand Up @@ -704,7 +705,8 @@ def cim_generate(directory, output_path, version, lang_pack):
with the template engine chevron. The attribute version of this function defines the name of the folder where the
created classes are stored. This folder should not exist and is created in the class generation procedure.
:param directory: path to RDF files containing cgmes ontology, e.g. directory = "./examples/cgmes_schema/cgmes_v2_4_15_schema"
:param directory: path to RDF files containing cgmes ontology,
e.g. directory = "./examples/cgmes_schema/cgmes_v2_4_15_schema"
:param output_path: CGMES version, e.g. version = "cgmes_v2_4_15"
:param lang_pack: python module containing language specific functions
"""
Expand Down Expand Up @@ -734,7 +736,7 @@ def cim_generate(directory, output_path, version, lang_pack):
# work out the subclasses for each class by noting the reverse relationship
for className in class_dict_with_origins:
superClassName = class_dict_with_origins[className].superClass()
if superClassName != None:
if superClassName is not None:
if superClassName in class_dict_with_origins:
superClass = class_dict_with_origins[superClassName]
superClass.addSubClass(className)
Expand Down
21 changes: 10 additions & 11 deletions cimgen/languages/cpp/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def get_class_location(class_name, class_map, version):
# This is the function that runs the template.
def run_template(outputPath, class_details):

if class_details["is_a_float"] == True:
if class_details["is_a_float"]:
templates = float_template_files
elif class_details["has_instances"] == True:
elif class_details["has_instances"]:
templates = enum_template_files
else:
templates = template_files
Expand Down Expand Up @@ -210,7 +210,6 @@ def create_nullptr_assigns(text, render):
attributes_json = eval(attributes_txt)
nullptr_init_string = ": "
for attribute in attributes_json:
name = attribute["label"]
if attribute_type(attribute) == "primitive":
continue
if attribute["multiplicity"] == "M:0..n" or attribute["multiplicity"] == "M:1..n":
Expand Down Expand Up @@ -244,7 +243,7 @@ def create_class_assign(text, render):
}
}
return false;
}""".replace(
}""".replace( # noqa: E101,W191
"OBJECT_CLASS", attribute_json["domain"]
)
.replace("ATTRIBUTE_CLASS", attribute_class)
Expand All @@ -266,7 +265,7 @@ def create_class_assign(text, render):
return assign_INVERSEC_INVERSEL(BaseClass_ptr2, BaseClass_ptr1);
}
return false;
}""".replace(
}""".replace( # noqa: E101,W191
"OBJECT_CLASS", attribute_json["domain"]
)
.replace("ATTRIBUTE_CLASS", attribute_class)
Expand All @@ -284,7 +283,7 @@ def create_class_assign(text, render):
return true;
}
return false;
}""".replace(
}""".replace( # noqa: E101,W191
"OBJECT_CLASS", attribute_json["domain"]
)
.replace("ATTRIBUTE_CLASS", attribute_class)
Expand Down Expand Up @@ -318,7 +317,7 @@ def create_assign(text, render):
}
else
return false;
}""".replace(
}""".replace( # noqa: E101,W191
"CLASS", attribute_json["domain"]
)
.replace("LABEL", attribute_json["label"])
Expand All @@ -335,7 +334,7 @@ def create_assign(text, render):
return true;
}
return false;
}""".replace(
}""".replace( # noqa: E101,W191
"CLASS", attribute_json["domain"]
).replace(
"LABEL", attribute_json["label"]
Expand Down Expand Up @@ -378,7 +377,7 @@ def _create_attribute_includes(text, render):
inputText = render(text)
jsonString = inputText.replace("'", '"')
jsonStringNoHtmlEsc = jsonString.replace("&quot;", '"')
if jsonStringNoHtmlEsc != None and jsonStringNoHtmlEsc != "":
if jsonStringNoHtmlEsc is not None and jsonStringNoHtmlEsc != "":
attributes = json.loads(jsonStringNoHtmlEsc)
for attribute in attributes:
_type = attribute_type(attribute)
Expand All @@ -398,7 +397,7 @@ def _create_attribute_class_declarations(text, render):
inputText = render(text)
jsonString = inputText.replace("'", '"')
jsonStringNoHtmlEsc = jsonString.replace("&quot;", '"')
if jsonStringNoHtmlEsc != None and jsonStringNoHtmlEsc != "":
if jsonStringNoHtmlEsc is not None and jsonStringNoHtmlEsc != "":
attributes = json.loads(jsonStringNoHtmlEsc)
for attribute in attributes:
_type = attribute_type(attribute)
Expand Down Expand Up @@ -479,7 +478,7 @@ def _create_header_include_file(directory, header_include_filename, header, foot
filepath = os.path.join(directory, filename)
basepath, ext = os.path.splitext(filepath)
basename = os.path.basename(basepath)
if ext == ".hpp" and not _is_enum_class(filepath) and not basename in blacklist:
if ext == ".hpp" and not _is_enum_class(filepath) and basename not in blacklist:
lines.append(before + basename + after)
lines.sort()
for line in lines:
Expand Down
22 changes: 8 additions & 14 deletions cimgen/languages/java/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def run_template(outputPath, class_details):
for attr in class_details["attributes"]:
if attribute_type(attr) == "primitive":
class_details["primitives"].append(attr)
if class_details["is_a_float"] == True:
if class_details["is_a_float"]:
templates = float_template_files
elif class_details["has_instances"] == True:
elif class_details["has_instances"]:
templates = enum_template_files
else:
templates = template_files
Expand Down Expand Up @@ -206,7 +206,7 @@ def create_class_assign(text, render):
and Attribute Class as ATTRIBUTE_CLASS
and Inversec as INVERSEC
and Inversel as INVERSEL
""".replace(
""".replace( # noqa: E101,W191
"OBJECT_CLASS", attribute_json["domain"]
)
.replace("ATTRIBUTE_CLASS", attribute_class)
Expand All @@ -221,7 +221,7 @@ def create_class_assign(text, render):
with Label as LABEL
and Object Class as OBJECT_CLASS
and Attribute Class as ATTRIBUTE_CLASS
""".replace(
""".replace( # noqa: E101,W191
"OBJECT_CLASS", attribute_json["domain"]
)
.replace("ATTRIBUTE_CLASS", attribute_class)
Expand All @@ -248,7 +248,7 @@ def create_assign(text, render):
attr.setValue(value);
return attr;
}
""".replace(
""".replace( # noqa: E101,W191
"CLASS", _class
).replace(
"LABEL", attribute_json["label"]
Expand Down Expand Up @@ -298,7 +298,7 @@ def _create_attribute_includes(text, render):
inputText = render(text)
jsonString = inputText.replace("'", '"')
jsonStringNoHtmlEsc = jsonString.replace("&quot;", '"')
if jsonStringNoHtmlEsc != None and jsonStringNoHtmlEsc != "":
if jsonStringNoHtmlEsc is not None and jsonStringNoHtmlEsc != "":
attributes = json.loads(jsonStringNoHtmlEsc)
for attribute in attributes:
_type = attribute_type(attribute)
Expand All @@ -319,7 +319,7 @@ def _create_attribute_class_declarations(text, render):
inputText = render(text)
jsonString = inputText.replace("'", '"')
jsonStringNoHtmlEsc = jsonString.replace("&quot;", '"')
if jsonStringNoHtmlEsc != None and jsonStringNoHtmlEsc != "":
if jsonStringNoHtmlEsc is not None and jsonStringNoHtmlEsc != "":
attributes = json.loads(jsonStringNoHtmlEsc)
for attribute in attributes:
_type = attribute_type(attribute)
Expand Down Expand Up @@ -404,7 +404,7 @@ def _create_header_include_file(directory, header_include_filename, header, foot
filepath = os.path.join(directory, filename)
basepath, ext = os.path.splitext(filepath)
basename = os.path.basename(basepath)
if ext == ".java" and not _is_enum_class(filepath) and not basename in blacklist:
if ext == ".java" and not _is_enum_class(filepath) and basename not in blacklist:
lines.append(before + 'Map.entry("' + basename + '", new cim4j.' + basename + after + "),\n")
lines.sort()
lines[-1] = lines[-1].replace("),", ")")
Expand Down Expand Up @@ -441,9 +441,3 @@ def resolve_headers(outputPath):
"()",
class_blacklist,
)


# iec61970_header = [ "#ifndef IEC61970_H\n", "#define IEC61970_H\n" ]
# iec61970_footer = [ '#include "UnknownType.hpp"\n', '#endif' ]

# _create_header_include_file(outputPath, "IEC61970.hpp", iec61970_header, iec61970_footer, "#include \"", ".hpp\"\n", iec61970_blacklist)
2 changes: 1 addition & 1 deletion cimgen/languages/javascript/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_template(outputPath, class_details):
attr["attributeClass"] = _get_rid_of_hash(attr["dataType"])

for index, attribute in enumerate(class_details["attributes"]):
if is_an_unused_attribute(attribute) == True:
if is_an_unused_attribute(attribute):
del class_details["attributes"][index]

renderAttribute = ""
Expand Down
4 changes: 2 additions & 2 deletions cimgen/languages/python/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_class_location(class_name, class_map, version):
if class_map[class_name].superClass():
if class_map[class_name].superClass() in class_map:
return "cimpy." + version + "." + class_map[class_name].superClass()
elif class_map[class_name].superClass() == "Base" or class_map[class_name].superClass() == None:
elif class_map[class_name].superClass() == "Base" or class_map[class_name].superClass() is None:
return location(version)
else:
return location(version)
Expand Down Expand Up @@ -109,7 +109,7 @@ def _create_base(path):
' """\n',
" Base Class for CIM\n",
' """\n\n',
' cgmesProfile = Enum("cgmesProfile", {"EQ": 0, "SSH": 1, "TP": 2, "SV": 3, "DY": 4, "GL": 5, "DL": 6, "TP_BD": 7, "EQ_BD": 8})',
' cgmesProfile = Enum("cgmesProfile", {"EQ": 0, "SSH": 1, "TP": 2, "SV": 3, "DY": 4, "GL": 5, "DL": 6, "TP_BD": 7, "EQ_BD": 8})', # noqa: E501
"\n\n",
" def __init__(self, *args, **kw_args):\n",
" pass\n",
Expand Down

0 comments on commit d5e80d7

Please sign in to comment.