From 83ec3e48c34a39fa0273190ca23cea98926b0f4c Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Wed, 9 Oct 2024 17:44:39 -0400 Subject: [PATCH 1/4] Fix check for Python3 (#610) When changing to find_package(Python3) (see #610), the variable PYTHON_VERSION_MAJOR no longer gets set. That caused HAS_PYTHON3 to get set to FALSE and for the test TriBITS_sphinx_rst_generator_UnitTests to not get enabled (but is actually disabled using property DISABLED). NOTE: The CDash feature that reports when tests go missing caught this problem! (I never noticed that when doing local testing). Here is what that CDash email looked like: ---- Summary: [tribits-checkins] FAILED (m=1): TriBITS/TriBITS - tribits_cmake-3.25.2_makefiles_python-3.8_g++-11 - Continuous A submission to CDash for the project TriBITS has missing tests. You have been identified as one of the authors who have checked in changes that are part of this submission or you are listed in the default contact list. Details on the submission can be found at https://my.cdash.org/build/2685504. Project: TriBITS SubProject: TriBITS Site: ubuntu-latest Build Name: tribits_cmake-3.25.2_makefiles_python-3.8_g++-11 Build Time: 2024-10-09 16:55:55 Type: Continuous Total Missing Tests: 1 *Missing Tests* TriBITS_sphinx_rst_generator_UnitTests (https://my.cdash.org/viewTest.php?buildid=2685505) -CDash ---- That is such a nice feature! --- test/doc/CMakeLists.txt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/test/doc/CMakeLists.txt b/test/doc/CMakeLists.txt index 6cc978641..26c550c0c 100644 --- a/test/doc/CMakeLists.txt +++ b/test/doc/CMakeLists.txt @@ -1,10 +1,3 @@ -if (PYTHON_VERSION_MAJOR GREATER_EQUAL 3) - set(HAS_PYTHON3 TRUE) -else() - set(HAS_PYTHON3 FALSE) -endif() - - advanced_set( ${PROJECT_NAME}_ENABLE_DOC_GENERATION_TESTS OFF CACHE BOOL "Enable testing for the build of the documentation, including using Sphinx. Requires docutils, sphinx, and sphinx-rd-theme and will blow away and rebuild the existing documentation in the source tree since the documentation builds in place. Therefore, one must be careful to not blow away non-tracked files." ) @@ -13,7 +6,7 @@ advanced_set( ${PROJECT_NAME}_ENABLE_DOC_GENERATION_TESTS OFF tribits_add_advanced_test( sphinx_rst_generator_UnitTests OVERALL_WORKING_DIRECTORY TEST_NAME OVERALL_NUM_MPI_PROCS 1 - EXCLUDE_IF_NOT_TRUE HAS_PYTHON3 + EXCLUDE_IF_NOT_TRUE Python3_EXECUTABLE TEST_0 CMND ${Python3_EXECUTABLE} ARGS ${CMAKE_CURRENT_SOURCE_DIR}/sphinx_rst_generator_UnitTests.py -v PASS_REGULAR_EXPRESSION "OK" @@ -21,7 +14,6 @@ tribits_add_advanced_test( sphinx_rst_generator_UnitTests DISABLED "Test is broken for long time, see commit c477daa1" ) - tribits_add_advanced_test( build_docs EXCLUDE_IF_NOT_TRUE ${PROJECT_NAME}_ENABLE_DOC_GENERATION_TESTS GIT_EXECUTABLE From 3e050ce8d44a936cac035ebd99d687a4a334fc26 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 10 Oct 2024 14:00:14 -0400 Subject: [PATCH 2/4] Improve Python3 changelog entry with links to more info (#610) --- tribits/CHANGELOG.md | 54 +++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/tribits/CHANGELOG.md b/tribits/CHANGELOG.md index ca6a8724d..d824c7810 100644 --- a/tribits/CHANGELOG.md +++ b/tribits/CHANGELOG.md @@ -4,25 +4,43 @@ ChangeLog for TriBITS ## 2024-10-08: -* **Changed:** The internal TriBITS framework find operation for Python has - been changed from calling `find_package(PythonInterp)` (using the deprecated - `FindPythonInterp.cmake` module) to calling `find_package(Python3)`, which - will find `python3` in the path automatically. The internal variable set by - this operation was changed from `PYTHON_EXECUTABLE` to `Python3_EXECUTABLE` - and TriBITS projects need make that change as well when upgrading TriBITS. - (This change can be made automatically in all of the project's CMake files - by running the script `tribits/refactoring/to-python3.sh `.) However, - backward compatibility for users of TriBITS projects that set `-D - PYTHON_EXECUTABLE=` is provided. If a TriBITS project user sets `-D +* **Changed:** The TriBITS framework find operation for + Python[†](#tribits_python_support) has been changed from + calling `find_package(PythonInterp)` (which uses the deprecated + `FindPythonInterp.cmake` module) to calling `find_package(Python3)` (which + uses [FindPython3.cmake]). In the process, the internal CMake cache + variable set by this operation was changed from `PYTHON_EXECUTABLE` to + `Python3_EXECUTABLE`, and TriBITS projects need make that change as well + when upgrading TriBITS. (This change can be made automatically in all of + the project's CMake files by running the script + `tribits/refactoring/to-python3.sh `.) However, backward compatibility + is provided for users confiugring TriBITS CMake projects which set `-D + PYTHON_EXECUTABLE=`. In this case, if user sets `-D PYTHON_EXECUTABLE=` in the cache, TriBITS will set that value `` - to `Python3_EXECUTABLE` and avoid the call to `find_package(Python3)`; - however, a deprecation warning we be issued by default. TriBITS project - users should change to use `-D Python3_EXECUTABLE=` instead, or just - remove setting `PYTHON_EXECUTABLE` or `Python3_EXECUTABLE` altogether and - just make sure that the desired `python3` executable is in the path. See - issue - [TriBITSPub/TriBITS#610](https://github.com/TriBITSPub/TriBITS/issues/610) - for more details. + to the variable `Python3_EXECUTABLE` and avoid the call to + `find_package(Python3)` (however, a deprecation warning we be issued by + default, see [tribits_deprecated()] and [adjusting CMake DEPRECATION + warnings]). TriBITS project users should change to use `-D + Python3_EXECUTABLE=` instead, or just remove setting + `PYTHON_EXECUTABLE` or `Python3_EXECUTABLE` altogether and just make sure + that the desired `python3` executable is in the path. See issue + [TriBITSPub/TriBITS#610] for more details. + +† **TriBITS Python Support**: See "Find Python" at [Full Processing of TriBITS Project Files], [Python Support] and [Setting or disabling Python] + +[FindPython3.cmake]: https://cmake.org/cmake/help/latest/module/FindPython3.html + +[Full Processing of TriBITS Project Files]: https://tribitspub.github.io/TriBITS/users_guide/index.html#full-tribits-project-configuration + +[Python Support]: https://tribitspub.github.io/TriBITS/users_guide/index.html#python-support + +[Setting or disabling Python]: https://tribitspub.github.io/TriBITS/build_ref/index.html#setting-or-disabling-python + +[tribits_deprecated()]: https://tribitspub.github.io/TriBITS/users_guide/index.html#tribits-deprecated + +[Adjusting CMake DEPRECATION warnings]: https://tribitspub.github.io/TriBITS/build_ref/index.html#adjusting-cmake-deprecation-warnings + +[TriBITSPub/TriBITS#610]: https://github.com/TriBITSPub/TriBITS/issues/610 ## 2023-06-22: From 23135a950201002e601a050a06f244b8f9555da3 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 10 Oct 2024 14:00:46 -0400 Subject: [PATCH 3/4] Add link to FindPython3.cmake and fix typo for unsetting Python3_EXECUTABLE (#610) This typo did not get discovered on the PR review that added this. --- tribits/doc/build_ref/TribitsBuildReferenceBody.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst index c7351ebe2..b8601d6e8 100644 --- a/tribits/doc/build_ref/TribitsBuildReferenceBody.rst +++ b/tribits/doc/build_ref/TribitsBuildReferenceBody.rst @@ -2238,11 +2238,11 @@ To set which Python interpreter is used, configure with:: -D Python3_EXECUTABLE= Otherwise, Python will be found automatically by default using -``find_python(Python3)`` internally. +``find_python(Python3)`` internally (see `FindPython3.cmake`_). -To disable the finding and usage of Python, configure with:: +To disable the finding and usage of Python, configure with (empty):: - -D Python3_EXECUTABLE= + -D Python3_EXECUTABLE= Outputting package dependency information @@ -4505,4 +4505,7 @@ dashboard``. .. _xSDK Community Package Policies: https://doi.org/10.6084/m9.figshare.4495136 +.. _FindPython3.cmake: https://cmake.org/cmake/help/latest/module/FindPython3.html + + .. LocalWords: templated instantiation Makefiles CMake From 22c6ffe45727105a19a21744364c15bf92dde2b6 Mon Sep 17 00:00:00 2001 From: "Roscoe A. Bartlett" Date: Thu, 10 Oct 2024 14:10:24 -0400 Subject: [PATCH 4/4] Fix up and better document to-python3.sh (#610) Now this is safer to run on a project's entire source tree and it is documented to explain what this is for. --- tribits/refactoring/to-python3.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tribits/refactoring/to-python3.sh b/tribits/refactoring/to-python3.sh index 2a295f5f6..4c40c0d67 100755 --- a/tribits/refactoring/to-python3.sh +++ b/tribits/refactoring/to-python3.sh @@ -1,12 +1,23 @@ #!/bin/sh # +# Refactor a TriBITS project's CMake files for the change from +# find_package(PythonInterp) to find_package(Python3) (see CHANGELOG.md entry +# for 2024-10-08). +# # Usage: # # to-python3.sh # +# NOTES: +# * This is safe to run multiple times on the same set of files. +# * This is safe to run from the base project source tree. +# * This will exclude any files under '.git/' +# * This will exclude any files under 'tribits/' directories (so it will not mess up TriBITS) +# _SCRIPT_DIR=`echo $0 | sed "s/\(.*\)\/to-python3[.]sh/\1/g"` baseDir=$1 find ${baseDir} -type f \ \( -name CMakeLists.txt -or -name "*.cmake" -or -name "*.cmake.in" -or -name "*.rst" \) \ + ! -wholename "*/.git/*" ! -wholename "*/tribits/*" \ -exec $_SCRIPT_DIR/token-replace.py -t PYTHON_EXECUTABLE -r Python3_EXECUTABLE -f {} ';'