On 5/8/24 12:47 AM, Collin Funk wrote:
>> With .sh, both fail. With .py, both succeed. Looks like a bug in
>> gnulib-tool.py: When the 'make' or 'make check' step fails, the entire
>> command should fail.
>
> I see what you mean. I'll have a look at fixing that right now.

I've pushed the attached patch. In gnulib-tool.sh the following is
done:

    ../configure || func_exit 1
    $MAKE || func_exit 1
    [...]

So here we can just use sp.run([command, arg], check=True) and exit if
an exception occurs.

As a side note, gradually I'll start changing sp.call(),
sp.check_call(), etc. to sp.run(). Under the hood they all call the
same internal functions, but the latter is newer and "recommended"
[1].

I always forget how that module works and just using the recommended
sp.run() makes scanning the documentation easier.

[1] 
https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module

Collin
From 17b859fb7bdaff11c0e22b366a66623f9c5b6f6d Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 8 May 2024 01:24:09 -0700
Subject: [PATCH] gnulib-tool.py: Fix behavior of --test when a subprocess
 fails.

Reported by Bruno Haible in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00101.html>.

* pygnulib/main.py (main): Use sp.run with check=True so that an
exception is thrown when a process fails. Simply exit if an exception
occurs.
---
 ChangeLog        | 9 +++++++++
 pygnulib/main.py | 8 ++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 41a8ef7eb6..6d74b450bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-05-08  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix behavior of --test when a subprocess fails.
+	Reported by Bruno Haible in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2024-05/msg00101.html>.
+	* pygnulib/main.py (main): Use sp.run with check=True so that an
+	exception is thrown when a process fails. Simply exit if an exception
+	occurs.
+
 2024-05-07  Collin Funk  <collin.fu...@gmail.com>
 
 	base32, base64: Prefer stdckdint to intprops.
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 6e29374af2..128f25f9c1 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1098,10 +1098,10 @@ def main(temp_directory: str) -> None:
         os.mkdir('build')
         os.chdir('build')
         try:  # Try to execute commands
-            sp.call(['../configure'])
-            sp.call([UTILS['make']])
-            sp.call([UTILS['make'], 'check'])
-            sp.call([UTILS['make'], 'distclean'])
+            sp.run(['../configure'], check=True)
+            sp.run([UTILS['make']], check=True)
+            sp.run([UTILS['make'], 'check'], check=True)
+            sp.run([UTILS['make'], 'distclean'], check=True)
         except Exception:
             sys.exit(1)
         args = ['find', '.', '-type', 'f', '-print']
-- 
2.45.0

Reply via email to