diff --git a/python/podio/__init__.py b/python/podio/__init__.py index 1414f58be..e21c2dbad 100644 --- a/python/podio/__init__.py +++ b/python/podio/__init__.py @@ -7,50 +7,44 @@ import ROOT # pylint: disable=wrong-import-order -# Track whether we were able to dynamially load the library that is built by -# podio and enable certain features of the bindings only if they are actually -# available. -_DYNAMIC_LIBS_LOADED = False - -# Check if we can locate the dictionary wthout loading it as this allows us to -# silence any ouptput. If we can find it, we can also safely load it -if ROOT.gSystem.DynamicPathName("libpodioDict.so", True): - ROOT.gSystem.Load("libpodioDict.so") +# Check if we can locate the dictionary without loading it as this allows us to +# silence any output. If we can find it, we can also safely load it +if ROOT.gSystem.Load("libpodioDict.so") >= 0: from ROOT import podio - - _DYNAMIC_LIBS_LOADED = True - -if _DYNAMIC_LIBS_LOADED: - from .frame import Frame - 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 - - try: - # For some reason the test_utils only work at (test) runtime if they are - # imported with the rest of podio. Otherwise they produce a weird c++ error. - # This happens even if we import the *exact* same file. - from . import test_utils # noqa: F401 - except ImportError: - pass - - # Make sure that this module is actually usable as podio even though most of - # it is dynamically populated by cppyy - sys.modules["podio"] = podio - - __all__ = [ - "__version__", - "Frame", - "root_io", - "sio_io", - "reading", - "EventStore" - ] +else: + sys.exit("Could not load the podio dictionary. Please make sure that the " + "library has been built and is available in PYTHONPATH") + +from .frame import Frame +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 + +try: + # For some reason the test_utils only work at (test) runtime if they are + # imported with the rest of podio. Otherwise they produce a weird c++ error. + # This happens even if we import the *exact* same file. + from . import test_utils # noqa: F401 +except ImportError: + pass + +# Make sure that this module is actually usable as podio even though most of +# it is dynamically populated by cppyy +sys.modules["podio"] = podio + +__all__ = [ + "__version__", + "Frame", + "root_io", + "sio_io", + "reading", + "EventStore" + ] diff --git a/python/podio/sio_io.py b/python/podio/sio_io.py index 30257a860..a0d45236b 100644 --- a/python/podio/sio_io.py +++ b/python/podio/sio_io.py @@ -2,9 +2,9 @@ """Python module for reading sio files containing podio Frames""" from ROOT import gSystem -ret = gSystem.Load('libpodioSioIO') # noqa: 402 -# Return values: -1 when it doesn't exist and -2 when there is a version mismatch -if ret < 0: +if gSystem.DynamicPathName("libpodioSioIO.so", True): + gSystem.Load('libpodioSioIO') # noqa: 402 +else: raise ImportError('Error when importing libpodioSioIO') from ROOT import podio # noqa: 402 # pylint: disable=wrong-import-position