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
2 changes: 1 addition & 1 deletion bindings/jupyroot/python/JupyROOT/helpers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# For the list of contributors see $ROOTSYS/README/CREDITS. #
################################################################################

from threading import Thread
from time import sleep as timeSleep
from sys import platform

Check failure on line 17 in bindings/jupyroot/python/JupyROOT/helpers/handlers.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/jupyroot/python/JupyROOT/helpers/handlers.py:17:17: F401 `sys.platform` imported but unused
from os import path

Check failure on line 18 in bindings/jupyroot/python/JupyROOT/helpers/handlers.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/jupyroot/python/JupyROOT/helpers/handlers.py:18:16: F401 `os.path` imported but unused
import queue

from JupyROOT import helpers
import libROOTPythonizations as _lib
import ROOT.libROOTPythonizations as _lib

Check failure on line 22 in bindings/jupyroot/python/JupyROOT/helpers/handlers.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/jupyroot/python/JupyROOT/helpers/handlers.py:15:1: I001 Import block is un-sorted or un-formatted


class IOHandler(object):
Expand Down Expand Up @@ -179,7 +179,7 @@
if not silent:
printFunction(ioHandler)
ioHandler.Clear()
if executor.HasFinished(): break

Check failure on line 182 in bindings/jupyroot/python/JupyROOT/helpers/handlers.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E701)

bindings/jupyroot/python/JupyROOT/helpers/handlers.py:182:34: E701 Multiple statements on one line (colon)
timeSleep(.1)
executor.Wait()
ioHandler.EndCapture()
Expand Down
25 changes: 19 additions & 6 deletions bindings/pyroot/pythonizations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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)

Expand Down Expand Up @@ -212,16 +225,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
Expand Down
21 changes: 15 additions & 6 deletions bindings/pyroot/pythonizations/python/ROOT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,32 @@
# For the list of contributors see $ROOTSYS/README/CREDITS. #
################################################################################

from os import environ
import importlib

Check failure on line 11 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:11:8: F401 `importlib` imported but unused
import os
import sys

# Prevent cppyy's check for the PCH
environ["CLING_STANDARD_PCH"] = "none"
os.environ["CLING_STANDARD_PCH"] = "none"

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

# Prevent cppyy from filtering ROOT libraries
environ["CPPYY_NO_ROOT_FILTER"] = "1"
os.environ["CPPYY_NO_ROOT_FILTER"] = "1"

# The libROOTPythonizations CPython extension is in the same directory as the
# ROOT Python module, but to find the other ROOT libraries we need to also add
# the path of the ROOT library directory (only needed on Windows). For example,
# if the ROOT Python module is in $ROOTSYS/bin/ROOT/__init__.py, the libraries
# are usually in $ROOTSYS/bin.
if 'win32' in sys.platform:
root_module_path = os.path.dirname(__file__) # expected to be $ROOTSYS/bin/ROOT
os.add_dll_directory(os.path.dirname(root_module_path)) # expected to be $ROOTSYS/bin

# Do setup specific to AddressSanitizer environments
from . import _asan

Check failure on line 34 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:34:15: F401 `._asan` imported but unused; consider removing, adding to `__all__`, or using a redundant alias

import cppyy

Check failure on line 36 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:34:1: I001 Import block is un-sorted or un-formatted
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).
Expand All @@ -34,12 +43,12 @@
_cached_strings.append(sys.intern(s))

# Trigger the addition of the pythonizations
from ._pythonization import _register_pythonizations

Check failure on line 46 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:46:1: E402 Module level import not at top of file

_register_pythonizations()

# Check if we are in the IPython shell
import builtins

Check failure on line 51 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:51:1: E402 Module level import not at top of file

_is_ipython = hasattr(builtins, "__IPYTHON__")

Expand All @@ -64,7 +73,7 @@
__all__ = _PoisonedDunderAll()

# Configure ROOT facade module
import sys

Check failure on line 76 in bindings/pyroot/pythonizations/python/ROOT/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

bindings/pyroot/pythonizations/python/ROOT/__init__.py:76:1: E402 Module level import not at top of file
from ._facade import ROOTFacade

_root_facade = ROOTFacade(sys.modules[__name__], _is_ipython)
Expand Down
20 changes: 13 additions & 7 deletions bindings/pyroot/pythonizations/python/ROOT/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -35,6 +35,7 @@ def _ipython_config():

from IPython import get_ipython
from IPython.terminal import pt_inputhooks
from IPython.terminal.interactiveshell import TerminalInteractiveShell

def inputhook(context):
while not context.input_is_ready():
Expand All @@ -44,7 +45,10 @@ def inputhook(context):
pt_inputhooks.register('ROOT', inputhook)

ipy = get_ipython()
if ipy:

# Only the TerminalInteractiveShell will use the input hooks that are
# registered via terminal.pt_inputhooks.
if ipy and isinstance(ipy, TerminalInteractiveShell):
get_ipython().run_line_magic('gui', 'ROOT')

@staticmethod
Expand Down Expand Up @@ -75,10 +79,11 @@ def init_graphics(self):

# Note that we only end up in this function if gROOT.IsBatch() is false
import __main__
if self._is_ipython and 'IPython' in sys.modules and sys.modules['IPython'].version_info[0] >= 5:

if self._is_ipython and "IPython" in sys.modules and sys.modules["IPython"].version_info[0] >= 5:
# ipython and notebooks, register our event processing with their hooks
self._ipython_config()
elif sys.flags.interactive == 1 or not hasattr(__main__, '__file__') or gSystem.InheritsFrom('TMacOSXSystem'):
elif sys.flags.interactive == 1 or not hasattr(__main__, "__file__") or gSystem.InheritsFrom("TMacOSXSystem"):
# Python in interactive mode, use the PyOS_InputHook to call our event processing
# - sys.flags.interactive checks for the -i flags passed to python
# - __main__ does not have the attribute __file__ if the Python prompt is started directly
Expand All @@ -94,12 +99,13 @@ def _process_root_events(self):
while self.keep_polling:
gSystem.ProcessEvents()
time.sleep(0.01)

import threading
self.keep_polling = True # Used to shut down the thread safely at teardown time

self.keep_polling = True # Used to shut down the thread safely at teardown time
update_thread = threading.Thread(None, _process_root_events, None, (self,))
self.process_root_events = update_thread # The thread is joined at teardown time
self.process_root_events = update_thread # The thread is joined at teardown time
update_thread.daemon = True
update_thread.start()

self._set_display_hook()

2 changes: 1 addition & 1 deletion bindings/pyroot/pythonizations/python/ROOT/_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def pythonize_cppinstance():
import cppyy
from libROOTPythonizations import AddCPPInstancePickling
from ROOT.libROOTPythonizations import AddCPPInstancePickling

klass = cppyy._backend.CPPInstance

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _rdataframe(local_rdf, distributed_rdf):

def rdataframe(*args, **kwargs):
import ROOT
from libROOTPythonizations import PyObjRefCounterAsStdAny
from ROOT.libROOTPythonizations import PyObjRefCounterAsStdAny

if kwargs.get("executor", None) is not None:
rdf = distributed_rdf(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
################################################################################

import cppyy
from libROOTPythonizations import AddTClassDynamicCastPyz
from ROOT.libROOTPythonizations import AddTClassDynamicCastPyz


def pythonize_tclass():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading