From cae535e054e278e3c5ac408bcf86ef7dc0df50f4 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 23 Apr 2024 01:01:57 +0200 Subject: [PATCH] [PyROOT] Move CPython extensions into subdirectories Closes #14917. --- .../python/JupyROOT/helpers/handlers.py | 2 +- bindings/pyroot/pythonizations/CMakeLists.txt | 25 ++++++++++++++----- .../pythonizations/python/ROOT/__init__.py | 1 - .../python/ROOT/_application.py | 2 +- .../pythonizations/python/ROOT/_facade.py | 2 +- .../ROOT/_pythonization/_cppinstance.py | 2 +- .../python/ROOT/_pythonization/_generic.py | 2 +- .../python/ROOT/_pythonization/_tclass.py | 2 +- .../python/ROOT/_pythonization/_tobject.py | 2 +- .../python/ROOT/_pythonization/_ttree.py | 2 +- 10 files changed, 27 insertions(+), 15 deletions(-) diff --git a/bindings/jupyroot/python/JupyROOT/helpers/handlers.py b/bindings/jupyroot/python/JupyROOT/helpers/handlers.py index 8a1273a8ec024..24cb8e19ecc57 100644 --- a/bindings/jupyroot/python/JupyROOT/helpers/handlers.py +++ b/bindings/jupyroot/python/JupyROOT/helpers/handlers.py @@ -19,7 +19,7 @@ import queue from JupyROOT import helpers -import libROOTPythonizations as _lib +import ROOT.libROOTPythonizations as _lib class IOHandler(object): diff --git a/bindings/pyroot/pythonizations/CMakeLists.txt b/bindings/pyroot/pythonizations/CMakeLists.txt index e9c9f4fb1cc65..d88c5f7ba3e54 100644 --- a/bindings/pyroot/pythonizations/CMakeLists.txt +++ b/bindings/pyroot/pythonizations/CMakeLists.txt @@ -172,6 +172,19 @@ set(libname ROOTPythonizations) add_library(${libname} SHARED ${cpp_sources}) +# To make sure that the library also ends up in the right subdirectory in the +# build directory tree. +if(MSVC) + set_target_properties(${libname} + PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/ROOT + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/ROOT + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/bin/ROOT + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/bin/ROOT) +else() + set_target_properties(${libname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/ROOT) +endif() + # Insert the ROOTPythonizationsPySources in the dependency graph add_dependencies(${libname} ROOTPythonizationsPySources) @@ -215,16 +228,16 @@ target_link_libraries(PyROOT INTERFACE cppyy_backend cppyy ROOTPythonizations) # Install library install(TARGETS ${libname} EXPORT ${CMAKE_PROJECT_NAME}Exports - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries - LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries - ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/ROOT COMPONENT libraries + LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/ROOT COMPONENT libraries + ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/ROOT COMPONENT libraries) # Install meta-target PyROOT3 (INTERFACE library) # Install library install(TARGETS PyROOT EXPORT ${CMAKE_PROJECT_NAME}Exports - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries - LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries - ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR} COMPONENT libraries) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/ROOT COMPONENT libraries + LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/ROOT COMPONENT libraries + ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR}/ROOT COMPONENT libraries) # Install Python sources and bytecode install(DIRECTORY ${localruntimedir}/ROOT diff --git a/bindings/pyroot/pythonizations/python/ROOT/__init__.py b/bindings/pyroot/pythonizations/python/ROOT/__init__.py index b8b0e04dfa7ad..92ab8cc1abc5d 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/__init__.py +++ b/bindings/pyroot/pythonizations/python/ROOT/__init__.py @@ -24,7 +24,6 @@ import cppyy import sys, importlib -import libROOTPythonizations # Build cache of commonly used python strings (the cache is python intern, so # all strings are shared python-wide, not just in PyROOT). diff --git a/bindings/pyroot/pythonizations/python/ROOT/_application.py b/bindings/pyroot/pythonizations/python/ROOT/_application.py index a0b5655111eea..d995bff83b84c 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_application.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_application.py @@ -13,7 +13,7 @@ from cppyy.gbl import gSystem, gInterpreter, gEnv -from libROOTPythonizations import InitApplication, InstallGUIEventInputHook +from ROOT.libROOTPythonizations import InitApplication, InstallGUIEventInputHook class PyROOTApplication(object): diff --git a/bindings/pyroot/pythonizations/python/ROOT/_facade.py b/bindings/pyroot/pythonizations/python/ROOT/_facade.py index e099b456a7be4..bac6a45985074 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_facade.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_facade.py @@ -175,7 +175,7 @@ def _register_converters_and_executors(self): "Double32_t&": "double&", } - from libROOTPythonizations import CPyCppyyRegisterConverterAlias, CPyCppyyRegisterExecutorAlias + from ROOT.libROOTPythonizations import CPyCppyyRegisterConverterAlias, CPyCppyyRegisterExecutorAlias for name, target in converter_aliases.items(): CPyCppyyRegisterConverterAlias(name, target) diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_cppinstance.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_cppinstance.py index 2be2c6aa4c13c..b5775fc7b0e6a 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_cppinstance.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_cppinstance.py @@ -10,7 +10,7 @@ def pythonize_cppinstance(): import cppyy - from libROOTPythonizations import AddCPPInstancePickling + from ROOT.libROOTPythonizations import AddCPPInstancePickling klass = cppyy._backend.CPPInstance diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_generic.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_generic.py index ea3bee21d6ba1..86f4eee7d9a2c 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_generic.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_generic.py @@ -8,7 +8,7 @@ # For the list of contributors see $ROOTSYS/README/CREDITS. # ################################################################################ -from libROOTPythonizations import AddPrettyPrintingPyz +from ROOT.libROOTPythonizations import AddPrettyPrintingPyz def _add_getitem_checked(klass): # Parameters: diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tclass.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tclass.py index 49b1664fc3ea7..eceaecb577aff 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tclass.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tclass.py @@ -9,7 +9,7 @@ ################################################################################ import cppyy -from libROOTPythonizations import AddTClassDynamicCastPyz +from ROOT.libROOTPythonizations import AddTClassDynamicCastPyz def pythonize_tclass(): diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py index 762bbade14ef4..1b2e9b570234e 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tobject.py @@ -8,7 +8,7 @@ # For the list of contributors see $ROOTSYS/README/CREDITS. # ################################################################################ -from libROOTPythonizations import AddTObjectEqNePyz +from ROOT.libROOTPythonizations import AddTObjectEqNePyz import cppyy # Searching diff --git a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_ttree.py b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_ttree.py index 4f7dcb12e4050..23dbecdc8b15a 100644 --- a/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_ttree.py +++ b/bindings/pyroot/pythonizations/python/ROOT/_pythonization/_ttree.py @@ -159,7 +159,7 @@ \endpythondoc """ -from libROOTPythonizations import GetBranchAttr, BranchPyz +from ROOT.libROOTPythonizations import GetBranchAttr, BranchPyz from ._rvec import _array_interface_dtype_map, _get_cpp_type_from_numpy_type from . import pythonization from ROOT._pythonization._memory_utils import _should_give_up_ownership, _constructor_releasing_ownership, _SetDirectory_SetOwnership