From fe2dc40e83a9e5aebcdbcbc68094426b4e6d70a8 Mon Sep 17 00:00:00 2001 From: Lee Newberg Date: Wed, 22 Apr 2026 14:27:29 -0400 Subject: [PATCH 1/3] BUG: Depend upon Python / pybind11 only if requested --- CMakeLists.txt | 19 +++++++++---------- exputil/DiskDensityFunc.cc | 3 ++- include/DiskDensityFunc.H | 8 ++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17f9b64e0..335cefc47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ if(ENABLE_MINIMAL) set(ENABLE_UTILS OFF) set(ENABLE_TESTS OFF) endif() - + # Metaflag for pyEXP only if(ENABLE_PYEXP_ONLY) @@ -86,7 +86,7 @@ if(ENABLE_PYEXP_ONLY) set(ENABLE_UTILS OFF) set(ENABLE_TESTS OFF) endif() - + # Set mpirun launcher for CTest set(EXP_MPI_LAUNCH "mpirun" CACHE STRING "Command to run an MPI application (for unit tests only)") @@ -298,13 +298,13 @@ if(ENABLE_TESTS) add_subdirectory(tests) endif() -# try to find pybind11 and build wrapper python module -find_package(Python3 COMPONENTS Interpreter Development) -message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") -if(Python3_FOUND) - set(HAVE_PYTHON3 TRUE) -else() - if(ENABLE_PYEXP) +if(ENABLE_PYEXP) + # try to find pybind11 and build wrapper python module + find_package(Python3 COMPONENTS Interpreter Development) + message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") + if(Python3_FOUND) + set(HAVE_PYTHON3 TRUE) + else() message(FATAL_ERROR "You asked for pyEXP but I cannot find a Python3 environment. Please make Python3 available or disable pyEXP. CMake will exit." ) endif() endif() @@ -405,4 +405,3 @@ set(CMAKE_CXX_FLAGS_UBSAN # from the same source. configure_file(${CMAKE_SOURCE_DIR}/config_cmake.h_in ${CMAKE_BINARY_DIR}/config_exp.h) include_directories(${PROJECT_BINARY_DIR}) - diff --git a/exputil/DiskDensityFunc.cc b/exputil/DiskDensityFunc.cc index 65418193e..c8dfd3587 100644 --- a/exputil/DiskDensityFunc.cc +++ b/exputil/DiskDensityFunc.cc @@ -1,3 +1,4 @@ +#include #include "DiskDensityFunc.H" #ifdef HAVE_PYTHON3 @@ -38,7 +39,7 @@ DiskDensityFunc::DiskDensityFunc(const std::string& modulename, const std::string& funcname) : funcname(funcname) { - throw std::runtime_error("DiskDensityFunc: you environoment does not have Python3 support. Use a built-in density target or install Python3 and recompile"); + throw std::runtime_error("DiskDensityFunc: your environoment does not have Python3 support. Use a built-in density target or install Python3 and recompile"); } DiskDensityFunc::~DiskDensityFunc() diff --git a/include/DiskDensityFunc.H b/include/DiskDensityFunc.H index 637d8cb14..ba874a3fe 100644 --- a/include/DiskDensityFunc.H +++ b/include/DiskDensityFunc.H @@ -2,9 +2,11 @@ #define _DiskDensityFunc_H_ #include +#include #include "config_exp.h" +#ifdef HAVE_PYTHON3 #include #include @@ -26,12 +28,14 @@ a = 1.0 # Scale radius h = 0.2 # Scale height f = math.exp(-0.5*math.fabs(z)/h) # Prevent overflows - sech = 2.0*f / (1.0 + f*f) # + sech = 2.0*f / (1.0 + f*f) # return math.exp(-R/a)*sech*sech/(8*math.pi*h*a*a) - + --------------------------cut here-------------------------------- */ +#endif + class __attribute__((visibility("default"))) DiskDensityFunc { From e04afc491ebfe2a525bb2285cbb67f7ac9ae7e89 Mon Sep 17 00:00:00 2001 From: Lee Newberg Date: Thu, 2 Jul 2026 13:48:32 -0400 Subject: [PATCH 2/3] ENH: Add and use cmake flag DISABLE_PYTHON Also, undo previous commit per discussion at https://github.com/EXP-code/EXP/pull/217 --- CMakeLists.txt | 15 +++++++++------ exputil/DiskDensityFunc.cc | 1 - include/DiskDensityFunc.H | 8 ++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 335cefc47..d638baf72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ option(ENABLE_TESTS "Enable build tests for EXP, pyEXP and helpers" ON) option(ENABLE_MINIMAL "Compile EXP support libraries only" OFF) option(BUILD_SHARED_LIBS "Build using shared libraries" ON) option(BUILD_DOCS "Build documentation" OFF) +option(DISABLE_PYTHON "Disable the Python development environment" OFF) # Metaflag for minimal build @@ -298,13 +299,15 @@ if(ENABLE_TESTS) add_subdirectory(tests) endif() -if(ENABLE_PYEXP) - # try to find pybind11 and build wrapper python module +# try to find pybind11 and build wrapper python module +if (NOT DISABLE_PYTHON) find_package(Python3 COMPONENTS Interpreter Development) - message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") - if(Python3_FOUND) - set(HAVE_PYTHON3 TRUE) - else() +endif() +message(STATUS "python3 include dirs: ${Python3_INCLUDE_DIRS}") +if(Python3_FOUND) + set(HAVE_PYTHON3 TRUE) +else() + if(ENABLE_PYEXP) message(FATAL_ERROR "You asked for pyEXP but I cannot find a Python3 environment. Please make Python3 available or disable pyEXP. CMake will exit." ) endif() endif() diff --git a/exputil/DiskDensityFunc.cc b/exputil/DiskDensityFunc.cc index c8dfd3587..44ad15990 100644 --- a/exputil/DiskDensityFunc.cc +++ b/exputil/DiskDensityFunc.cc @@ -1,4 +1,3 @@ -#include #include "DiskDensityFunc.H" #ifdef HAVE_PYTHON3 diff --git a/include/DiskDensityFunc.H b/include/DiskDensityFunc.H index ba874a3fe..637d8cb14 100644 --- a/include/DiskDensityFunc.H +++ b/include/DiskDensityFunc.H @@ -2,11 +2,9 @@ #define _DiskDensityFunc_H_ #include -#include #include "config_exp.h" -#ifdef HAVE_PYTHON3 #include #include @@ -28,14 +26,12 @@ a = 1.0 # Scale radius h = 0.2 # Scale height f = math.exp(-0.5*math.fabs(z)/h) # Prevent overflows - sech = 2.0*f / (1.0 + f*f) # + sech = 2.0*f / (1.0 + f*f) # return math.exp(-R/a)*sech*sech/(8*math.pi*h*a*a) - + --------------------------cut here-------------------------------- */ -#endif - class __attribute__((visibility("default"))) DiskDensityFunc { From 1d498f8c113af8279ad4faeb30504e76f71d74fd Mon Sep 17 00:00:00 2001 From: Lee Newberg Date: Thu, 2 Jul 2026 16:16:53 -0400 Subject: [PATCH 3/3] Need more includes when Python is not included --- include/DiskDensityFunc.H | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/DiskDensityFunc.H b/include/DiskDensityFunc.H index 637d8cb14..f2b521e5b 100644 --- a/include/DiskDensityFunc.H +++ b/include/DiskDensityFunc.H @@ -2,11 +2,15 @@ #define _DiskDensityFunc_H_ #include +#include +#include #include "config_exp.h" +#ifdef HAVE_PYTHON3 #include #include +#endif /** Python disk-density function wrapper @@ -26,9 +30,9 @@ a = 1.0 # Scale radius h = 0.2 # Scale height f = math.exp(-0.5*math.fabs(z)/h) # Prevent overflows - sech = 2.0*f / (1.0 + f*f) # + sech = 2.0*f / (1.0 + f*f) # return math.exp(-R/a)*sech*sech/(8*math.pi*h*a*a) - + --------------------------cut here-------------------------------- */