]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool: Simplify the Python version test.
authorBruno Haible <bruno@clisp.org>
Sat, 27 Apr 2024 18:33:59 +0000 (20:33 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Apr 2024 09:21:39 +0000 (11:21 +0200)
Suggested by Pádraig Brady in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00469.html>.

* gnulib-tool: Use Python's sys.version_info, not --version.
* gnulib-tool.py: Use the same version test here. Use --version only to
produce a specific error message.

ChangeLog
gnulib-tool
gnulib-tool.py

index 185daab4154cc7ffcfb522d684eaab24c5eff61e..30afe4b1908c2986048c2809e4cad8ad0c5f3012 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,15 @@
        * pygnulib/GLTestDir.py (GLMegaTestDir.execute): Use a separate set to
        remove duplicates from the original list without sorting.
 
+2024-04-27  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool: Simplify the Python version test.
+       Suggested by Pádraig Brady in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00469.html>.
+       * gnulib-tool: Use Python's sys.version_info, not --version.
+       * gnulib-tool.py: Use the same version test here. Use --version only to
+       produce a specific error message.
+
 2024-04-27  Bruno Haible  <bruno@clisp.org>
 
        fcntl-h, stdio, unistd: Ensure off64_t is defined on all platforms.
index 441958ae7e59d5525fee607d7579404708d29532..56c447331818e127c885ff3281a885d7db07cb7b 100755 (executable)
@@ -143,12 +143,7 @@ case "$GNULIB_TOOL_IMPL" in
   '')
     # Use the Python implementation if a suitable Python version is found
     # in $PATH. This is the same Python version test as in gnulib-tool.py.
-    if (python3 --version) >/dev/null 2>/dev/null \
-       && case `python3 --version 2>&1` in
-            Python\ 3.[0-6] | Python\ 3.[0-6].*) false ;;
-            Python\ 3.*) true ;;
-            *) false ;;
-          esac; then
+    if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 2>/dev/null; then
       exec "$gnulib_dir/gnulib-tool.py" "$@"
     else
       echo "gnulib-tool: warning: python3 not found or too old, using the slow shell-based implementation" 1>&2
index 81537c272ca10f7f953b2b8480367634f7ad1884..52389dcd7858125c9b386a469a19b67ef1227e68 100755 (executable)
@@ -131,17 +131,21 @@ func_gnulib_dir ()
 func_gnulib_dir
 
 # Check the Python version.
-if (python3 --version) >/dev/null 2>/dev/null; then
-  case `python3 --version 2>&1` in
-    Python\ 3.[0-6] | Python\ 3.[0-6].*)
-      func_fatal_error "python3 is too old (minimum required version is 3.7); try setting GNULIB_TOOL_IMPL=sh" ;;
-    Python\ 3.*)
-      ;;
-    *)
-      func_fatal_error "python3 version is unsupported" ;;
-  esac
+if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 2>/dev/null; then
+  :
 else
-  func_fatal_error "python3 not found; try setting GNULIB_TOOL_IMPL=sh"
+  if (python3 --version) >/dev/null 2>/dev/null; then
+    case `python3 --version 2>&1` in
+      Python\ 3.[0-6] | Python\ 3.[0-6].*)
+        func_fatal_error "python3 is too old (minimum required version is 3.7); try setting GNULIB_TOOL_IMPL=sh" ;;
+      Python\ 3.*)
+        ;;
+      *)
+        func_fatal_error "python3 version is unsupported" ;;
+    esac
+  else
+    func_fatal_error "python3 not found; try setting GNULIB_TOOL_IMPL=sh"
+  fi
 fi
 
 # Tell Python to store the compiled bytecode outside the gnulib directory.