Improve discovery for Debian default version of Python

ci/unstable
Timo Röhling 2 years ago
parent b0906ae4ae
commit d76385e96b

@ -1,34 +1,104 @@
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Mon, 13 Sep 2021 18:59:25 +0200
Date: Fri, 14 Oct 2022 11:59:04 +0200
Subject: Prefer Debian default version of Python
Forwarded: not-needed
---
Modules/FindPython/Support.cmake | 14 ++++++++++++++
1 file changed, 14 insertions(+)
Modules/FindPython/Support.cmake | 20 ++++++++++++++++++++
Modules/FindPythonInterp.cmake | 20 ++++++++++++++++++++
Modules/FindPythonLibs.cmake | 20 ++++++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake
index c4fae6b..51fa989 100644
index c4fae6b..3e4279e 100644
--- a/Modules/FindPython/Support.cmake
+++ b/Modules/FindPython/Support.cmake
@@ -23,6 +23,20 @@ if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
@@ -23,6 +23,26 @@ if (NOT DEFINED _${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR)
endif()
if (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "3")
set(_${_PYTHON_PREFIX}_VERSIONS 3.12 3.11 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
+ # Debian-specific: prefer current default version
+ execute_process(
+ COMMAND py3versions -vd
+ OUTPUT_VARIABLE _${_PYTHON_PREFIX}_DEFAULT_VERSION
+ RESULT_VARIABLE _${_PYTHON_PREFIX}_DEFAULT_RESULT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+ if(NOT _${_PYTHON_PREFIX}_DEFAULT_RESULT)
+ list(REMOVE_ITEM _${_PYTHON_PREFIX}_VERSIONS ${_${_PYTHON_PREFIX}_DEFAULT_VERSION})
+ list(INSERT _${_PYTHON_PREFIX}_VERSIONS 0 ${_${_PYTHON_PREFIX}_DEFAULT_VERSION})
+ if(NOT DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ execute_process(
+ COMMAND py3versions -vd
+ OUTPUT_VARIABLE _PYTHON3_DEFAULT_VERSION
+ RESULT_VARIABLE _PYTHON3_DEFAULT_RESULT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+ if(_PYTHON3_DEFAULT_RESULT EQUAL "0")
+ set(PYTHON3_DEBIAN_DEFAULT_VERSION "${_PYTHON3_DEFAULT_VERSION}" CACHE INTERNAL "Current Python 3 default version in Debian")
+ endif()
+ unset(_PYTHON3_DEFAULT_VERSION)
+ unset(_PYTHON3_DEFAULT_RESULT)
+ endif()
+ unset(_${_PYTHON_PREFIX}_DEFAULT_RESULT)
+ unset(_${_PYTHON_PREFIX}_DEFAULT_VERSION)
+ if(DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ list(REMOVE_ITEM _${_PYTHON_PREFIX}_VERSIONS ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ list(INSERT _${_PYTHON_PREFIX}_VERSIONS 0 ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ endif()
+ # End of Debian-specific code
elseif (_${_PYTHON_PREFIX}_REQUIRED_VERSION_MAJOR EQUAL "2")
set(_${_PYTHON_PREFIX}_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
else()
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 7ad3587..d6e41b0 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -76,6 +76,26 @@ if(PythonInterp_FIND_VERSION)
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonInterp_FIND_VERSION_MAJOR}_VERSIONS})
endif()
else()
+ # Debian-specific: prefer current default version
+ if(NOT DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ execute_process(
+ COMMAND py3versions -vd
+ OUTPUT_VARIABLE _PYTHON3_DEFAULT_VERSION
+ RESULT_VARIABLE _PYTHON3_DEFAULT_RESULT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+ if(_PYTHON3_DEFAULT_RESULT EQUAL "0")
+ set(PYTHON3_DEBIAN_DEFAULT_VERSION "${_PYTHON3_DEFAULT_VERSION}" CACHE INTERNAL "Current Python 3 default version in Debian")
+ endif()
+ unset(_PYTHON3_DEFAULT_VERSION)
+ unset(_PYTHON3_DEFAULT_RESULT)
+ endif()
+ if(DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ list(REMOVE_ITEM _PYTHON3_VERSIONS ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ list(INSERT _PYTHON3_VERSIONS 0 ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ endif()
+ # End of Debian-specific code
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
endif()
find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
index 43a84dd..8bf2015 100644
--- a/Modules/FindPythonLibs.cmake
+++ b/Modules/FindPythonLibs.cmake
@@ -103,6 +103,26 @@ if(PythonLibs_FIND_VERSION)
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION_MAJOR}_VERSIONS})
endif()
else()
+ # Debian-specific: prefer current default version
+ if(NOT DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ execute_process(
+ COMMAND py3versions -vd
+ OUTPUT_VARIABLE _PYTHON3_DEFAULT_VERSION
+ RESULT_VARIABLE _PYTHON3_DEFAULT_RESULT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+ if(_PYTHON3_DEFAULT_RESULT EQUAL "0")
+ set(PYTHON3_DEBIAN_DEFAULT_VERSION "${_PYTHON3_DEFAULT_VERSION}" CACHE INTERNAL "Current Python 3 default version in Debian")
+ endif()
+ unset(_PYTHON3_DEFAULT_VERSION)
+ unset(_PYTHON3_DEFAULT_RESULT)
+ endif()
+ if(DEFINED PYTHON3_DEBIAN_DEFAULT_VERSION)
+ list(REMOVE_ITEM _PYTHON3_VERSIONS ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ list(INSERT _PYTHON3_VERSIONS 0 ${PYTHON3_DEBIAN_DEFAULT_VERSION})
+ endif()
+ # End of Debian-specific code
set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
endif()

Loading…
Cancel
Save