From: Bruno Haible Date: Sat, 27 Apr 2024 18:33:59 +0000 (+0200) Subject: gnulib-tool: Simplify the Python version test. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=6cb75b5ee654ccafc605cb73087aa8e23bd2e457;p=gnulib.git gnulib-tool: Simplify the Python version test. Suggested by Pádraig Brady in . * 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/ChangeLog b/ChangeLog index 185daab415..30afe4b190 100644 --- 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 + + gnulib-tool: Simplify the Python version test. + Suggested by Pádraig Brady in + . + * 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 fcntl-h, stdio, unistd: Ensure off64_t is defined on all platforms. 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 () 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.