Repository: computationalgeography/lue (language: python)

Issue:
Use FindPython instead of FindPython3
FindPython2 / FindPython3 allow for concurrent use of both interpreters. We don't need that. Just use FindPython with a mininum version (3.9).

Find and replace all `Python3_XXX` variables in CMake and other code by `Python_XXX`.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index ad89e9c7c..fb9573945 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -153,7 +153,7 @@ jobs:
                       -D LUE_FRAMEWORK_WITH_PYTHON_API=TRUE \
                       -D HPX_ROOT=${{ env.hpx_install_directory }} \
                       -D MDSPAN_ROOT=${{ env.mdspan_install_directory }} \
-                      -D Python3_FIND_VIRTUALENV=ONLY
+                      -D Python_FIND_VIRTUALENV=ONLY
 
         - name: build
           run: |
diff --git a/document/luepy/case_study/CMakeLists.txt b/document/luepy/case_study/CMakeLists.txt
index b6adb7ce7..59cab6563 100644
--- a/document/luepy/case_study/CMakeLists.txt
+++ b/document/luepy/case_study/CMakeLists.txt
@@ -39,7 +39,7 @@ function(preprocess_case_study)
             lue::py
             ${dot_properties_pathname}
         COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=$<TARGET_FILE_DIR:lue::py>/.." ${environment}
-            ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${script_name}
+            ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${script_name}
         COMMAND $<TARGET_FILE:lue_validate> --issues ${dataset_name}
         COMMAND $<TARGET_FILE:lue_translate> export
             --meta ${dot_properties_pathname} ${dataset_name} ${dot_name}
diff --git a/environment/cmake/Lue.cmake b/environment/cmake/Lue.cmake
index 9249aec20..e50c17987 100644
--- a/environment/cmake/Lue.cmake
+++ b/environment/cmake/Lue.cmake
@@ -58,9 +58,9 @@ file(RELATIVE_PATH LUE_BIN_TO_LIB_DIR
 # In this project we need to be able to install the Python package in a certain directory. For
 # that, we create a variable similar to the ones set by GNUInstallDirs. It can be overridden by
 # the user.
-if(Python3_FOUND)
+if(Python_FOUND)
     set(LUE_BUILD_PYTHON_PACKAGE_DIR
-        "${CMAKE_INSTALL_LIBDIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/${LUE_LOWER_PROJECT_NAME}")
+        "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/${LUE_LOWER_PROJECT_NAME}")
 
     set(LUE_INSTALL_PYTHON_PACKAGE_DIR "${LUE_BUILD_PYTHON_PACKAGE_DIR}" CACHE PATH
         "Relative (to install prefix) pathname of directory to install Python package in")
@@ -111,7 +111,7 @@ message(STATUS "CMAKE_INSTALL_LIBDIR          : ${CMAKE_INSTALL_LIBDIR}")
 message(STATUS "CMAKE_INSTALL_LIBEXECDIR      : ${CMAKE_INSTALL_LIBEXECDIR}")
 message(STATUS "CMAKE_INSTALL_INCLUDEDIR      : ${CMAKE_INSTALL_INCLUDEDIR}")
 message(STATUS "CMAKE_INSTALL_DOCDIR          : ${CMAKE_INSTALL_DOCDIR}")
-if(Python3_FOUND)
+if(Python_FOUND)
     message(STATUS "LUE_INSTALL_PYTHON_PACKAGE_DIR: ${LUE_INSTALL_PYTHON_PACKAGE_DIR}")
     message(STATUS "LUE_PYTHON_PACKAGE_TO_LIB_DIR : ${LUE_PYTHON_PACKAGE_TO_LIB_DIR}")
 endif()
diff --git a/environment/cmake/LueConfiguration.cmake b/environment/cmake/LueConfiguration.cmake
index 55f4564d6..3cfb61ef4 100644
--- a/environment/cmake/LueConfiguration.cmake
+++ b/environment/cmake/LueConfiguration.cmake
@@ -298,27 +298,27 @@ endif()
 # ------------------------------------------------------------------------------
 if(LUE_PYTHON_REQUIRED)
     # Order matters: Pybind11 must be searched for after Python has been found.
-    find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy)
+    find_package(Python 3.9 REQUIRED COMPONENTS Interpreter Development NumPy)
 
-    if((Python3_INTERPRETER_ID STREQUAL "Anaconda") OR (Python3_EXECUTABLE MATCHES "^.*conda.*$"))
+    if((Python_INTERPRETER_ID STREQUAL "Anaconda") OR (Python_EXECUTABLE MATCHES "^.*conda.*$"))
         set(LUE_PYTHON_FROM_CONDA TRUE)
 
         # If we use a Conda build environment, then packages should be searched for in the current
         # Conda environment.
