mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 02:23:34 +00:00
Merge v0.7.0 -- src\ifcopenshell-python\ifcopenshell\express
This commit is contained in:
@@ -9,7 +9,7 @@ from codegen import indent
|
||||
|
||||
def reverse_compile(s):
|
||||
return re.sub(
|
||||
"\s*\-\s*EXPRESS_ONE_BASED_INDEXING",
|
||||
r"\s*\-\s*EXPRESS_ONE_BASED_INDEXING",
|
||||
"",
|
||||
re.sub(
|
||||
", )?+.(, INDETERMINATE)\\"[::-1],
|
||||
@@ -81,14 +81,29 @@ def run(f, logger):
|
||||
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")
|
||||
source = open(fn, "r").read()
|
||||
fn = os.path.join(os.path.dirname(__file__), "rules", f"{f.schema_identifier}.py")
|
||||
try:
|
||||
source = open(fn, "r").read()
|
||||
except FileNotFoundError as e:
|
||||
import sys
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
current_dir_files = {fn.lower(): fn for fn in os.listdir('.')}
|
||||
schema_name = str(f.schema_identifier).split(' ')[-1].lower()
|
||||
schema_path = current_dir_files.get(schema_name + '.exp')
|
||||
fn = schema_path[:-4] + '.py'
|
||||
if not os.path.exists(fn):
|
||||
subprocess.run([sys.executable, "-m", "ifcopenshell.express.rule_compiler", schema_path, fn], check=True)
|
||||
time.sleep(1.)
|
||||
source = open(fn, "r").read()
|
||||
|
||||
a = ast.parse(source)
|
||||
assertion.rewrite.rewrite_asserts(mod=a, source=source)
|
||||
cd = compile(a, f"{f.schema}.py", "exec")
|
||||
cd = compile(a, f"{f.schema_identifier}.py", "exec")
|
||||
scope = {}
|
||||
exec(cd, scope)
|
||||
S = ifcopenshell.ifcopenshell_wrapper.schema_by_name(f.schema)
|
||||
S = ifcopenshell.ifcopenshell_wrapper.schema_by_name(f.schema_identifier)
|
||||
|
||||
rules = list(filter(lambda x: hasattr(x, "SCOPE"), scope.values()))
|
||||
|
||||
@@ -182,10 +197,14 @@ def run(f, logger):
|
||||
type = type.declared_type()
|
||||
|
||||
if isinstance(value, (list, tuple)):
|
||||
assert isinstance(type, ifcopenshell.ifcopenshell_wrapper.aggregation_type)
|
||||
ty = type.type_of_element()
|
||||
for v in value:
|
||||
check(v, ty, instance=inst)
|
||||
if isinstance(type, ifcopenshell.ifcopenshell_wrapper.aggregation_type):
|
||||
ty = type.type_of_element()
|
||||
for v in value:
|
||||
check(v, ty, instance=inst)
|
||||
else:
|
||||
# Let's hope a schema validation error was reported for this case
|
||||
pass
|
||||
|
||||
elif isinstance(value, ifcopenshell.entity_instance):
|
||||
if isinstance(
|
||||
S.declaration_by_name(value.is_a()),
|
||||
@@ -198,7 +217,14 @@ def run(f, logger):
|
||||
check(value[0], S.declaration_by_name(value.is_a()), instance=inst)
|
||||
|
||||
for inst in f:
|
||||
values = list(inst)
|
||||
try:
|
||||
values = list(inst)
|
||||
except Exception as e:
|
||||
if hasattr(logger, "set_state"):
|
||||
logger.error(str(e))
|
||||
else:
|
||||
logger.error("For instance:\n %s\n%s", inst, e)
|
||||
continue
|
||||
entity = S.declaration_by_name(inst.is_a())
|
||||
attrs = entity.all_attributes()
|
||||
for i, (attr, val, is_derived) in enumerate(
|
||||
|
||||
Reference in New Issue
Block a user