0001-Correct-a-flaw-in-the-Python-3-version-checking.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. From 4dc82e9d503518a00e54972be7c0cb5f342f985e Mon Sep 17 00:00:00 2001
  2. From: Rich Ercolani <214141+rincebrain@users.noreply.github.com>
  3. Date: Tue, 8 Jun 2021 20:20:16 -0400
  4. Subject: [PATCH] Correct a flaw in the Python 3 version checking
  5. It turns out the ax_python_devel.m4 version check assumes that
  6. ("3.X+1.0" >= "3.X.0") is True in Python, which is not when X+1
  7. is 10 or above and X is not. (Also presumably X+1=100 and ...)
  8. So let's remake the check to behave consistently, using the
  9. "packaging" or (if absent) the "distlib" modules.
  10. (Also, update the Github workflows to use the new packages.)
  11. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
  12. Reviewed-by: John Kennedy <john.kennedy@delphix.com>
  13. Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
  14. Closes: #12073
  15. (cherry picked from commit 08cd0717359b1a18693e3c8e6d6e5a2819b35a48)
  16. [Romain: drop rpm spec and github workflows changes]
  17. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  18. ---
  19. config/always-pyzfs.m4 | 15 +++++++++++++++
  20. config/ax_python_devel.m4 | 33 +++++++++++++++++++++++++++------
  21. 2 files changed, 42 insertions(+), 6 deletions(-)
  22. diff --git a/config/always-pyzfs.m4 b/config/always-pyzfs.m4
  23. index 76e07b593..fa39fd885 100644
  24. --- a/config/always-pyzfs.m4
  25. +++ b/config/always-pyzfs.m4
  26. @@ -46,6 +46,21 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYZFS], [
  27. ])
  28. AC_SUBST(DEFINE_PYZFS)
  29. + dnl #
  30. + dnl # Python "packaging" (or, failing that, "distlib") module is required to build and install pyzfs
  31. + dnl #
  32. + AS_IF([test "x$enable_pyzfs" = xcheck -o "x$enable_pyzfs" = xyes], [
  33. + ZFS_AC_PYTHON_MODULE([packaging], [], [
  34. + ZFS_AC_PYTHON_MODULE([distlib], [], [
  35. + AS_IF([test "x$enable_pyzfs" = xyes], [
  36. + AC_MSG_ERROR("Python $PYTHON_VERSION packaging and distlib modules are not installed")
  37. + ], [test "x$enable_pyzfs" != xno], [
  38. + enable_pyzfs=no
  39. + ])
  40. + ])
  41. + ])
  42. + ])
  43. +
  44. dnl #
  45. dnl # Require python-devel libraries
  46. dnl #
  47. diff --git a/config/ax_python_devel.m4 b/config/ax_python_devel.m4
  48. index c51b45b7d..cdfbbf81f 100644
  49. --- a/config/ax_python_devel.m4
  50. +++ b/config/ax_python_devel.m4
  51. @@ -97,9 +97,18 @@ AC_DEFUN([AX_PYTHON_DEVEL],[
  52. # Check for a version of Python >= 2.1.0
  53. #
  54. AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
  55. - ac_supports_python_ver=`$PYTHON -c "import sys; \
  56. - ver = sys.version.split ()[[0]]; \
  57. - print (ver >= '2.1.0')"`
  58. + ac_supports_python_ver=`cat<<EOD | $PYTHON -
  59. +from __future__ import print_function;
  60. +import sys;
  61. +try:
  62. + from packaging import version;
  63. +except ImportError:
  64. + from distlib import version;
  65. +ver = sys.version.split ()[[0]];
  66. +(tst_cmp, tst_ver) = ">= '2.1.0'".split ();
  67. +tst_ver = tst_ver.strip ("'");
  68. +eval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
  69. +EOD`
  70. if test "$ac_supports_python_ver" != "True"; then
  71. if test -z "$PYTHON_NOVERSIONCHECK"; then
  72. AC_MSG_RESULT([no])
  73. @@ -126,9 +135,21 @@ to something else than an empty string.
  74. #
  75. if test -n "$1"; then
  76. AC_MSG_CHECKING([for a version of Python $1])
  77. - ac_supports_python_ver=`$PYTHON -c "import sys; \
  78. - ver = sys.version.split ()[[0]]; \
  79. - print (ver $1)"`
  80. + # Why the strip ()? Because if we don't, version.parse
  81. + # will, for example, report 3.10.0 >= '3.11.0'
  82. + ac_supports_python_ver=`cat<<EOD | $PYTHON -
  83. +
  84. +from __future__ import print_function;
  85. +import sys;
  86. +try:
  87. + from packaging import version;
  88. +except ImportError:
  89. + from distlib import version;
  90. +ver = sys.version.split ()[[0]];
  91. +(tst_cmp, tst_ver) = "$1".split ();
  92. +tst_ver = tst_ver.strip ("'");
  93. +eval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
  94. +EOD`
  95. if test "$ac_supports_python_ver" = "True"; then
  96. AC_MSG_RESULT([yes])
  97. else
  98. --
  99. 2.31.1