-        cmake_path(GET Python3_EXECUTABLE PARENT_PATH LUE_CONDA_PREFIX)
+        cmake_path(GET Python_EXECUTABLE PARENT_PATH LUE_CONDA_PREFIX)
         cmake_path(GET LUE_CONDA_PREFIX PARENT_PATH LUE_CONDA_PREFIX)
         list(APPEND CMAKE_PREFIX_PATH "${LUE_CONDA_PREFIX}")
     endif()
 
-    message(STATUS "Found Python3:")
-    message(STATUS "    Interpreter ID        : ${Python3_INTERPRETER_ID}")
-    message(STATUS "        version           : ${Python3_VERSION}")
-    message(STATUS "        executable        : ${Python3_EXECUTABLE}")
-    message(STATUS "        site-arch         : ${Python3_SITEARCH}")
-    message(STATUS "        site-lib          : ${Python3_SITELIB}")
+    message(STATUS "Found Python:")
+    message(STATUS "    Interpreter ID        : ${Python_INTERPRETER_ID}")
+    message(STATUS "        version           : ${Python_VERSION}")
+    message(STATUS "        executable        : ${Python_EXECUTABLE}")
+    message(STATUS "        site-arch         : ${Python_SITEARCH}")
+    message(STATUS "        site-lib          : ${Python_SITELIB}")
     message(STATUS "    NumPy:")
-    message(STATUS "        version           : ${Python3_NumPy_VERSION}")
-    message(STATUS "        include           : ${Python3_NumPy_INCLUDE_DIRS}")
+    message(STATUS "        version           : ${Python_NumPy_VERSION}")
+    message(STATUS "        include           : ${Python_NumPy_INCLUDE_DIRS}")
     message(STATUS "    LUE_PYTHON_FROM_CONDA : ${LUE_PYTHON_FROM_CONDA}")
 
     if(LUE_PYTHON_FROM_CONDA)
@@ -400,7 +400,7 @@ if(LUE_HPX_REQUIRED)
 
                         # TODO Use LUE_OTF2_WITH_PYTHON to turn on/off the
                         #   build of the Python bindings.
