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.
This commit is contained in:
Dion Moult
2026-04-24 07:33:13 +10:00
parent 35be7f4190
commit eea2398e07
2 changed files with 7 additions and 5 deletions
@@ -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:
@@ -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