mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Run black on IfcOpenShell-python.
This commit is contained in:
@@ -26,13 +26,16 @@ import documentation
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
class Header(codegen.Base):
|
||||
def __init__(self, mapping):
|
||||
declarations = []
|
||||
|
||||
case_lookup = lambda nm: [k for k in mapping.schema.keys if k.lower() == nm.lower()][0]
|
||||
case_normalize = lambda nm: nm if nm.startswith("IfcUtil::") else case_lookup(nm)
|
||||
create_supertype_statement = lambda nms: ", ".join("public %s %s" % ("" if c.startswith("IfcUtil::") else "",c) for c in nms)
|
||||
create_supertype_statement = lambda nms: ", ".join(
|
||||
"public %s %s" % ("" if c.startswith("IfcUtil::") else "", c) for c in nms
|
||||
)
|
||||
|
||||
write = lambda str, **kwargs: declarations.append(
|
||||
str
|
||||
@@ -80,18 +83,24 @@ class Header(codegen.Base):
|
||||
else:
|
||||
superclasses.append("IfcUtil::IfcBaseType")
|
||||
superclasses.extend(get_select_super_types(name, bases=all_superclasses))
|
||||
|
||||
is_emitted = lambda nm: nm == "IfcUtil::IfcBaseType" or nm in mapping.schema.selects or nm.lower() in emitted_simpletypes
|
||||
|
||||
is_emitted = (
|
||||
lambda nm: nm == "IfcUtil::IfcBaseType"
|
||||
or nm in mapping.schema.selects
|
||||
or nm.lower() in emitted_simpletypes
|
||||
)
|
||||
if not all(map(is_emitted, superclasses)):
|
||||
continue
|
||||
|
||||
|
||||
superclasses = list(map(case_normalize, superclasses))
|
||||
|
||||
emitted_simpletypes.add(name.lower())
|
||||
|
||||
superclass_statement = create_supertype_statement(superclasses)
|
||||
|
||||
write(templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement)
|
||||
write(
|
||||
templates.simpletype, name=name, type=type_str, attr_type=attr_type, superclass=superclass_statement
|
||||
)
|
||||
|
||||
class_definitions = []
|
||||
|
||||
@@ -149,7 +158,7 @@ class Header(codegen.Base):
|
||||
supertypes.extend(get_select_super_types(name, bases=all_supertypes))
|
||||
supertypes = list(map(case_normalize, supertypes))
|
||||
superclass = create_supertype_statement(supertypes)
|
||||
|
||||
|
||||
argument_count = mapping.argument_count(type)
|
||||
|
||||
argument_start = argument_count - len(type.attributes)
|
||||
|
||||
@@ -92,14 +92,16 @@ class Implementation(codegen.Base):
|
||||
else:
|
||||
return templates.get_attr_stmt
|
||||
|
||||
null_check = ''
|
||||
null_check = ""
|
||||
if arg["is_optional"]:
|
||||
attr_check = "if(!data_->getArgument(%d) || data_->getArgument(%d)->isNull()) { return %%s; }" % (arg["index"] - 1, arg["index"] - 1)
|
||||
attr_check = (
|
||||
"if(!data_->getArgument(%d) || data_->getArgument(%d)->isNull()) { return %%s; }"
|
||||
% (arg["index"] - 1, arg["index"] - 1)
|
||||
)
|
||||
if "boost::optional" in arg["full_type"]:
|
||||
null_check = attr_check % "boost::none"
|
||||
else:
|
||||
null_check = attr_check % "nullptr"
|
||||
|
||||
|
||||
tmpl = find_template(arg)
|
||||
write_attr(
|
||||
@@ -115,9 +117,11 @@ class Implementation(codegen.Base):
|
||||
"index": arg["index"] - 1,
|
||||
"type": arg["full_type"].replace("::Value", ""),
|
||||
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||
"non_optional_type_no_pointer": arg["non_optional_type"].replace("::Value", "").replace("*", ""),
|
||||
"non_optional_type_no_pointer": arg["non_optional_type"]
|
||||
.replace("::Value", "")
|
||||
.replace("*", ""),
|
||||
"list_instance_type": arg["list_instance_type"],
|
||||
"null_check": null_check
|
||||
"null_check": null_check,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -143,10 +147,10 @@ class Implementation(codegen.Base):
|
||||
schema_name_upper=schema_name_upper,
|
||||
body=tmpl
|
||||
% {
|
||||
"index": arg["index"] - 1,
|
||||
"index": arg["index"] - 1,
|
||||
"type": arg["full_type"].replace("::Value", ""),
|
||||
"non_optional_type": arg["non_optional_type"].replace("::Value", ""),
|
||||
"star_if_optional": "*" if "boost::optional" in arg["full_type"] else ""
|
||||
"star_if_optional": "*" if "boost::optional" in arg["full_type"] else "",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -142,10 +142,13 @@ class Mapping:
|
||||
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
|
||||
|
||||
ty = _make_argument_type(attr.type if hasattr(attr, "type") else attr)
|
||||
if ty == "TRIBOOL": ty = "LOGICAL"
|
||||
|
||||
if ty == "TRIBOOL":
|
||||
ty = "LOGICAL"
|
||||
|
||||
if ty not in self.supported_argument_types:
|
||||
import pdb; pdb.set_trace()
|
||||
import pdb
|
||||
|
||||
pdb.set_trace()
|
||||
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
|
||||
ty = "UNKNOWN"
|
||||
return "IfcUtil::Argument_%s" % ty
|
||||
@@ -175,7 +178,7 @@ class Mapping:
|
||||
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type)
|
||||
# We do not use pointers in aggregate_of<T>. aggregate_of has member vector<T*>
|
||||
ty = ty.replace("*", "")
|
||||
|
||||
|
||||
if self.schema.is_select(attr_type.type):
|
||||
type_str = templates.untyped_list
|
||||
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
|
||||
|
||||
Reference in New Issue
Block a user