From 2e9fc463790562e1b9458d1ae442c48109b92cae Mon Sep 17 00:00:00 2001 From: Olivier PELLET-MANY Date: Wed, 26 Mar 2025 09:59:50 +0100 Subject: [PATCH 1/4] Add find python debug executable --- tools/pybind11NewTools.cmake | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 087784c22c..a65832ba95 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -125,14 +125,21 @@ if(NOT _PYBIND11_CROSSCOMPILING) unset(PYTHON_MODULE_EXTENSION CACHE) endif() - set(PYBIND11_PYTHON_EXECUTABLE_LAST - "${${_Python}_EXECUTABLE}" - CACHE INTERNAL "Python executable during the last CMake run") + if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEFINED ${_Python}_EXECUTABLE_DEBUG) + set(PYBIND11_PYTHON_EXECUTABLE_LAST + "${${_Python}_EXECUTABLE_DEBUG}" + CACHE INTERNAL "Python executable during the last CMake run") + else() + set(PYBIND11_PYTHON_EXECUTABLE_LAST + "${${_Python}_EXECUTABLE}" + CACHE INTERNAL "Python executable during the last CMake run") + endif() + if(NOT DEFINED PYTHON_IS_DEBUG) # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process( - COMMAND "${${_Python}_EXECUTABLE}" "-c" + COMMAND "${PYBIND11_PYTHON_EXECUTABLE_LAST}" "-c" "import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))" RESULT_VARIABLE _PYTHON_IS_DEBUG) set(PYTHON_IS_DEBUG @@ -145,7 +152,7 @@ if(NOT _PYBIND11_CROSSCOMPILING) if(NOT DEFINED PYTHON_MODULE_EXTENSION OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX) execute_process( COMMAND - "${${_Python}_EXECUTABLE}" "-c" + "${PYBIND11_PYTHON_EXECUTABLE_LAST}" "-c" "import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))" OUTPUT_VARIABLE _PYTHON_MODULE_EXT_SUFFIX ERROR_VARIABLE _PYTHON_MODULE_EXT_SUFFIX_ERR From 927daa94bb747963712e8c73ebaebf434b6e9fd2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Mar 2025 09:04:03 +0000 Subject: [PATCH 2/4] style: pre-commit fixes --- tools/pybind11NewTools.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index a65832ba95..6e6eaff2a0 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -135,7 +135,6 @@ if(NOT _PYBIND11_CROSSCOMPILING) CACHE INTERNAL "Python executable during the last CMake run") endif() - if(NOT DEFINED PYTHON_IS_DEBUG) # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process( From 45862ced204c1691129df1bd360c67aa01977d47 Mon Sep 17 00:00:00 2001 From: Olivier PELLET-MANY Date: Wed, 26 Mar 2025 09:59:50 +0100 Subject: [PATCH 3/4] Add find python debug executable --- tools/pybind11NewTools.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 6e6eaff2a0..aa4249d789 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -125,7 +125,7 @@ if(NOT _PYBIND11_CROSSCOMPILING) unset(PYTHON_MODULE_EXTENSION CACHE) endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEFINED ${_Python}_EXECUTABLE_DEBUG) + if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEFINED ${_Python}_EXECUTABLE_DEBUG AND IS_EXECUTABLE ${${_Python}_EXECUTABLE_DEBUG}) set(PYBIND11_PYTHON_EXECUTABLE_LAST "${${_Python}_EXECUTABLE_DEBUG}" CACHE INTERNAL "Python executable during the last CMake run") @@ -135,6 +135,7 @@ if(NOT _PYBIND11_CROSSCOMPILING) CACHE INTERNAL "Python executable during the last CMake run") endif() + if(NOT DEFINED PYTHON_IS_DEBUG) # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process( From 836784b377c01f2bf3f1a07cf10c49fd88bd9836 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Mar 2025 14:30:57 +0000 Subject: [PATCH 4/4] style: pre-commit fixes --- tools/pybind11NewTools.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index aa4249d789..f228a8c278 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -125,7 +125,9 @@ if(NOT _PYBIND11_CROSSCOMPILING) unset(PYTHON_MODULE_EXTENSION CACHE) endif() - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND DEFINED ${_Python}_EXECUTABLE_DEBUG AND IS_EXECUTABLE ${${_Python}_EXECUTABLE_DEBUG}) + if(CMAKE_BUILD_TYPE STREQUAL "Debug" + AND DEFINED ${_Python}_EXECUTABLE_DEBUG + AND IS_EXECUTABLE ${${_Python}_EXECUTABLE_DEBUG}) set(PYBIND11_PYTHON_EXECUTABLE_LAST "${${_Python}_EXECUTABLE_DEBUG}" CACHE INTERNAL "Python executable during the last CMake run") @@ -135,7 +137,6 @@ if(NOT _PYBIND11_CROSSCOMPILING) CACHE INTERNAL "Python executable during the last CMake run") endif() - if(NOT DEFINED PYTHON_IS_DEBUG) # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter execute_process(