From 54d00786bfdb0514a859834c6a9e172a41a8988a Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 23 Jan 2026 12:52:02 -0500 Subject: [PATCH 1/2] refactor: move python examples to `examples/` --- bind/python/README.md | 2 +- bind/python/meson.build | 11 ------- .../iguana_ex_python_00_run_functions.py | 0 .../iguana_ex_python_01_action_functions.py | 0 .../iguana_ex_python_hipopy.py | 0 examples/meson.build | 32 ++++++++++++++++++- meson.build | 9 ++++++ 7 files changed, 41 insertions(+), 13 deletions(-) rename {bind/python => examples}/iguana_ex_python_00_run_functions.py (100%) rename {bind/python => examples}/iguana_ex_python_01_action_functions.py (100%) rename {bind/python => examples}/iguana_ex_python_hipopy.py (100%) diff --git a/bind/python/README.md b/bind/python/README.md index ca9158dd1..dbff9624a 100644 --- a/bind/python/README.md +++ b/bind/python/README.md @@ -36,7 +36,7 @@ For Python to be able to find and use these bindings, you need to set some envir ## Running the Examples -Example Python scripts are found in this directory as `iguana_ex_*.py`; they will be installed in the `bin/` subdirectory. +Example Python scripts are found in the [`examples/` directory as `iguana_ex_python*.py`](/examples); they will be installed in the `bin/` subdirectory. Most of them are analogous to the C++ examples, but some may be specific to the Python bindings. diff --git a/bind/python/meson.build b/bind/python/meson.build index b55d22d17..d11240e0d 100644 --- a/bind/python/meson.build +++ b/bind/python/meson.build @@ -1,12 +1 @@ install_subdir('pyiguana', install_dir: project_pythondir) - -if (get_option('install_examples')) - python_examples = [ - 'iguana_ex_python_00_run_functions.py', - 'iguana_ex_python_01_action_functions.py', - 'iguana_ex_python_hipopy.py', - ] - foreach example : python_examples - install_data(example, install_dir: get_option('bindir'), install_mode: 'rwxr-xr-x') - endforeach -endif diff --git a/bind/python/iguana_ex_python_00_run_functions.py b/examples/iguana_ex_python_00_run_functions.py similarity index 100% rename from bind/python/iguana_ex_python_00_run_functions.py rename to examples/iguana_ex_python_00_run_functions.py diff --git a/bind/python/iguana_ex_python_01_action_functions.py b/examples/iguana_ex_python_01_action_functions.py similarity index 100% rename from bind/python/iguana_ex_python_01_action_functions.py rename to examples/iguana_ex_python_01_action_functions.py diff --git a/bind/python/iguana_ex_python_hipopy.py b/examples/iguana_ex_python_hipopy.py similarity index 100% rename from bind/python/iguana_ex_python_hipopy.py rename to examples/iguana_ex_python_hipopy.py diff --git a/examples/meson.build b/examples/meson.build index 8ba5bb5c0..e760a92fc 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -2,8 +2,9 @@ example_config_files_prefix = project_etcdir / 'examples' install_subdir('config', install_dir: example_config_files_prefix, strip_directory: true) -# example source information +# compiled examples example_sources = { + # C++ 'iguana_ex_cpp_00_run_functions': {'sources': [ 'iguana_ex_cpp_00_run_functions.cc' ]}, 'iguana_ex_cpp_00_run_functions_with_banks': {'sources': [ 'iguana_ex_cpp_00_run_functions_with_banks.cc' ]}, 'iguana_ex_cpp_01_action_functions': {'sources': [ 'iguana_ex_cpp_01_action_functions.cc' ]}, @@ -16,6 +17,7 @@ example_sources = { 'sources': [ 'iguana_ex_cpp_config_files.cc' ], 'test_args': [ get_option('prefix') / example_config_files_prefix ], }, + # Fortran 'iguana_ex_fortran_01_action_functions': { 'sources': [ 'iguana_ex_fortran_01_action_functions.f' ], 'build_this': get_option('bind_fortran') and ROOT_dep.found(), # depends on physics::InclusiveKinematics, which depends on ROOT @@ -48,3 +50,31 @@ foreach example, info : example_sources endif endif endforeach + +# Python examples +if (get_option('bind_python')) + python_examples = [ + 'iguana_ex_python_00_run_functions.py', + 'iguana_ex_python_01_action_functions.py', + 'iguana_ex_python_hipopy.py', + ] + foreach example : python_examples + install_data( + example, + install_dir: get_option('bindir'), + install_mode: 'rwxr-xr-x' + ) + # FIXME: currently these are just tested in CI; there is some environment issue here... + # if fs.is_file(get_option('test_data_file')) + # test( + # example, + # prog_python, + # suite: [ 'example', 'single_threaded' ], + # args: [ example, get_option('test_data_file'), '100' ], # don't run too many events, or meson test log will be huge + # workdir: meson.current_source_dir(), + # env: project_test_env, + # timeout: 240, + # ) + # endif + endforeach +endif diff --git a/meson.build b/meson.build index 28d21364d..a1651c7ce 100644 --- a/meson.build +++ b/meson.build @@ -78,6 +78,11 @@ prog_ruby = find_program( version: '>=3.0.0', required: use_chameleon, ) +prog_python = find_program( + 'python3', + version: '>=3.0.0', + required: get_option('bind_python'), +) rcdb_dep = dependency( 'rcdb', fallback: ['rcdb', 'rcdb_dep'], @@ -178,6 +183,10 @@ project_test_env.set( 'LSAN_OPTIONS', 'suppressions=' + meson.project_source_root() / 'meson' / 'lsan.supp', ) +project_test_env.prepend( + 'PYTHONPATH', + meson.project_source_root() / 'bind' / 'python' +) # set preprocessor macros add_project_arguments('-DIGUANA_ETCDIR="' + get_option('prefix') / project_etcdir + '"', language: [ 'cpp' ]) From 6f144156bcee14c5ac9dc21b33d901d714dcb1a9 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 23 Jan 2026 18:32:13 -0500 Subject: [PATCH 2/2] fix: python stuff --- bind/python/requirements.txt | 8 ++++---- examples/iguana_ex_python_00_run_functions.py | 6 +++--- examples/meson.build | 4 +++- meson.build | 2 +- meson/setup_python_venv.sh | 7 +++++++ 5 files changed, 18 insertions(+), 9 deletions(-) create mode 100755 meson/setup_python_venv.sh diff --git a/bind/python/requirements.txt b/bind/python/requirements.txt index a9ea7c103..1c1a7428c 100644 --- a/bind/python/requirements.txt +++ b/bind/python/requirements.txt @@ -1,6 +1,6 @@ -cppyy==3.1.2 -cppyy-backend==1.15.2 -cppyy-cling==6.30.0 -CPyCppyy==1.12.16 +cppyy==3.5.0 +cppyy-backend==1.15.3 +cppyy-cling==6.32.8 +CPyCppyy==1.13.0 pkgconfig==1.5.5 hipopy==2.0.1 diff --git a/examples/iguana_ex_python_00_run_functions.py b/examples/iguana_ex_python_00_run_functions.py index 1f82093a3..7e350f4a1 100755 --- a/examples/iguana_ex_python_00_run_functions.py +++ b/examples/iguana_ex_python_00_run_functions.py @@ -44,9 +44,9 @@ # set log levels # NOTE: this can also be done in a config file -seq.SetOption('clas12::EventBuilderFilter', 'log', 'info') -seq.SetOption('clas12::SectorFinder', 'log', 'info') -seq.SetOption('clas12::rga::MomentumCorrection', 'log', 'info') +seq.SetLogLevel('clas12::EventBuilderFilter', 'info') +seq.SetLogLevel('clas12::SectorFinder', 'info') +seq.SetLogLevel('clas12::rga::MomentumCorrection', 'info') # set algorithm options # NOTE: this can also be done in a config file, but setting options here OVERRIDES config file settings diff --git a/examples/meson.build b/examples/meson.build index e760a92fc..94eebeec5 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -64,7 +64,9 @@ if (get_option('bind_python')) install_dir: get_option('bindir'), install_mode: 'rwxr-xr-x' ) - # FIXME: currently these are just tested in CI; there is some environment issue here... + # FIXME: test disabled, because of https://github.com/JeffersonLab/iguana/issues/427 + # and many of us have Clas12root libraries in LD_LIBRARY_PATH; anyway, these scripts + # are tested on CI at least # if fs.is_file(get_option('test_data_file')) # test( # example, diff --git a/meson.build b/meson.build index a1651c7ce..6449b2469 100644 --- a/meson.build +++ b/meson.build @@ -185,7 +185,7 @@ project_test_env.set( ) project_test_env.prepend( 'PYTHONPATH', - meson.project_source_root() / 'bind' / 'python' + get_option('prefix') / 'python' ) # set preprocessor macros diff --git a/meson/setup_python_venv.sh b/meson/setup_python_venv.sh new file mode 100755 index 000000000..22920a1b3 --- /dev/null +++ b/meson/setup_python_venv.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail +python -m venv .venv +source .venv/bin/activate +python -m pip install -r bind/python/requirements.txt +python -m pip install -r doc/mkdocs/requirements.txt +echo "DONE: now source one of the activate scripts in '.venv/bin/'"