bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gnulib-tool: Use the Python implementation by default


From: Bruno Haible
Subject: Re: gnulib-tool: Use the Python implementation by default
Date: Sat, 27 Apr 2024 20:38:41 +0200

Hi Pádraig,

Thanks for the details.

> So this is a general question, unrelated to my particular suggestion.

It _is_ related :-)

> Possible drop in replacements for the python3 command might be ...
> 
> ... pypy, which separates its implementation version from python language 
> support version:
> $ dnf install pypy3
> $ pypy3
> 
>  >>>> sys.pypy_version_info
> sys.pypy_version_info(major=7, minor=3, micro=15, releaselevel='final', 
> serial=0)
>  >>>> sys.version_info
> sys.version_info(major=3, minor=10, micro=13, releaselevel='final', serial=0)
> 
> ... cinder, which is very close to cpython ...
> $ dnf install docker
> $ sudo systemctl start docker
> $ sudo setfacl --modify user:$USER:rw /var/run/docker.sock
> $ docker run -it --rm ghcr.io/facebookincubator/cinder-runtime:cinder-3.10
> 
> Python 3.10.5+cinder (main, Apr 26 2024, 22:00:58) [GCC 10.3.1 20210422 (Red 
> Hat 10.3.1-1)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import sys
>  >>> sys.version_info
> sys.version_info(major=3, minor=10, micro=5, releaselevel='final', serial=0)
> 
> 
> There are no other real contenders for drop in python 3 replacement.

OK. This means that people might be tempted to create a symlink
python3 -> pypy3
or
python3 -> cinder.

With the values that you have shown, it will be indeed better to use
sys.version_info.

> Testing shows that a subshell does avoid that issue, so the following works:
> 
>    if (python3 -c 'import sys; sys.exit(not sys.version_info >= (3,7))') 
> 2>/dev/null; then

Thanks, I'm taking this one.


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.

diff --git a/gnulib-tool b/gnulib-tool
index 441958ae7e..56c4473318 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -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
diff --git a/gnulib-tool.py b/gnulib-tool.py
index 81537c272c..52389dcd78 100755
--- a/gnulib-tool.py
+++ b/gnulib-tool.py
@@ -131,17 +131,21 @@
 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.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]