From eea2398e07a5a0ca8ef02ede8578848b702e5b70 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 24 Apr 2026 07:33:13 +1000 Subject: [PATCH] ifcopenshell-python: fix broken imports after upstream refactors Two upstream commits on this branch landed without updating all their callers, leaving `import ifcopenshell.geom` unusable: 89c66f62b "Python import fixes: import from wrapper now which inherits from mixins" moved the `file` class out of ifcopenshell/file.py into ifcopenshell_wrapper, but missed geom/main.py and stream.py which still did `from ..file import file`. b022ca7e7 "Some plug-in work" dropped the SWIG exports for `serialise`, `tesselate`, `XmlSerializer` (and other serializers) with a `// @todo bring back serialization` marker, but left geom/main.py referencing them at module-load time. Fix the `file` imports to come from ifcopenshell_wrapper, and guard the removed-serializer references behind `hasattr`, matching the pattern already in use for the other optional serializers (gltf, hdf5, collada, json, ttl). Revert once upstream fixes this. --- src/ifcopenshell-python/ifcopenshell/geom/main.py | 10 ++++++---- src/ifcopenshell-python/ifcopenshell/stream.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/main.py b/src/ifcopenshell-python/ifcopenshell/geom/main.py index 30c2233a89..cf1189ad3c 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/main.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/main.py @@ -24,7 +24,7 @@ from typing import TYPE_CHECKING, Any, Literal, Optional, TypeVar, Union, cast, from .. import ifcopenshell_wrapper, open from ..entity_instance import entity_instance -from ..file import file +from ..ifcopenshell_wrapper import file from . import has_occ if TYPE_CHECKING: @@ -625,8 +625,9 @@ def make_shape_function(fn): return _ -serialise = make_shape_function(ifcopenshell_wrapper.serialise) -tesselate = make_shape_function(ifcopenshell_wrapper.tesselate) +if hasattr(ifcopenshell_wrapper, "serialise"): + serialise = make_shape_function(ifcopenshell_wrapper.serialise) + tesselate = make_shape_function(ifcopenshell_wrapper.tesselate) def transform_string(v: Union[str, serializers.buffer]) -> serializers.buffer: @@ -659,7 +660,8 @@ class serializers: # Hdf- Xml- and glTF- serializers don't support writing to a buffer, only to filename # so no wrap_buffer_creation() for these serializers - xml = ifcopenshell_wrapper.XmlSerializer + if hasattr(ifcopenshell_wrapper, "XmlSerializer"): + xml = ifcopenshell_wrapper.XmlSerializer buffer = ifcopenshell_wrapper.buffer # gltf, hdf5, collada and json availability depend on IfcOpenShell configuration settings try: diff --git a/src/ifcopenshell-python/ifcopenshell/stream.py b/src/ifcopenshell-python/ifcopenshell/stream.py index c9556fa708..6afbc8a1f6 100644 --- a/src/ifcopenshell-python/ifcopenshell/stream.py +++ b/src/ifcopenshell-python/ifcopenshell/stream.py @@ -30,7 +30,7 @@ try: from . import ifcopenshell_wrapper from .entity_instance import entity_instance - from .file import file + from .ifcopenshell_wrapper import file class StreamTransformer(Transformer): file: file