From 2427ee193136585d62c954d82ec1e72d18842f01 Mon Sep 17 00:00:00 2001 From: Wouter Deconinck Date: Mon, 14 Aug 2023 12:43:21 -0500 Subject: [PATCH] feat: support for python (import edm4eic) --- CMakeLists.txt | 1 + python/CMakeLists.txt | 6 ++++++ python/edm4eic/__init__.py | 29 +++++++++++++++++++++++++++++ python/edm4eic/__version__.py.in | 3 +++ 4 files changed, 39 insertions(+) create mode 100644 python/CMakeLists.txt create mode 100644 python/edm4eic/__init__.py create mode 100644 python/edm4eic/__version__.py.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e75298..fb977c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ list(APPEND EDM4EIC_INSTALL_LIBS edm4eic edm4eicDict) add_subdirectory(utils) add_subdirectory(test) +add_subdirectory(python) install(TARGETS ${EDM4EIC_INSTALL_LIBS} EXPORT ${PROJECT_NAME}Targets diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 0000000..86c52d5 --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +install(DIRECTORY edm4eic DESTINATION python + REGEX .*\\.in EXCLUDE + PATTERN __pycache__ EXCLUDE +) diff --git a/python/edm4eic/__init__.py b/python/edm4eic/__init__.py new file mode 100644 index 0000000..17dffda --- /dev/null +++ b/python/edm4eic/__init__.py @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: Apache-2.0 + +"""Python module for the EDM4EIC datamodel and utilities.""" +import sys + +from .__version__ import __version__ +import ROOT +res = ROOT.gSystem.Load('libedm4eicDict.so') +if res < 0: + raise RuntimeError('Failed to load libedm4eicDict.so') + +res = ROOT.gSystem.Load('libedm4eicRDF.so') +if res < 0: + raise RuntimeError('Failed to load libedm4eicRDF.so') + +res = ROOT.gInterpreter.LoadFile('edm4eic/utils/kinematics.h') +if res != 0: + raise RuntimeError('Failed to load kinematics.h') + +res = ROOT.gInterpreter.LoadFile('edm4eic/utils/dataframe.h') +if res != 0: + raise RuntimeError('Failed to load dataframe.h') +from ROOT import edm4eic + +# Make TAB completion work for utils +setattr(edm4eic, 'utils', edm4eic.utils) + +# Make `import edm4eic` work +sys.modules['edm4eic'] = edm4eic diff --git a/python/edm4eic/__version__.py.in b/python/edm4eic/__version__.py.in new file mode 100644 index 0000000..253e2c9 --- /dev/null +++ b/python/edm4eic/__version__.py.in @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: Apache-2.0 + +__version__ = "@EDM4EIC_VERSION@"