Blame SOURCES/automake-1.16.2-python-version-multiple-digits.patch

3f601b
From e21d46fddd0753e66a4acda88317670fee07f3e6 Mon Sep 17 00:00:00 2001
3f601b
From: "Miro Hron\\v{c}ok" <miro@hroncok.cz>
3f601b
Date: Tue, 27 Oct 2020 14:33:46 -0700
3f601b
Subject: [PATCH] python: determine Python (3.10) version number correctly.
3f601b
3f601b
This change fixes https://bugs.gnu.org/44239
3f601b
(and https://bugzilla.redhat.com/show_bug.cgi?id=1889732).
3f601b
3f601b
* m4/python.m4: use print('%u.%u' % sys.version_info[:2]) for
3f601b
the version number instead of merely sys.version[:3], so the
3f601b
numbers are treated as numbers.
3f601b
* t/python-vars.sh (PYTHON_VERSION): Likewise.
3f601b
* doc/automake.texi: Document it.
3f601b
* NEWS: mention it. (Minor tweaks from Karl Berry.)
3f601b
---
3f601b
 NEWS              |  2 ++
3f601b
 doc/automake.texi |  2 +-
3f601b
 m4/python.m4      | 12 +++++++-----
3f601b
 t/python-vars.sh  |  4 +++-
3f601b
 4 files changed, 13 insertions(+), 7 deletions(-)
3f601b
3f601b
diff --git a/doc/automake.texi b/doc/automake.texi
3f601b
index ed7e2e242..17bc2dae6 100644
3f601b
--- a/doc/automake.texi
3f601b
+++ b/doc/automake.texi
3f601b
@@ -7861,7 +7861,7 @@ AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
3f601b
 @item PYTHON_VERSION
3f601b
 The Python version number, in the form @var{major}.@var{minor}
3f601b
 (e.g., @samp{2.5}).  This is currently the value of
3f601b
-@samp{sys.version[:3]}.
3f601b
+@samp{'%u.%u' % sys.version_info[:2]}.
3f601b
 
3f601b
 @item PYTHON_PREFIX
3f601b
 The string @samp{$@{prefix@}}.  This term may be used in future work
3f601b
diff --git a/m4/python.m4 b/m4/python.m4
3f601b
index 16c2f4f1a..b2302baa3 100644
3f601b
--- a/m4/python.m4
3f601b
+++ b/m4/python.m4
3f601b
@@ -1,7 +1,7 @@
3f601b
 ## ------------------------                                 -*- Autoconf -*-
3f601b
 ## Python file handling
3f601b
 ## From Andrew Dalke
3f601b
-## Updated by James Henstridge
3f601b
+## Updated by James Henstridge and other contributors.
3f601b
 ## ------------------------
3f601b
 # Copyright (C) 1999-2020 Free Software Foundation, Inc.
3f601b
 #
3f601b
@@ -86,12 +86,14 @@ AC_DEFUN([AM_PATH_PYTHON],
3f601b
     m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
3f601b
   else
3f601b
 
3f601b
-  dnl Query Python for its version number.  Getting [:3] seems to be
3f601b
-  dnl the best way to do this; it's what "site.py" does in the standard
3f601b
-  dnl library.
3f601b
+  dnl Query Python for its version number.  Although site.py simply uses
3f601b
+  dnl sys.version[:3], printing that failed with Python 3.10, since the
3f601b
+  dnl trailing zero was eliminated. So now we output just the major
3f601b
+  dnl and minor version numbers, as numbers. Apparently the tertiary
3f601b
+  dnl version is not of interest.
3f601b
 
3f601b
   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
3f601b
-    [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
3f601b
+    [am_cv_python_version=`$PYTHON -c "import sys; print('%u.%u' % sys.version_info[[:2]])"`])
3f601b
   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
3f601b
 
3f601b
   dnl Use the values of $prefix and $exec_prefix for the corresponding
3f601b
diff --git a/t/python-vars.sh b/t/python-vars.sh
3f601b
index 5c748bcf1..b53018b37 100644
3f601b
--- a/t/python-vars.sh
3f601b
+++ b/t/python-vars.sh
3f601b
@@ -28,7 +28,9 @@ CONFIG_SITE=/dev/null; export CONFIG_SITE
3f601b
 # vary among different python installations, so we need more relaxed
3f601b
 # and ad-hoc checks for them.  Also, more proper "functional" checks
3f601b
 # on them should be done in the 'python-virtualenv.sh' test.
3f601b
-PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version[:3])') || exit 1
3f601b
+# 
3f601b
+# This version identification is duplicated in python.m4 (and the manual).
3f601b
+PYTHON_VERSION=$($PYTHON -c 'import sys; print("%u.%u" % sys.version_info[:2])') || exit 1
3f601b
 PYTHON_PLATFORM=$($PYTHON -c 'import sys; print(sys.platform)') || exit 1
3f601b
 PYTHON_EXEC_PREFIX='${exec_prefix}'
3f601b
 PYTHON_PREFIX='${prefix}'
3f601b
-- 
3f601b
2.29.0
3f601b