-                        # PYTHON=${Python3_EXECUTABLE} PYTHON_FOR_GENERATOR=:
+                        # PYTHON=${Python_EXECUTABLE} PYTHON_FOR_GENERATOR=:
                         execute_process(
                             COMMAND
                                 ${otf2_SOURCE_DIR}/configure
diff --git a/environment/cmake/LueMacro.cmake b/environment/cmake/LueMacro.cmake
index 6b729554f..929333890 100644
--- a/environment/cmake/LueMacro.cmake
+++ b/environment/cmake/LueMacro.cmake
@@ -323,7 +323,7 @@ function(add_hpx_unit_test)
 
     add_test(NAME ${TEST_EXE_NAME}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
@@ -558,7 +558,7 @@ function(generate_template_instantiation)
 
     add_custom_command(
         OUTPUT ${ARG_OUTPUT_PATHNAME}
-        COMMAND ${Python3_EXECUTABLE} ${LUE_TEMPLATIZE}
+        COMMAND ${Python_EXECUTABLE} ${LUE_TEMPLATIZE}
             ${ARG_INPUT_PATHNAME} ${ARG_OUTPUT_PATHNAME}
             ${ARG_DICTIONARY}
         DEPENDS ${ARG_INPUT_PATHNAME}
diff --git a/environment/conda/bld.bat b/environment/conda/bld.bat
index 087724cfa..324677a5b 100644
--- a/environment/conda/bld.bat
+++ b/environment/conda/bld.bat
@@ -48,7 +48,7 @@ cmake --preset conan-release ^
     -D LUE_FRAMEWORK_WITH_IMAGE_LAND=TRUE ^
     -D LUE_FRAMEWORK_WITH_PYTHON_API=TRUE ^
     -D HPX_IGNORE_COMPILER_COMPATIBILITY=TRUE ^
-    -D Python3_EXECUTABLE="%PYTHON%"
+    -D Python_EXECUTABLE="%PYTHON%"
 if errorlevel 1 exit /b 1
 
 cmake --build build --config Release --target all
diff --git a/environment/conda/build.sh b/environment/conda/build.sh
index bbc45c984..4c3427c6b 100644
--- a/environment/conda/build.sh
+++ b/environment/conda/build.sh
@@ -33,7 +33,7 @@ CMAKE_PREFIX_PATH=build \
         -D LUE_FRAMEWORK_WITH_IMAGE_LAND=TRUE \
         -D LUE_FRAMEWORK_WITH_PYTHON_API=TRUE \
         -D HPX_IGNORE_COMPILER_COMPATIBILITY=TRUE \
-        -D Python3_EXECUTABLE="${PYTHON}"
+        -D Python_EXECUTABLE="${PYTHON}"
 
 cmake --build build --config Release --target all
 cmake --install build --config Release --component lue_runtime
diff --git a/source/data_model/python/CMakeLists.txt b/source/data_model/python/CMakeLists.txt
index 08e9f865c..e2cfda82d 100644
--- a/source/data_model/python/CMakeLists.txt
+++ b/source/data_model/python/CMakeLists.txt
@@ -113,7 +113,7 @@ target_link_libraries(lue_py_data_model
         pybind11::thin_lto
         pybind11::opt_size
         pybind11::windows_extras
-        Python3::NumPy
+        Python::NumPy
         nonstd::span-lite
 )
 
@@ -135,7 +135,7 @@ if(LUE_PYTHON_FROM_CONDA AND NOT DEFINED ENV{CONDA_BUILD})
         TARGET lue_py_data_model
         APPEND
         PROPERTY INSTALL_RPATH
-            ${Python3_LIBRARY_DIRS}
+            ${Python_LIBRARY_DIRS}
     )
 endif()
 
diff --git a/source/framework/image_land/python/CMakeLists.txt b/source/framework/image_land/python/CMakeLists.txt
index 48a0bf70e..b21aee511 100644
--- a/source/framework/image_land/python/CMakeLists.txt
+++ b/source/framework/image_land/python/CMakeLists.txt
@@ -53,7 +53,7 @@ target_link_libraries(lue_py_image_land
         pybind11::thin_lto
         pybind11::opt_size
         pybind11::windows_extras
-        Python3::Python
+        Python::Python
 )
 
 # TODO pybind11_strip does not work on macOS, when building using Conda packages
@@ -74,7 +74,7 @@ if(LUE_PYTHON_FROM_CONDA AND NOT DEFINED ENV{CONDA_BUILD})
         TARGET lue_py_image_land
         APPEND
         PROPERTY INSTALL_RPATH
-            ${Python3_LIBRARY_DIRS}
+            ${Python_LIBRARY_DIRS}
     )
 endif()
 
diff --git a/source/framework/python/CMakeLists.txt b/source/framework/python/CMakeLists.txt
index 46cd59a2f..260dd308f 100644
--- a/source/framework/python/CMakeLists.txt
+++ b/source/framework/python/CMakeLists.txt
@@ -193,7 +193,7 @@ target_link_libraries(lue_py_framework
         pybind11::thin_lto
         pybind11::opt_size
         pybind11::windows_extras
-        Python3::Python
+        Python::Python
 )
 
 # TODO pybind11_strip does not work on macOS, when building using Conda packages
@@ -214,7 +214,7 @@ if(LUE_PYTHON_FROM_CONDA AND NOT DEFINED ENV{CONDA_BUILD})
         TARGET lue_py_framework
         APPEND
         PROPERTY INSTALL_RPATH
-            ${Python3_LIBRARY_DIRS}
+            ${Python_LIBRARY_DIRS}
     )
 endif()
 
diff --git a/source/python/include/lue/py/configure.hpp.in b/source/python/include/lue/py/configure.hpp.in
index de4073f3c..96880dbae 100644
--- a/source/python/include/lue/py/configure.hpp.in
+++ b/source/python/include/lue/py/configure.hpp.in
@@ -2,10 +2,10 @@
 #include <cstdint>
 
 
-#define Python3_VERSION "${Python3_VERSION}"
-#define Python3_VERSION_MAJOR ${Python3_VERSION_MAJOR}
-#define Python3_VERSION_MINOR ${Python3_VERSION_MINOR}
-#define Python3_VERSION_PATCH ${Python3_VERSION_PATCH}
+#define Python_VERSION "${Python_VERSION}"
+#define Python_VERSION_MAJOR ${Python_VERSION_MAJOR}
+#define Python_VERSION_MINOR ${Python_VERSION_MINOR}
+#define Python_VERSION_PATCH ${Python_VERSION_PATCH}
 
 
 namespace lue::py {
@@ -16,7 +16,7 @@ namespace lue::py {
         public:
 
             static constexpr std::int32_t python_version{
-                10000 * Python3_VERSION_MAJOR + 100 * Python3_VERSION_MINOR + Python3_VERSION_PATCH};
+                10000 * Python_VERSION_MAJOR + 100 * Python_VERSION_MINOR + Python_VERSION_PATCH};
 
     };
 
diff --git a/source/qa/python/CMakeLists.txt b/source/qa/python/CMakeLists.txt
index 6e6ee76ab..c4c560df2 100644
--- a/source/qa/python/CMakeLists.txt
+++ b/source/qa/python/CMakeLists.txt
@@ -50,7 +50,7 @@ if(LUE_QA_WITH_PYTHON_API)
             TARGET lue_py_qa
             APPEND
             PROPERTY INSTALL_RPATH
-                ${Python3_LIBRARY_DIRS}
+                ${Python_LIBRARY_DIRS}
         )
     endif()
 


