Skip to content

Commit

Permalink
Fix python imports when built without SIO support (#490)
Browse files Browse the repository at this point in the history
* Do not unconditionally try to import the sio bindings

* Make regex a bit less error prone

* Avoid noisy but harmless ROOT message during podio builds
  • Loading branch information
tmadlener authored Sep 22, 2023
1 parent 0cf68a8 commit 590e3f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ else()
DESTINATION ${podio_PYTHON_INSTALLDIR}
REGEX test_.*\\.py$ EXCLUDE # Do not install test files
PATTERN __pycache__ EXCLUDE # Or pythons caches
REGEX .*sio.*\\.py$ EXCLUDE # All things sio related
REGEX .*sio_.*\\.py$ EXCLUDE # All things sio related
)
endif()

Expand Down
10 changes: 9 additions & 1 deletion python/podio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@

if _DYNAMIC_LIBS_LOADED:
from .frame import Frame
from . import root_io, sio_io, reading
from . import root_io, reading

try:
# We try to import the sio bindings which may fail if ROOT is not able to
# load the dictionary in this case they have most likely not been built and
# we just move on
from . import sio_io
except ImportError:
pass

from . import EventStore

Expand Down
3 changes: 2 additions & 1 deletion python/podio/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import os
import ROOT

ROOT.gSystem.Load("libTestDataModelDict.so") # noqa: E402
if ROOT.gSystem.DynamicPathName("libTestDataModelDict.so", True): # noqa: E402
ROOT.gSystem.Load("libTestDataModelDict.so") # noqa: E402
from ROOT import ExampleHitCollection, ExampleClusterCollection # noqa: E402 # pylint: disable=wrong-import-position

from podio import Frame # pylint: disable=wrong-import-position
Expand Down

0 comments on commit 590e3f2

Please sign in to comment.