Correct a flaw in the Python 3 version checking (#12636)

It turns out the ax_python_devel.m4 version check assumes that
("3.X+1.0" >= "3.X.0") is True in Python, which is not when X+1
is 10 or above and X is not. (Also presumably X+1=100 and ...)

So let's remake the check to behave consistently, using the
"packaging" or (if absent) the "distlib" modules.

(Also, update the Github workflows to use the new packages.)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes: #12073
This commit is contained in:
Rich Ercolani 2021-11-01 17:54:47 -04:00 committed by GitHub
parent 71c6098526
commit 8cd9f20a34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 10 deletions

View File

@ -26,7 +26,7 @@ jobs:
xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \ xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \
libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \ libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \
libpam0g-dev pamtester python-dev python-setuptools python-cffi \ libpam0g-dev pamtester python-dev python-setuptools python-cffi \
python3 python3-dev python3-setuptools python3-cffi python3 python3-dev python3-setuptools python3-cffi python3-packaging
- name: Autogen.sh - name: Autogen.sh
run: | run: |
sh autogen.sh sh autogen.sh

View File

@ -22,7 +22,7 @@ jobs:
xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \ xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \
libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \ libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \
libpam0g-dev pamtester python-dev python-setuptools python-cffi \ libpam0g-dev pamtester python-dev python-setuptools python-cffi \
python3 python3-dev python3-setuptools python3-cffi python3 python3-dev python3-setuptools python3-cffi python3-packaging
- name: Autogen.sh - name: Autogen.sh
run: | run: |
sh autogen.sh sh autogen.sh

View File

@ -22,8 +22,8 @@ jobs:
xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \ xfslibs-dev libattr1-dev libacl1-dev libudev-dev libdevmapper-dev \
libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \ libssl-dev libffi-dev libaio-dev libelf-dev libmount-dev \
libpam0g-dev \ libpam0g-dev \
python-dev python-setuptools python-cffi \ python-dev python-setuptools python-cffi python-packaging \
python3 python3-dev python3-setuptools python3-cffi python3 python3-dev python3-setuptools python3-cffi python3-packaging
- name: Autogen.sh - name: Autogen.sh
run: | run: |
sh autogen.sh sh autogen.sh

View File

@ -46,6 +46,21 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
]) ])
AC_SUBST(DEFINE_PYZFS) AC_SUBST(DEFINE_PYZFS)
dnl #
dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
dnl #
AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
ZFS_AC_PYTHON_MODULE([packaging], [], [
ZFS_AC_PYTHON_MODULE([distlib], [], [
AS_IF([test "x$enable_pyzfs" = xyes], [
AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
], [test "x$enable_pyzfs" != xno], [
enable_pyzfs=no
])
])
])
])
dnl # dnl #
dnl # Require python-devel libraries dnl # Require python-devel libraries
dnl # dnl #

View File

@ -97,9 +97,18 @@ AC_DEFUN([AX_PYTHON_DEVEL],[
# Check for a version of Python >= 2.1.0 # Check for a version of Python >= 2.1.0
# #
AC_MSG_CHECKING([for a version of Python >= '2.1.0']) AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
ac_supports_python_ver=`$PYTHON -c "import sys; \ ac_supports_python_ver=`cat<<EOD | $PYTHON -
ver = sys.version.split ()[[0]]; \ from __future__ import print_function;
print (ver >= '2.1.0')"` import sys;
try:
from packaging import version;
except ImportError:
from distlib import version;
ver = sys.version.split ()[[0]];
(tst_cmp, tst_ver) = ">= '2.1.0'".split ();
tst_ver = tst_ver.strip ("'");
eval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
EOD`
if test "$ac_supports_python_ver" != "True"; then if test "$ac_supports_python_ver" != "True"; then
if test -z "$PYTHON_NOVERSIONCHECK"; then if test -z "$PYTHON_NOVERSIONCHECK"; then
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
@ -126,9 +135,21 @@ to something else than an empty string.
# #
if test -n "$1"; then if test -n "$1"; then
AC_MSG_CHECKING([for a version of Python $1]) AC_MSG_CHECKING([for a version of Python $1])
ac_supports_python_ver=`$PYTHON -c "import sys; \ # Why the strip ()? Because if we don't, version.parse
ver = sys.version.split ()[[0]]; \ # will, for example, report 3.10.0 >= '3.11.0'
print (ver $1)"` ac_supports_python_ver=`cat<<EOD | $PYTHON -
from __future__ import print_function;
import sys;
try:
from packaging import version;
except ImportError:
from distlib import version;
ver = sys.version.split ()[[0]];
(tst_cmp, tst_ver) = "$1".split ();
tst_ver = tst_ver.strip ("'");
eval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
EOD`
if test "$ac_supports_python_ver" = "True"; then if test "$ac_supports_python_ver" = "True"; then
AC_MSG_RESULT([yes]) AC_MSG_RESULT([yes])
else else

View File

@ -311,6 +311,11 @@ Requires: libffi
Requires: python%{__python_pkg_version} Requires: python%{__python_pkg_version}
Requires: %{__python_cffi_pkg} Requires: %{__python_cffi_pkg}
%if 0%{?rhel}%{?fedora}%{?suse_version} %if 0%{?rhel}%{?fedora}%{?suse_version}
%if 0%{?rhel} >= 8 || 0%{?centos} >= 8 || 0%{?fedora} >= 28
BuildRequires: python3-packaging
%else
BuildRequires: python-packaging
%endif
BuildRequires: python%{__python_pkg_version}-devel BuildRequires: python%{__python_pkg_version}-devel
BuildRequires: %{__python_cffi_pkg} BuildRequires: %{__python_cffi_pkg}
BuildRequires: %{__python_setuptools_pkg} BuildRequires: %{__python_setuptools_pkg}