diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d2314110fd2d..7945ee63a3078 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -691,6 +691,9 @@ if(pyroot) set(PYTESTS_WILLFAIL WILLFAIL) endif() +#---Insert Python metadata for ROOT import package---------------------------------------------- +include(InstallPythonMetadata) + #---Configure Testing using CTest---------------------------------------------------------------- configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/CTestCustom.cmake ${CMAKE_BINARY_DIR} COPYONLY) if(testing) diff --git a/cmake/modules/InstallPythonMetadata.cmake b/cmake/modules/InstallPythonMetadata.cmake new file mode 100644 index 0000000000000..f2622b2487f05 --- /dev/null +++ b/cmake/modules/InstallPythonMetadata.cmake @@ -0,0 +1,12 @@ +# Installs Python METADATA and INSTALLER files for compatibility with importlib.metadata +# The presence of INSTALLER (along with intentionally neglecting RECORD) prevents +# package managers from uninstalling or otherwise touching the ROOT import package if +# it wasn't installed via a wheel. +# See: https://packaging.python.org/en/latest/specifications/recording-installed-packages/ + +# scikit-build-core handles metadata so only do this for non-wheel builds to avoid conflict +if(NOT _wheel_build) + configure_file("${CMAKE_SOURCE_DIR}/config/METADATA.in" "${CMAKE_BINARY_DIR}/dist-info/METADATA" @ONLY NEWLINE_STYLE UNIX) + file(WRITE "${CMAKE_BINARY_DIR}/dist-info/INSTALLER" "CMake") + install(DIRECTORY "${CMAKE_BINARY_DIR}/dist-info/" DESTINATION "${CMAKE_INSTALL_PYTHONDIR}/root-${ROOT_VERSION}.dist-info") +endif() \ No newline at end of file diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake index 0966ae13c3353..a40aa275758cb 100644 --- a/cmake/modules/RootBuildOptions.cmake +++ b/cmake/modules/RootBuildOptions.cmake @@ -191,6 +191,7 @@ option(rootbench "Build rootbench if rootbench exists in root or if it is a sibl option(roottest "Build roottest (implies testing=ON)" OFF) option(testing "Enable testing with CTest" OFF) option(asan "Build ROOT with address sanitizer instrumentation" OFF) +option(_wheel_build "ROOT is being packaged as a wheel, do not install .dist-info metadata" OFF) set(gcctoolchain "" CACHE PATH "Set path to GCC toolchain used to build llvm/clang") diff --git a/config/METADATA.in b/config/METADATA.in new file mode 100644 index 0000000000000..d43d95b6da150 --- /dev/null +++ b/config/METADATA.in @@ -0,0 +1,3 @@ +Metadata-Version: 2.2 +Name: root +Version: @ROOT_VERSION@ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5f4f50d05bfe5..096eba25b8703 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ opengl="OFF" runtime_cxxmodules="ON" fail-on-missing="ON" +# Prevent CMake from producing its own .dist-info metadata +_wheel_build="ON" + # Explicitly list components that gminimal implicitly turns off as documentation # tmva-pymva and tpython are disabled for manylinux compatibility # see https://peps.python.org/pep-0513/#libpythonx-y-so-1