Hi Bruno,

On 3/26/24 3:19 PM, Bruno Haible wrote:
> Feel free to do so. Either in GLFileSystem only, or globally - as you like.

I would prefer to do it globally. I find they make it easier to
reference code. Since we have *some* of the information in docstrings,
I would just remove those and turn them into actual type hints.

Since the type-hinting requires the

    from __future__ import annotations

wizardry for older versions of Python3, it would be nice for me to be
able to confirm things remain compatible.

Since we don't use (and probably won't ever have the need) for third
party packages, what do you think of this patch adding the PYTHON
environment variable?

Most GNU/Linux distributions and FreeBSD package various python3.x
packages. This would allow me to run the test case:

    $ env PYTHON=python3.7 GNULIB_TOOL_IMPL=py ./test-all.sh

This should be enough to ensure type hints + no future changes break
compatibility with older Python versions. And doesn't require learning
the complicated virtual environment stuff.

Collin
From 56b4990c7ca5224655525accf83c1e4c9094acf5 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Tue, 26 Mar 2024 16:26:39 -0700
Subject: [PATCH] gnulib-tool.py: Obey the PYTHON environment variable.

* gnulib-tool.py: Change all invocations of 'python3' to use the PYTHON
environment variable.
---
 ChangeLog      |  6 ++++++
 gnulib-tool.py | 14 ++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e70c0e9271..5e1d2d65c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-26  Collin Funk  <[email protected]>
+
+	gnulib-tool.py: Obey the PYTHON environment variable.
+	* gnulib-tool.py: Change all invocations of 'python3' to use the PYTHON
+	environment variable.
+
 2024-03-26  Collin Funk  <[email protected]>
 
 	gnulib-tool.py: Allow the use of both configure.ac and configure.in.
diff --git a/gnulib-tool.py b/gnulib-tool.py
index f94c9c36a7..93ab0afbd0 100755
--- a/gnulib-tool.py
+++ b/gnulib-tool.py
@@ -19,6 +19,8 @@
 # This program invokes the Python rewrite of gnulib-tool.
 # It is meant to behave identically to gnulib-tool, just faster.
 
+: "${PYTHON="python3"}"
+
 progname=$0
 
 # func_exit STATUS
@@ -131,21 +133,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
+if ($PYTHON --version) >/dev/null 2>/dev/null; then
+  case `$PYTHON --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" ;;
+      func_fatal_error "python3 is too old (minimum required version is 3.7); set PYTHON to a newer version or try setting GNULIB_TOOL_IMPL=sh" ;;
     Python\ 3.*)
       ;;
     *)
-      func_fatal_error "python3 version is unsupported" ;;
+      func_fatal_error "python3 version is unsupported; set PYTHON to a newer version" ;;
   esac
 else
-  func_fatal_error "python3 not found; try setting GNULIB_TOOL_IMPL=sh"
+  func_fatal_error "python3 not found; set PYTHON to a python version 3.7+ or try setting GNULIB_TOOL_IMPL=sh"
 fi
 
 # Setting the PYTHONPATH environment variable is needed to avoid an error:
 #   from . import constants          =>   ImportError: attempted relative import with no known parent package
 #   from pygnulib import constants   =>   ModuleNotFoundError: No module named 'pygnulib'
 # Explanation: https://stackoverflow.com/questions/16981921/relative-imports-in-python-3
-exec env PYTHONPATH="$gnulib_dir" python3 "$gnulib_dir/pygnulib/main.py" "$@"
+exec env PYTHONPATH="$gnulib_dir" $PYTHON "$gnulib_dir/pygnulib/main.py" "$@"
-- 
2.44.0

Reply via email to