In order to pay the technical debt that is the Python 2 support I
intend to start removing its support.

The first step is to change the build support to ignore Python 2.

Since that is code that, usually, I run away from I would like to get
your feedback before committing it. Because if this breaks the package
does not build and that is a huge problem. :-)

@Jean-Marc is the code OK for the autotools?
@Kornel is the code right for cmake?


There is another change that deserves to be discussed, in the process I
have bumped the minimum python version to be 3.10.

Assuming that the next development cycle takes 2.5 years this will be a
version that will be 5 years old by then and so it should be widely
available.


In this particular case the reason to jump directly to 3.10 is the
structural pattern matching:

https://docs.python.org/3/whatsnew/3.10.html#pep-634-structural-pattern-matching

FWIW notice that this is a lot more powerful than the usual C/C++
switch.
I think that some of our code, like lyx2lyx, can take direct advantage
of this feature.

Best regards,
-- 
José Abílio
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 26bca21728..43a524c655 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -924,26 +924,17 @@ unset(PYTHON_VERSION_MAJOR)
 unset(PYTHON_VERSION_MINOR)
 unset(PYTHON_VERSION_STRING)
 if (CMAKE_VERSION VERSION_LESS "3.13")
-  find_package(PythonInterp 3.5 QUIET)
+  find_package(PythonInterp 3.10 QUIET)
   if(NOT PYTHONINTERP_FOUND)
-    find_package(PythonInterp 2.0 REQUIRED)
-    if(NOT PYTHON_VERSION_STRING VERSION_LESS 2.8)
-      message(FATAL_ERROR "Python interpreter found, but is not suitable")
-    endif()
+	message(FATAL_ERROR "Python interpreter not found or not suitable")
   endif()
   set(LYX_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Python to be used by LyX")
 else()
-  find_package(Python3 3.5 QUIET)
+  find_package(Python3 3.10 QUIET)
   if(NOT Python3_Interpreter_FOUND)
-    unset(PYTHON_EXECUTABLE CACHE)
-    find_package(Python2 2.0 REQUIRED)
-    if(NOT Python2_VERSION VERSION_LESS 2.8)
-      message(FATAL_ERROR "Python interpreter found, but is not suitable")
-    endif()
-    set(LYX_PYTHON_EXECUTABLE ${Python2_EXECUTABLE} CACHE FILEPATH "Python to be used by LyX")
-  else()
-    set(LYX_PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Python to be used by LyX")
+	message(FATAL_ERROR "Python interpreter not found or not suitable")
   endif()
+  set(LYX_PYTHON_EXECUTABLE ${Python3_EXECUTABLE} CACHE FILEPATH "Python to be used by LyX")
 endif()
 
 if(LYX_NLS)
diff --git a/config/lyxpython.m4 b/config/lyxpython.m4
index 21d0d8a963..274e7742d6 100644
--- a/config/lyxpython.m4
+++ b/config/lyxpython.m4
@@ -10,19 +10,18 @@
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
 
-dnl Usage: LYX_PATH_PYTHON23(PY2-MIN-VERSION, PYTHON3-MIN-VERSION)
-dnl Find a suitable Python interpreter, that is either python2 >= $1
-dnl or python3 >= $2. Stop with an error message if it has not been found.
-AC_DEFUN([LYX_PATH_PYTHON23],
+dnl Usage: LYX_PATH_PYTHON(PYTHON-MIN-VERSION)
+dnl Find a suitable Python interpreter, that is >= $1
+dnl Stop with an error message if it has not been found.
+AC_DEFUN([LYX_PATH_PYTHON],
  [
-  m4_define(py2_ver, [patsubst($1,[\.],[,])])
-  m4_define(py3_ver, [patsubst($2,[\.],[,])])
+  m4_define(py_ver, [patsubst($1,[\.],[,])])
 
-  m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python3 python2 python])
+  m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python3 python])
 
     if test -n "$PYTHON"; then
       # If the user set $PYTHON, use it and don't search something else.
-      AC_MSG_CHECKING([whether $PYTHON version is >= $1 or $2])
+      AC_MSG_CHECKING([whether $PYTHON version is >= $1])
       LYX_PYTHON_CHECK_VERSION([$PYTHON],
 			      [AC_MSG_RESULT([yes])],
 			      [AC_MSG_RESULT([no])
@@ -31,7 +30,7 @@ AC_DEFUN([LYX_PATH_PYTHON23],
     else
       # Otherwise, try each interpreter until we find one that satisfies
       # LYX_PYTHON_CHECK_VERSION.
-      AC_CACHE_CHECK([for a Python interpreter with version >= $1 or $2],
+      AC_CACHE_CHECK([for a Python interpreter with version >= $1],
 	[am_cv_pathless_PYTHON],[
 	for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
 	  test "$am_cv_pathless_PYTHON" = none && break
@@ -53,10 +52,10 @@ AC_DEFUN([LYX_PATH_PYTHON23],
 
 # LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
 # ---------------------------------------------------------------------------
-# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
+# Run ACTION-IF-TRUE if the Python interpreter PROG has version py_ver.
 # Run ACTION-IF-FALSE otherwise.
 AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
  [prog="import sys
 version = sys.version_info@<:@:3@:>@
-sys.exit(not ((py2_ver) <= version < (3,0,0) or version >= (py3_ver)))"
+sys.exit(version < (py_ver))"
   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])
diff --git a/configure.ac b/configure.ac
index 442a8a05d9..9ad5f101ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,7 @@ for file in config/install-sh ; do
 done
 
 # Find a suitable python interpreter
-LYX_PATH_PYTHON23([2.7.0], [3.5.0])
+LYX_PATH_PYTHON([3.10.0])
 # do the usual python setup stuff
 AM_PATH_PYTHON
 
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to