Test patch:
diff --git a/source/data_model/python/test/CMakeLists.txt b/source/data_model/python/test/CMakeLists.txt
index 876d99cc7..6008eada3 100644
--- a/source/data_model/python/test/CMakeLists.txt
+++ b/source/data_model/python/test/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_test(
     NAME lue_py_data_model_python_test
-    COMMAND ${Python3_EXECUTABLE}
+    COMMAND ${Python_EXECUTABLE}
         -m unittest discover
         --verbose
         --start-directory ${CMAKE_CURRENT_SOURCE_DIR}
diff --git a/source/framework/algorithm/test/CMakeLists.txt b/source/framework/algorithm/test/CMakeLists.txt
index 79617731c..f510e20dc 100644
--- a/source/framework/algorithm/test/CMakeLists.txt
+++ b/source/framework/algorithm/test/CMakeLists.txt
@@ -141,7 +141,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/image_land/python/test/CMakeLists.txt b/source/framework/image_land/python/test/CMakeLists.txt
index 084ce7ece..75f0b19a8 100644
--- a/source/framework/image_land/python/test/CMakeLists.txt
+++ b/source/framework/image_land/python/test/CMakeLists.txt
@@ -1,12 +1,12 @@
 add_test(
     NAME lue_py_image_land_python_test
     COMMAND
-        ${Python3_EXECUTABLE} ${HPXRUN}
+        ${Python_EXECUTABLE} ${HPXRUN}
             "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
             "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
             "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
             "--thread" ${LUE_QA_TEST_NR_THREADS_PER_LOCALITY} --
-                ${Python3_EXECUTABLE}
+                ${Python_EXECUTABLE}
                     -m lue_unit_test discover
                     --verbose
                     --start-directory ${CMAKE_CURRENT_SOURCE_DIR}
diff --git a/source/framework/image_land/test/CMakeLists.txt b/source/framework/image_land/test/CMakeLists.txt
index dbbd6fe15..e8a3f5313 100644
--- a/source/framework/image_land/test/CMakeLists.txt
+++ b/source/framework/image_land/test/CMakeLists.txt
@@ -22,7 +22,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/io/test/CMakeLists.txt b/source/framework/io/test/CMakeLists.txt
index 8d2c99c97..d38f46285 100644
--- a/source/framework/io/test/CMakeLists.txt
+++ b/source/framework/io/test/CMakeLists.txt
@@ -22,7 +22,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/model/test/CMakeLists.txt b/source/framework/model/test/CMakeLists.txt
index 26ca4e7f6..bd8fe4711 100644
--- a/source/framework/model/test/CMakeLists.txt
+++ b/source/framework/model/test/CMakeLists.txt
@@ -53,7 +53,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/partitioned_array/test/CMakeLists.txt b/source/framework/partitioned_array/test/CMakeLists.txt
index 9d7f3f267..8c19b6afc 100644
--- a/source/framework/partitioned_array/test/CMakeLists.txt
+++ b/source/framework/partitioned_array/test/CMakeLists.txt
@@ -56,7 +56,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/partitioned_route/test/CMakeLists.txt b/source/framework/partitioned_route/test/CMakeLists.txt
index 425157979..03a201e03 100644
--- a/source/framework/partitioned_route/test/CMakeLists.txt
+++ b/source/framework/partitioned_route/test/CMakeLists.txt
@@ -56,7 +56,7 @@ foreach(name ${names})
 
     add_test(NAME ${test_name}
         COMMAND
-            ${Python3_EXECUTABLE} ${HPXRUN}
+            ${Python_EXECUTABLE} ${HPXRUN}
                 "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
                 "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
                 "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
diff --git a/source/framework/python/test/CMakeLists.txt b/source/framework/python/test/CMakeLists.txt
index e58f29aad..437c53951 100644
--- a/source/framework/python/test/CMakeLists.txt
+++ b/source/framework/python/test/CMakeLists.txt
@@ -1,12 +1,12 @@
 add_test(
     NAME lue_py_framework_python_test
     COMMAND
-        ${Python3_EXECUTABLE} ${HPXRUN}
+        ${Python_EXECUTABLE} ${HPXRUN}
             "--runwrapper" ${LUE_QA_TEST_HPX_RUNWRAPPER}
             "--parcelport" ${LUE_QA_TEST_HPX_PARCELPORT}
             "--localities" ${LUE_QA_TEST_NR_LOCALITIES_PER_TEST}
             "--thread" ${LUE_QA_TEST_NR_THREADS_PER_LOCALITY} --
-                ${Python3_EXECUTABLE}
+                ${Python_EXECUTABLE}
                     -m lue_unit_test discover
                     --verbose
                     --start-directory ${CMAKE_CURRENT_SOURCE_DIR}