diff mbox series

[v2] contrib: Improve dg-extract-results.sh's Python detection

Message ID 20240307142812.217417-1-sam@gentoo.org
State New
Headers show
Series [v2] contrib: Improve dg-extract-results.sh's Python detection | expand

Commit Message

Sam James March 7, 2024, 2:27 p.m. UTC
'python' on some systems (e.g. SLES 15) might be Python 2. Prefer python3,
then python, then python2 (as the script still tries to work there).

contrib/ChangeLog:

    * dg-extract-results.sh: Check for python3 before python. Check for python2 last.
---
v2: Add python2 and drop EPYTHON.

 contrib/dg-extract-results.sh | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Comments

Jeff Law March 8, 2024, 3:19 p.m. UTC | #1
On 3/7/24 07:27, Sam James wrote:
> 'python' on some systems (e.g. SLES 15) might be Python 2. Prefer python3,
> then python, then python2 (as the script still tries to work there).
> 
> contrib/ChangeLog:
> 
>      * dg-extract-results.sh: Check for python3 before python. Check for python2 last.
OK.  And given that the shell version is just fundamentally broken for 
parallel checks, consider a patch to remove it pre-approved.

Jeff
diff mbox series

Patch

diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
index 00ef80046f74..9398de786125 100755
--- a/contrib/dg-extract-results.sh
+++ b/contrib/dg-extract-results.sh
@@ -28,14 +28,17 @@ 
 
 PROGNAME=dg-extract-results.sh
 
-# Try to use the python version if possible, since it tends to be faster.
+# Try to use the python version if possible, since it tends to be faster and
+# produces more stable results.
 PYTHON_VER=`echo "$0" | sed 's/sh$/py/'`
-if test "$PYTHON_VER" != "$0" &&
-   test -f "$PYTHON_VER" &&
-   python -c 'import sys, getopt, re, io, datetime, operator; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
-     > /dev/null 2> /dev/null; then
-  exec python $PYTHON_VER "$@"
-fi
+for python in python3 python python2 ; do
+	if test "$PYTHON_VER" != "$0" &&
+	   test -f "$PYTHON_VER" &&
+	   ${python} -c 'import sys, getopt, re, io, datetime, operator; sys.exit (0 if sys.version_info >= (2, 6) else 1)' \
+	     > /dev/null 2> /dev/null; then
+	  exec ${python} $PYTHON_VER "$@"
+	fi
+done
 
 usage() {
   cat <<EOF >&2