]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
python: determine Python (3.10) version number correctly.
authorMiro Hron\v{c}ok <miro@hroncok.cz>
Tue, 27 Oct 2020 21:33:46 +0000 (14:33 -0700)
committerKarl Berry <karl@freefriends.org>
Tue, 27 Oct 2020 21:33:46 +0000 (14:33 -0700)
This change fixes https://bugs.gnu.org/44239
(and https://bugzilla.redhat.com/show_bug.cgi?id=1889732).

* m4/python.m4: use print('%u.%u' % sys.version_info[:2]) for
the version number instead of merely sys.version[:3], so the
numbers are treated as numbers.
* t/python-vars.sh (PYTHON_VERSION): Likewise.
* doc/automake.texi: Document it.
* NEWS: mention it. (Minor tweaks from Karl Berry.)

NEWS
doc/automake.texi
m4/python.m4
t/python-vars.sh

diff --git a/NEWS b/NEWS
index fa35bf120774b5e69201ea53b58434efe45c948f..9c69e48d19136ec1b8958e7cc5c5e185669a6b89 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,8 @@ New in ?.?.?:
 
 * Bugs fixed
 
+  - Python 3.10 version number no longer considered to be 3.1.
+
   - Broken links in manual fixed or removed, and new script
     contrib/checklinkx (a small modification of W3C checklink) added,
     with accompany target checklinkx to recheck urls.
index ed7e2e242aa23d51cb876439dbf824fe095ace0e..17bc2dae6e123893a66e2131ba100e4220177c7a 100644 (file)
@@ -7861,7 +7861,7 @@ AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
 @item PYTHON_VERSION
 The Python version number, in the form @var{major}.@var{minor}
 (e.g., @samp{2.5}).  This is currently the value of
-@samp{sys.version[:3]}.
+@samp{'%u.%u' % sys.version_info[:2]}.
 
 @item PYTHON_PREFIX
 The string @samp{$@{prefix@}}.  This term may be used in future work
index 16c2f4f1a0ea0c86dd6d0fa29c6eb8d925d43c63..b2302baa3daf0651d5b5234d24bdf4c4541f0a13 100644 (file)
@@ -1,7 +1,7 @@
 ## ------------------------                                 -*- Autoconf -*-
 ## Python file handling
 ## From Andrew Dalke
-## Updated by James Henstridge
+## Updated by James Henstridge and other contributors.
 ## ------------------------
 # Copyright (C) 1999-2020 Free Software Foundation, Inc.
 #
@@ -86,12 +86,14 @@ AC_DEFUN([AM_PATH_PYTHON],
     m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
   else
 
-  dnl Query Python for its version number.  Getting [:3] seems to be
-  dnl the best way to do this; it's what "site.py" does in the standard
-  dnl library.
+  dnl Query Python for its version number.  Although site.py simply uses
+  dnl sys.version[:3], printing that failed with Python 3.10, since the
+  dnl trailing zero was eliminated. So now we output just the major
+  dnl and minor version numbers, as numbers. Apparently the tertiary
+  dnl version is not of interest.
 
   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
-    [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`])
+    [am_cv_python_version=`$PYTHON -c "import sys; print('%u.%u' % sys.version_info[[:2]])"`])
   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
 
   dnl Use the values of $prefix and $exec_prefix for the corresponding
index 5c748bcf1b3d53958effeb2287d4787f3d6feb2b..b53018b37d1d932e5fe96da30f7968e94e71e66a 100644 (file)
@@ -28,7 +28,9 @@ CONFIG_SITE=/dev/null; export CONFIG_SITE
 # vary among different python installations, so we need more relaxed
 # and ad-hoc checks for them.  Also, more proper "functional" checks
 # on them should be done in the 'python-virtualenv.sh' test.
-PYTHON_VERSION=$($PYTHON -c 'import sys; print(sys.version[:3])') || exit 1
+# 
+# This version identification is duplicated in python.m4 (and the manual).
+PYTHON_VERSION=$($PYTHON -c 'import sys; print("%u.%u" % sys.version_info[:2])') || exit 1
 PYTHON_PLATFORM=$($PYTHON -c 'import sys; print(sys.platform)') || exit 1
 PYTHON_EXEC_PREFIX='${exec_prefix}'
 PYTHON_PREFIX='${prefix}'