Yasuhito FUTATSUKI wrote on Sat, Jan 23, 2021 at 01:57:07 +0900: > Parhaps it is a missed one, that should be fixed :) > > With this patch, even if environment variable PYTHON pointed to Python 2, > the configure script searches Python 3 at first. I'm irresolute that > it is what it should be or not, and we should add --with-python argment > to specify Python interpreter explicitly for this purpose or not.
A Unix program should do what it was told and exit silently, or else fail loudly (with non-empty stderr and a non-zero exit code). "Silently do something other than I was instructed" would be a bug. Thus, if the admin points to py2, then we should either use py2 or abort the build. It's their system, not ours. If we think the value of some envvar or --option is likely to be a mistake or unintended configuration, we can print a warning. In extreme cases, we can even require some sort of opt-in switch, such as --enable-broken-httpd-auth; however, this amounts to second-guessing the admin, so it's not usually done. (By the way, if I'm reading build/ac-macros/apache.m4 correctly, there's a bug in the implementation of that configure flag: it sets $broken_httpd_auth but tests $enable_broken_httpd_auth. Either I'm misreading the code, or nobody ever used that flag.) As to this specific case, here are some ideas: - We could deprecate $PYTHON and --with-python and require the admin to use envvars or configure option names that identify the py major version explicitly: e.g., ${PYTHON2}/${PYTHON3} or --with-python2/--with-python3. The logic for how to arbitrate among $PYTHON/--with-py2/--with-py3, when more than one of them is set/passed, would have to be designed. - Print a warning at the end of configure if py2 was selected automatically (where "automatically" means, say, "neither via --with-python2 nor by setting $PYTHON to a value whose basename contains the substring 'python2'"). Makes sense? Cheers, Daniel > [[[ > configure: Search Python 3 before searching Python 2 for tests suite. > > * build/find_python.sh: Add option to specify version to search for. > > * configure.ac: Search Python 3 before searching Python 2 for tests suite. > ]]] > > Cheers, > -- > Yasuhito FUTATSUKI <futat...@yf.bsclub.org> > Index: build/find_python.sh > =================================================================== > --- build/find_python.sh (revision 1885802) > +++ build/find_python.sh (working copy) > @@ -21,11 +21,28 @@ > # > > # Required version of Python > -VERSION=${1:-0x2070000} > +case $1 in > + -2) > + CANDIDATE="$PYTHON $PYTHON2 python python2" > + MIN_VER=${2:-0x2070000} > + MAX_VER="0x3000000" > + break > + ;; > + -3) > + CANDIDATE="$PYTHON $PYTHON3 python python3" > + MIN_VER=${2:-0x3000000} > + MAX_VER="0xffffffff" > + ;; > + *) > + CANDIDATE="$PYTHON $PYTHON3 python python3 $PYTHON2 python2" > + MIN_VER=${1:-0x2070000} > + MAX_VER="0xffffffff" > +esac > > -for pypath in "$PYTHON" "$PYTHON2" "$PYTHON3" python python2 python3; do > +for pypath in $CANDIDATE; do > if [ "x$pypath" != "x" ]; then > - DETECT_PYTHON="import sys;sys.exit((sys.hexversion < $VERSION) and 1 or > 0)" > + DETECT_PYTHON="import sys;\ > + sys.exit(0 if $MIN_VER <= sys.hexversion < $MAX_VER else > 1)" > if "$pypath" -c "$DETECT_PYTHON" >/dev/null 2>/dev/null; then > echo $pypath > exit 0 > Index: configure.ac > =================================================================== > --- configure.ac (revision 1885802) > +++ configure.ac (working copy) > @@ -1303,15 +1303,22 @@ > # Python: Used for testsuite > AC_ARG_VAR([PYTHON], [Python interpreter command]) > > -PYTHON="`$abs_srcdir/build/find_python.sh`" > -if test -z "$PYTHON"; then > - AC_MSG_WARN([Python 2.7 or later is required to run the testsuite.]) > - AC_MSG_WARN([]) > - AC_MSG_WARN([If you have a suitable Python installed, but not on the]) > - AC_MSG_WARN([PATH, set the environment variable PYTHON to the full path]) > - AC_MSG_WARN([to the Python executable, and re-run configure]) > - PYTHON=none > +detected_python="`$abs_srcdir/build/find_python.sh -3`" > +if test -z "$detected_python"; then > + detected_python="`$abs_srcdir/build/find_python.sh -2`" > + if test -z "$detected_python"; then > + AC_MSG_WARN([Python 2.7 or later is required to run the testsuite.]) > + AC_MSG_WARN([]) > + AC_MSG_WARN([If you have a suitable Python installed, but not on the]) > + AC_MSG_WARN([PATH, set the environment variable PYTHON to the full path]) > + AC_MSG_WARN([to the Python executable, and re-run configure]) > + detected_python=none > + else > + AC_MSG_WARN([We recommend you to use Python 3 or later]) > + AC_MSG_WARN([but only Python 2.7 is detected.]) > + fi > fi > +PYTHON="$detected_python" > AC_SUBST(PYTHON) > > # The minimum version for the JVM runtime for our Java bytecode.