From 0cf00acef7e7ec0474c7689410f512e4d9ff298e Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Fri, 22 Sep 2023 11:10:34 +0200 Subject: [PATCH] Fix python imports when built without SIO support (#490) * 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 --- python/CMakeLists.txt | 2 +- python/podio/__init__.py | 10 +++++++++- python/podio/test_utils.py | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index a17b07748..5952f8959 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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() diff --git a/python/podio/__init__.py b/python/podio/__init__.py index 483885729..1414f58be 100644 --- a/python/podio/__init__.py +++ b/python/podio/__init__.py @@ -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 diff --git a/python/podio/test_utils.py b/python/podio/test_utils.py index 3fed5959a..2c07d086b 100644 --- a/python/podio/test_utils.py +++ b/python/podio/test_utils.py @@ -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