mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
Use inverse unpacking in rule execution
This commit is contained in:
@@ -60,6 +60,9 @@ def fix_type(v):
|
|||||||
def run(f, logger):
|
def run(f, logger):
|
||||||
from _pytest import assertion
|
from _pytest import assertion
|
||||||
|
|
||||||
|
orig = ifcopenshell.settings.unpack_non_aggregate_inverses
|
||||||
|
ifcopenshell.settings.unpack_non_aggregate_inverses = True
|
||||||
|
|
||||||
fn = os.path.join(os.path.dirname(__file__), "rules", f"{f.schema}.py")
|
fn = os.path.join(os.path.dirname(__file__), "rules", f"{f.schema}.py")
|
||||||
source = open(fn, "r").read()
|
source = open(fn, "r").read()
|
||||||
a = ast.parse(source)
|
a = ast.parse(source)
|
||||||
@@ -77,7 +80,13 @@ def run(f, logger):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
ln = e.__traceback__.tb_next.tb_lineno
|
ln = e.__traceback__.tb_next.tb_lineno
|
||||||
logger.error(
|
logger.error(
|
||||||
str(error(R.__name__, reverse_compile(source.split("\n")[ln - 1]), reverse_compile(e.args[0])))
|
str(
|
||||||
|
error(
|
||||||
|
R.__name__,
|
||||||
|
reverse_compile(source.split("\n")[ln - 1]),
|
||||||
|
reverse_compile(e.args[0]),
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
types = {}
|
types = {}
|
||||||
@@ -85,7 +94,9 @@ def run(f, logger):
|
|||||||
for d in S.declarations():
|
for d in S.declarations():
|
||||||
if isinstance(d, ifcopenshell.ifcopenshell_wrapper.type_declaration):
|
if isinstance(d, ifcopenshell.ifcopenshell_wrapper.type_declaration):
|
||||||
types[d.name()] = d
|
types[d.name()] = d
|
||||||
if isinstance(d.declared_type(), ifcopenshell.ifcopenshell_wrapper.named_type):
|
if isinstance(
|
||||||
|
d.declared_type(), ifcopenshell.ifcopenshell_wrapper.named_type
|
||||||
|
):
|
||||||
subtypes[d.declared_type().declared_type().name()].append(d.name())
|
subtypes[d.declared_type().declared_type().name()].append(d.name())
|
||||||
|
|
||||||
D = collections.defaultdict(list)
|
D = collections.defaultdict(list)
|
||||||
@@ -135,7 +146,11 @@ def run(f, logger):
|
|||||||
# case in point IfcCompoundPlaneAngleMeasure. Therefore only unpack named
|
# case in point IfcCompoundPlaneAngleMeasure. Therefore only unpack named
|
||||||
# type references from this point onwards.
|
# type references from this point onwards.
|
||||||
while isinstance(
|
while isinstance(
|
||||||
type, (ifcopenshell.ifcopenshell_wrapper.named_type, ifcopenshell.ifcopenshell_wrapper.type_declaration)
|
type,
|
||||||
|
(
|
||||||
|
ifcopenshell.ifcopenshell_wrapper.named_type,
|
||||||
|
ifcopenshell.ifcopenshell_wrapper.type_declaration,
|
||||||
|
),
|
||||||
):
|
):
|
||||||
type = type.declared_type()
|
type = type.declared_type()
|
||||||
|
|
||||||
@@ -145,7 +160,10 @@ def run(f, logger):
|
|||||||
for v in value:
|
for v in value:
|
||||||
check(v, ty, instance=inst)
|
check(v, ty, instance=inst)
|
||||||
elif isinstance(value, ifcopenshell.entity_instance):
|
elif isinstance(value, ifcopenshell.entity_instance):
|
||||||
if isinstance(S.declaration_by_name(value.is_a()), ifcopenshell.ifcopenshell_wrapper.entity):
|
if isinstance(
|
||||||
|
S.declaration_by_name(value.is_a()),
|
||||||
|
ifcopenshell.ifcopenshell_wrapper.entity,
|
||||||
|
):
|
||||||
# top level entity instances will be checked on their own
|
# top level entity instances will be checked on their own
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -156,7 +174,9 @@ def run(f, logger):
|
|||||||
values = list(inst)
|
values = list(inst)
|
||||||
entity = S.declaration_by_name(inst.is_a())
|
entity = S.declaration_by_name(inst.is_a())
|
||||||
attrs = entity.all_attributes()
|
attrs = entity.all_attributes()
|
||||||
for i, (attr, val, is_derived) in enumerate(zip(attrs, values, entity.derived())):
|
for i, (attr, val, is_derived) in enumerate(
|
||||||
|
zip(attrs, values, entity.derived())
|
||||||
|
):
|
||||||
if is_derived:
|
if is_derived:
|
||||||
# @todo
|
# @todo
|
||||||
pass
|
pass
|
||||||
@@ -171,10 +191,17 @@ def run(f, logger):
|
|||||||
ln = e.__traceback__.tb_next.tb_lineno
|
ln = e.__traceback__.tb_next.tb_lineno
|
||||||
logger.error(
|
logger.error(
|
||||||
str(
|
str(
|
||||||
error(R.__name__, reverse_compile(source.split("\n")[ln - 1]), reverse_compile(e.args[0]), inst)
|
error(
|
||||||
|
R.__name__,
|
||||||
|
reverse_compile(source.split("\n")[ln - 1]),
|
||||||
|
reverse_compile(e.args[0]),
|
||||||
|
inst,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ifcopenshell.settings.unpack_non_aggregate_inverses = orig
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
Reference in New Issue
Block a user