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
6 changes: 6 additions & 0 deletions bindings/pyroot/pythonizations/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ set(py_sources
)

ROOT_PYTHON_PACKAGE(ROOT SOURCES ${py_sources})

# The Python version at build time should be easy to figure out from Python, so
# we can raise an exception if the used Python version is not compatible.
set(python_version_file "${localruntimedir}/ROOT/_python_version.py")
file(WRITE "${python_version_file}" "_root_python_version = \"${Python3_VERSION}\"\n")
install(FILES "${python_version_file}" DESTINATION "${CMAKE_INSTALL_PYTHONDIR}")
20 changes: 20 additions & 0 deletions bindings/pyroot/pythonizations/python/ROOT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@

import builtins
import os
import platform
import sys
import types
from importlib.abc import Loader, MetaPathFinder
from importlib.machinery import ModuleSpec

from . import _asan # noqa: F401 # imported for side effects for setup specific to AddressSanitizer environments
from ._facade import ROOTFacade
from ._python_version import _root_python_version

_runtime_version = platform.python_version()


def _major_minor(v):
return ".".join(v.split(".")[:2])


# Check for Python ABI compatibility with this ROOT build. This check prevents
# hard crashes and undefined behavior, yielding helpful error messages instead.
if _major_minor(_runtime_version) != _major_minor(_root_python_version):
import textwrap

message = f"""
ROOT was built for Python {_root_python_version}, but you are running Python {_runtime_version}.
Python major.minor versions must match. Use a matching Python or ROOT build.
"""
raise ImportError(textwrap.dedent(message))

# Prevent cppyy's check for extra header directory
os.environ["CPPYY_API_PATH"] = "none"
Expand Down
Loading