public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] contrib: Improve dg-extract-results.sh's Python detection
@ 2024-03-07 14:16 Sam James
  2024-03-07 14:21 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Sam James @ 2024-03-07 14:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: law, rguenth, Sam James

'python' on some systems (e.g. SLES 15) might be Python 2. Prefer ${EPYTHON}
if defined (used by Gentoo's python-exec wrapping), then python3, then python.

contrib/ChangeLog:

    * dg-extract-results.sh: Check for python3 before python.
---
 contrib/dg-extract-results.sh | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
index 00ef80046f74..2d1cd76fe255 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 ${EPYTHON:-python3} python ; 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
-- 
2.44.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] contrib: Improve dg-extract-results.sh's Python detection
  2024-03-07 14:16 [PATCH] contrib: Improve dg-extract-results.sh's Python detection Sam James
@ 2024-03-07 14:21 ` Jakub Jelinek
  2024-03-07 14:25   ` Sam James
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2024-03-07 14:21 UTC (permalink / raw)
  To: Sam James; +Cc: gcc-patches, law, rguenth

On Thu, Mar 07, 2024 at 02:16:37PM +0000, Sam James wrote:
> 'python' on some systems (e.g. SLES 15) might be Python 2. Prefer ${EPYTHON}
> if defined (used by Gentoo's python-exec wrapping), then python3, then python.

I'd say EPYTHON is too distro specific, just use for python in python3 python ?
Other scripts just have
#!/usr/bin/env python3
as the first line and go with that.

> contrib/ChangeLog:
> 
>     * dg-extract-results.sh: Check for python3 before python.
> ---
>  contrib/dg-extract-results.sh | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
> index 00ef80046f74..2d1cd76fe255 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 ${EPYTHON:-python3} python ; 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
> -- 
> 2.44.0

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] contrib: Improve dg-extract-results.sh's Python detection
  2024-03-07 14:21 ` Jakub Jelinek
@ 2024-03-07 14:25   ` Sam James
  2024-03-07 14:26     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Sam James @ 2024-03-07 14:25 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, law, rguenth

Jakub Jelinek <jakub@redhat.com> writes:

> On Thu, Mar 07, 2024 at 02:16:37PM +0000, Sam James wrote:
>> 'python' on some systems (e.g. SLES 15) might be Python 2. Prefer ${EPYTHON}
>> if defined (used by Gentoo's python-exec wrapping), then python3, then python.
>
> I'd say EPYTHON is too distro specific, just use for python in python3 python ?
> Other scripts just have
> #!/usr/bin/env python3
> as the first line and go with that.

Sure. Should I add python2 too as well (last), given the script nominally tries to
work with it still?

>
>> contrib/ChangeLog:
>> 
>>     * dg-extract-results.sh: Check for python3 before python.
>> ---
>>  contrib/dg-extract-results.sh | 17 ++++++++++-------
>>  1 file changed, 10 insertions(+), 7 deletions(-)
>> 
>> diff --git a/contrib/dg-extract-results.sh b/contrib/dg-extract-results.sh
>> index 00ef80046f74..2d1cd76fe255 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 ${EPYTHON:-python3} python ; 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
>> -- 
>> 2.44.0
>
> 	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] contrib: Improve dg-extract-results.sh's Python detection
  2024-03-07 14:25   ` Sam James
@ 2024-03-07 14:26     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2024-03-07 14:26 UTC (permalink / raw)
  To: Sam James; +Cc: gcc-patches, law, rguenth

On Thu, Mar 07, 2024 at 02:25:09PM +0000, Sam James wrote:
> Jakub Jelinek <jakub@redhat.com> writes:
> 
> > On Thu, Mar 07, 2024 at 02:16:37PM +0000, Sam James wrote:
> >> 'python' on some systems (e.g. SLES 15) might be Python 2. Prefer ${EPYTHON}
> >> if defined (used by Gentoo's python-exec wrapping), then python3, then python.
> >
> > I'd say EPYTHON is too distro specific, just use for python in python3 python ?
> > Other scripts just have
> > #!/usr/bin/env python3
> > as the first line and go with that.
> 
> Sure. Should I add python2 too as well (last), given the script nominally tries to
> work with it still?

Yes.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-07 14:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 14:16 [PATCH] contrib: Improve dg-extract-results.sh's Python detection Sam James
2024-03-07 14:21 ` Jakub Jelinek
2024-03-07 14:25   ` Sam James
2024-03-07 14:26     ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).