Subject: [bug#71672] [PATCH] python: Prefer python3 over python

From: "Zack Weinberg" <[email-masked]>
Date: Sun, 23 Jun 2024 02:11:29 +0000

Here's what I think might be useful:

Add these three macros to Autoconf proper:

# AC_PYTHON_VERSION_RANGE_IFELSE([PROG], [MIN-VERSION], [MAX-VERSION = next-major],
#    [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------------------------
# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= MIN-VERSION
#  and < MAX_VERSION.  If MAX_VERSION is empty, it defaults to the next
#  major version after MIN-VERSION (e.g. 2.7 -> 3, 3.6 -> 4).
# Run ACTION-IF-FALSE otherwise.

# AC_PATH_PYTHON2([MINIMUM-VERSION], [VALUE-IF-NOT-FOUND])
# --------------------------------------------------------
# Find a Python 2 interpreter.  If MINIMUM-VERSION is not empty, it must be at
# least that version.  If one is found, set the substitution variable PYTHON2
# to the full pathname of the selected interpreter.  Otherwise set PYTHON2 to
# VALUE-IF-NOT-FOUND.  Does nothing else; in particular, does not do any of the
# additional checks and substitutions done by AM_PATH_PYTHON.

This one will try bare 'python'.

# AC_PATH_PYTHON3([MINIMUM-VERSION], [VALUE-IF-NOT-FOUND])
# --------------------------------------------------------
# Find a Python 3 interpreter.  If MINIMUM-VERSION is not empty, it must be at
# least that version.  If one is found, set the substitution variable PYTHON3
# to the full pathname of the selected interpreter.  Otherwise set PYTHON3 to
# VALUE-IF-NOT-FOUND.  Does nothing else; in particular, does not do any of the
# additional checks and substitutions done by AM_PATH_PYTHON.

This one will not.

Automake's python.m4 should also define these if they are not already defined.
Then, we split AM_PATH_PYTHON into the part that sets PYTHON, which is implemented
in terms of the above macros (but still looks for both 2 and 3) and the part that
does all the rest of it.  People who want a slightly more efficient v3-only configure
script can use AC_PATH_PYTHON3 + whatever the name of the new "all the rest of it"
macro is.

I think that should disentangle things reasonably well, but we should definitely
do this early rather than late in an automake release cycle, and seek out feedback
from existing users of AM_PATH_PYTHON.  What say you?

zw