Fix bug where ifcopenshell express rule validator required a logger with set_state.

This commit is contained in:
Dion Moult
2023-02-20 11:24:23 +11:00
parent ac81169290
commit 147602e107
2 changed files with 10 additions and 6 deletions
@@ -67,9 +67,9 @@ def run(f, logger):
if hasattr(logger, "set_instance"): if hasattr(logger, "set_instance"):
# when using the json logger, we notify it of the relevant instance # when using the json logger, we notify it of the relevant instance
pre_annotate_instance = lambda instance: logger.set_state('instance', instance) pre_annotate_instance = lambda instance: logger.set_state('instance', instance) if hasattr(logger, 'set_state') else None
post_annotate_instance = lambda instance: instance post_annotate_instance = lambda instance: instance
pre_annotate_attribute = lambda attribute: logger.set_state('attribute', attribute) pre_annotate_attribute = lambda attribute: logger.set_state('attribute', attribute) if hasattr(logger, 'set_state') else None
post_annotate_attribute = lambda attribute: None post_annotate_attribute = lambda attribute: None
else: else:
# when using the normal text logger the instance is appended to the method # when using the normal text logger the instance is appended to the method
@@ -92,6 +92,7 @@ def run(f, logger):
rules = list(filter(lambda x: hasattr(x, "SCOPE"), scope.values())) rules = list(filter(lambda x: hasattr(x, "SCOPE"), scope.values()))
if hasattr(logger, 'set_state'):
logger.set_state('type', 'global_rule') logger.set_state('type', 'global_rule')
for R in [r for r in rules if r.SCOPE == "file"]: for R in [r for r in rules if r.SCOPE == "file"]:
@@ -110,6 +111,7 @@ def run(f, logger):
) )
) )
if hasattr(logger, 'set_state'):
logger.set_state('type', 'simpletype_rule') logger.set_state('type', 'simpletype_rule')
types = {} types = {}
@@ -208,6 +210,7 @@ def run(f, logger):
else: else:
check(val, attr.type_of_attribute(), instance=inst) check(val, attr.type_of_attribute(), instance=inst)
if hasattr(logger, 'set_state'):
logger.set_state('type', 'entity_rule') logger.set_state('type', 'entity_rule')
for R in [r for r in rules if r.SCOPE == "entity"]: for R in [r for r in rules if r.SCOPE == "entity"]:
@@ -291,6 +291,7 @@ def validate(f, logger, express_rules=False):
filename = None filename = None
if hasattr(logger, 'set_state'):
logger.set_state('type', 'schema') logger.set_state('type', 'schema')
if not isinstance(f, ifcopenshell.file): if not isinstance(f, ifcopenshell.file):