Run black on existing entity_instance

This commit is contained in:
Dion Moult
2023-06-16 16:17:17 +10:00
parent 704e27ecca
commit c8ede38edb
2 changed files with 26 additions and 62 deletions
+4 -2
View File
@@ -23,7 +23,8 @@ table below.
| .ifc | .ifcJSON | Ifc2JSON_ |
+-------------------------+-------------------------+----------------------+
| .ifc | .ifc | IfcPatch_ |
| | (IFC2X3, IFC4, IFC4X3) | |
| | (IFC2X3, IFC4, IFC4X3), | |
| | SQLite, MySQL | |
+-------------------------+-------------------------+----------------------+
| .ifc | .json (Code_Aster), | Ifc2CA_ |
| | .comm (Code_Aster) | |
@@ -33,7 +34,8 @@ table below.
+-------------------------+-------------------------+----------------------+
| .ifc | .csv, .ods, .xlsx | Ifc5D_ |
+-------------------------+-------------------------+----------------------+
| .ifc | .csv, .ods, .xlsx | IfcCSV_ |
| .ifc | .csv, .ods, .xlsx, | IfcCSV_ |
| | Pandas DataFrame | |
+-------------------------+-------------------------+----------------------+
| .csv | .ifc | Ifc5D_ |
+-------------------------+-------------------------+----------------------+
@@ -40,7 +40,7 @@ except ImportError as e:
def set_derived_attribute(*args):
raise TypeError("Unable to set derived attribute")
def set_unsupported_attribute(*args):
raise TypeError("This is an unsupported attribute type")
@@ -83,8 +83,7 @@ def register_schema_attributes(schema):
functions = [
set_derived_attribute
if mname == "setArgumentAsDerived"
else
set_unsupported_attribute
else set_unsupported_attribute
if mname == "setArgumentAsUnknown"
else getattr(ifcopenshell_wrapper.entity_instance, mname)
for mname in fn_names
@@ -139,18 +138,12 @@ class entity_instance(object):
idx = self.wrapped_data.get_argument_index(name)
if _method_dict[self.is_a(True)][idx] != set_derived_attribute:
# A bit ugly, but we fall through to derived attribute handling below
return entity_instance.wrap_value(
self.wrapped_data.get_argument(idx), self.wrapped_data.file
)
return entity_instance.wrap_value(self.wrapped_data.get_argument(idx), self.wrapped_data.file)
elif attr_cat == INVERSE:
vs = entity_instance.wrap_value(
self.wrapped_data.get_inverse(name), self.wrapped_data.file
)
vs = entity_instance.wrap_value(self.wrapped_data.get_inverse(name), self.wrapped_data.file)
if settings.unpack_non_aggregate_inverses:
schema_name = self.wrapped_data.is_a(True).split(".")[0]
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
self.is_a()
)
ent = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
inv = [i for i in ent.all_inverse_attributes() if i.name() == name][0]
if (inv.bound1(), inv.bound2()) == (-1, -1):
if vs:
@@ -164,9 +157,7 @@ class entity_instance(object):
rules = importlib.import_module(f"ifcopenshell.express.rules.{schema_name}")
def yield_supertypes():
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
self.is_a()
)
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
while decl:
yield decl.name()
decl = decl.supertype()
@@ -178,8 +169,7 @@ class entity_instance(object):
if attr_cat != FORWARD:
raise AttributeError(
"entity instance of type '%s' has no attribute '%s'"
% (self.wrapped_data.is_a(True), name)
"entity instance of type '%s' has no attribute '%s'" % (self.wrapped_data.is_a(True), name)
)
@staticmethod
@@ -218,11 +208,7 @@ class entity_instance(object):
:type attr: int
:rtype: string
"""
attr_idx = (
attr
if isinstance(attr, numbers.Integral)
else self.wrapped_data.get_argument_index(attr)
)
attr_idx = attr if isinstance(attr, numbers.Integral) else self.wrapped_data.get_argument_index(attr)
return self.wrapped_data.get_argument_type(attr_idx)
def attribute_name(self, attr_idx):
@@ -240,23 +226,15 @@ class entity_instance(object):
def __getitem__(self, key):
if key < 0 or key >= len(self):
raise IndexError(
"Attribute index {} out of range for instance of type {}".format(
key, self.is_a()
)
)
return entity_instance.wrap_value(
self.wrapped_data.get_argument(key), self.wrapped_data.file
)
raise IndexError("Attribute index {} out of range for instance of type {}".format(key, self.is_a()))
return entity_instance.wrap_value(self.wrapped_data.get_argument(key), self.wrapped_data.file)
def __setitem__(self, idx, value):
if self.wrapped_data.file and self.wrapped_data.file.transaction:
self.wrapped_data.file.transaction.store_edit(self, idx, value)
if self.method_list is None:
super(entity_instance, self).__setattr__(
"method_list", _method_dict[self.is_a(True)]
)
super(entity_instance, self).__setattr__("method_list", _method_dict[self.is_a(True)])
method = self.method_list[idx]
@@ -264,9 +242,7 @@ class entity_instance(object):
if method is not set_derived_attribute:
self.wrapped_data.setArgumentAsNull(idx)
else:
self.method_list[idx](
self.wrapped_data, idx, entity_instance.unwrap_value(value)
)
self.method_list[idx](self.wrapped_data, idx, entity_instance.unwrap_value(value))
return value
@@ -323,9 +299,9 @@ class entity_instance(object):
elif None in (self.wrapped_data.file, other.wrapped_data.file):
# when not added to a file, we can only compare attribute values
# and we need this for where rule evaluation
return self.get_info(
return self.get_info(recursive=True, include_identifier=False) == other.get_info(
recursive=True, include_identifier=False
) == other.get_info(recursive=True, include_identifier=False)
)
else:
# Proper entity instances have a stable identity by means of the numeric
# step id. Selected type instances (such as IfcPropertySingleValue.NominalValue
@@ -346,9 +322,7 @@ class entity_instance(object):
bool: True if the instance is an entity
"""
schema_name = self.wrapped_data.is_a(True).split(".")[0]
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(
self.is_a()
)
decl = ifcopenshell_wrapper.schema_by_name(schema_name).declaration_by_name(self.is_a())
return isinstance(decl, ifcopenshell_wrapper.entity)
def compare(self, other, op, reverse=False):
@@ -436,9 +410,7 @@ class entity_instance(object):
)
)
def get_info(
self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False
):
def get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=(), scalar_only=False):
"""Return a dictionary of the entity_instance's properties (Python and IFC) and their values.
:param include_identifier: Whether or not to include the STEP numerical identifier
@@ -472,18 +444,14 @@ class entity_instance(object):
yield "id", self.id()
yield "type", self.is_a()
except BaseException:
logging.exception(
"unhandled exception while getting id / type info on {}".format(
self
)
)
logging.exception("unhandled exception while getting id / type info on {}".format(self))
for i in range(len(self)):
try:
if self.wrapped_data.get_attribute_names()[i] in ignore:
continue
attr_value = self[i]
to_include = {'v': True}
to_include = {"v": True}
if recursive or scalar_only:
@@ -500,29 +468,23 @@ class entity_instance(object):
)
def do_ignore(inst):
to_include['v'] = False
to_include["v"] = False
return None
attr_value = entity_instance.walk(
is_instance, get_info_ if recursive else do_ignore, attr_value
)
if to_include['v']:
if to_include["v"]:
yield self.attribute_name(i), attr_value
except BaseException:
logging.exception(
"unhandled exception occurred setting attribute name for {}".format(
self
)
)
logging.exception("unhandled exception occurred setting attribute name for {}".format(self))
return return_type(_())
__dict__ = property(get_info)
def get_info_2(
self, include_identifier=True, recursive=False, return_type=dict, ignore=()
):
def get_info_2(self, include_identifier=True, recursive=False, return_type=dict, ignore=()):
assert include_identifier
assert recursive
assert return_type is dict