Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions bindings/pyroot/pythonizations/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ endif()

ROOT_ADD_PYUNITTEST(regression_18441 regression_18441.py)

ROOT_ADD_PYUNITTEST(package_metadata package_metadata.py)

if(NOT MSVC OR CMAKE_SIZEOF_VOID_P EQUAL 8 OR win_broken_tests)
# Test the conversion and low level views of interpreter-defined C++ arrays to NumPy
# We do not run this test on Windows x86 due to an interpreter issue with arrays:
Expand Down
10 changes: 10 additions & 0 deletions bindings/pyroot/pythonizations/test/package_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import importlib.metadata as meta
import unittest


class PackageMetadata(unittest.TestCase):
def test_query_metadata(self):
try:
meta.version("ROOT")
except Exception:
raise AssertionError("importlib failed to access .dist-info metadata for ROOT package")
18 changes: 18 additions & 0 deletions cmake/modules/InstallPythonMetadata.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 AND pyroot AND Python3_FOUND)
if(MSVC)
set(DISTINFO_INSTALL_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
else()
set(DISTINFO_INSTALL_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endif()

configure_file("${CMAKE_SOURCE_DIR}/config/METADATA.in" "${DISTINFO_INSTALL_DIR}/root-${ROOT_VERSION}.dist-info/METADATA" @ONLY NEWLINE_STYLE UNIX)
file(WRITE "${DISTINFO_INSTALL_DIR}/root-${ROOT_VERSION}.dist-info/INSTALLER" "CMake")
install(DIRECTORY "${DISTINFO_INSTALL_DIR}/root-${ROOT_VERSION}.dist-info" DESTINATION "${CMAKE_INSTALL_PYTHONDIR}")
endif()
1 change: 1 addition & 0 deletions cmake/modules/RootBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ option(roottest "Build roottest (implies testing=ON)" OFF)
option(test_roofit_hs3testsuite "Setup and use the HS3 conformance test suite (requires network)" OFF)
option(testing "Enable testing with CTest" OFF)
option(asan "Build ROOT with address sanitizer instrumentation (only GCC is currently supported)" 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")

Expand Down
3 changes: 3 additions & 0 deletions config/METADATA.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Metadata-Version: 2.2
Name: root
Version: @ROOT_VERSION@
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/PostInstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ if(BUILD_TESTING)
PROPERTIES ENVIRONMENT PYTHONPATH=${ROOT_LIBRARY_DIR}
PASS_REGULAR_EXPRESSION "myHistoName"
)
add_test(NAME python-package-metadata
COMMAND ${Python3_EXECUTABLE} -c "import importlib.metadata as meta, ROOT; meta.version(\"ROOT\")"
)
set_tests_properties(python-package-metadata
PROPERTIES ENVIRONMENT PYTHONPATH=${ROOT_LIBRARY_DIR}
)
endif()
endif()
Loading