Subject: Re: bug#28160: Support newer version of python

From: Mathieu Lirzin <[email-masked]>
Date: Sun, 04 Feb 2018 01:53:29 +0100

Hello,

Mathieu Lirzin <[email-masked]> writes:

>>> On 09/15/17 11:17, Mathieu Lirzin wrote:
>>>> Instead of preemptively adding possible future version of Python that
>>>> hopefully would be released, I would prefer a solution that removes the
>>>> need to hard-code them.
>
> It seems that GNU Pyconfigure has already found a way to build that list
> dynamically in m4.  Please see PC_PROG_PYTHON macro here:
>
>   https://git.savannah.gnu.org/cgit/pyconfigure.git/tree/src/m4/python.m4

I have adapted this to fit Automake context.  I am going to apply the
following patch in the following days.  Comments welcome.

>From 1d60fb72168e62d33fe433380af621de64e22f23 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <[email-masked]>
Date: Thu, 1 Feb 2018 13:51:03 +0100
Subject: [PATCH] python: Generate python interpreter list

_AM_PYTHON_INTERPRETER_LIST is used by AM_PYTHON_PATH to autodetect
Python programs whose names correspond to a specific Python
version (e.g. python3.6).  Previously this list was updated manually.
The automatic support of newer versions (up to 4.0 excluded) fixes
bug#28160.

* m4/python.m4 (am_py_min_ver, am_py_max_ver): New macros.
(_AM_PYTHON_INTERPRETER_LIST): Generate this list instead of hard-coding
it.  Implementation is taken from GNU Pyconfigure.
---
 m4/python.m4 | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/m4/python.m4 b/m4/python.m4
index 58dd18761..d6dda1363 100644
--- a/m4/python.m4
+++ b/m4/python.m4
@@ -36,11 +36,24 @@ AC_DEFUN([AM_PATH_PYTHON],
  [
   dnl Find a Python interpreter.  Python versions prior to 2.0 are not
   dnl supported. (2.0 was released on October 16, 2000).
-  dnl FIXME: Remove the need to hard-code Python versions here.
+  m4_define_default([am_py_min_ver], m4_ifval([$1], [$1], [2.0]))
+  dnl The arbitrary default maximum version.
+  m4_define_default([am_py_max_ver], [4.0])
+
   m4_define_default([_AM_PYTHON_INTERPRETER_LIST],
-[python python2 python3 python3.6 python3.5 python3.4 python3.3 python3.2 dnl
- python3.1 python3.0 python2.7 python2.6 python2.5 python2.4 python2.3 dnl
- python2.2 python2.1 python2.0])
+    [[python] \
+     dnl If we want some Python 2 versions (min version <= 2.7),
+     dnl also search for "python2".
+     m4_if(m4_version_compare(am_py_min_ver, [2.8]), [-1], [python2], []) \
+     [python3] \
+     dnl Construct a comma-separated list of interpreter names (python2.6,
+     dnl python2.7, etc). We only care about the first 3 characters of the
+     dnl version strings (major-dot-minor; not
+     dnl major-dot-minor-dot-bugfix[-dot-whatever])
+     m4_foreach([py_ver],
+       m4_esyscmd_s(seq -s[[", "]] -f["[[%.1f]]"] m4_substr(am_py_max_ver, [0], [3]) -0.1 m4_substr(am_py_min_ver, [0], [3])),
+       dnl Remove python2.8 and python2.9 since they will never exist
+       [m4_bmatch(py_ver, [2.[89]], [], [python]py_ver)])])
 
   AC_ARG_VAR([PYTHON], [the Python interpreter])
 
-- 
2.16.1

-- 
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761  070D 0ADE E100 9460 4D37