Hi Collin,

> On 3/10/24 5:13 AM, Bruno Haible wrote:
> >   automake_options = {x for y in configure_ac_automake_options for x in 
> > y.split()}
> 
> I've attached the fixed patch.

Thanks, applied.

> I would like to double check the regular expression I used:
> 
>     pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^\]\)]*).*$', 
> re.MULTILINE)
> 
> Compared to the sed one:
> 
>     s,^.*AM_INIT_AUTOMAKE([[ ]*\([^])]*\).*$,\1,p

This looks good to me. 'sed' accepts POSIX BREs, where '(' and '[' stand for
the literal '(' and '[' characters unless escaped.

Also, I applied the attached follow-up, in order to make the logic of the code
easier to follow. There was nothing wrong in your code; it's just to make it
more straightforward to read.
  - There's no need to define 'pattern' before reading the file. So, define
    it after reading the file.
  - The 'base' variable is only needed in the 'if not found_subdir_objects'
    case. So, define it only in this case.
  - Make the two code blocks that read configure.ac and Makefile.am more
    similar.

Bruno

>From 2045ee7288c2a4d0dbea090ae5b829557f96dc1a Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Mon, 11 Mar 2024 12:49:24 +0100
Subject: [PATCH] gnulib-tool.py: Make some code more straightforward.

* pygnulib/GLImport.py (GLImport.__init__): Reorder assignments and
conditions slightly.
---
 ChangeLog            |  6 ++++++
 pygnulib/GLImport.py | 33 +++++++++++++++++----------------
 2 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9135b6b779..308f75a4ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-03-11  Bruno Haible  <br...@clisp.org>
+
+	gnulib-tool.py: Make some code more straightforward.
+	* pygnulib/GLImport.py (GLImport.__init__): Reorder assignments and
+	conditions slightly.
+
 2024-03-11  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 52.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index de2961c55e..1dabccd201 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -261,31 +261,32 @@ class GLImport(object):
 
         # Determine whether --automake-subdir is supported.
         if self.config['automake_subdir']:
-            automake_options = set()
+            found_subdir_objects = False
             if self.config['destdir']:
-                pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^\]\)]*).*$', re.MULTILINE)
                 with open(self.config['configure_ac'], encoding='utf-8') as file:
                     data = file.read()
+                pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^\]\)]*).*$', re.MULTILINE)
                 configure_ac_automake_options = pattern.findall(data)
                 if configure_ac_automake_options:
                     automake_options = { x
                                          for y in configure_ac_automake_options
                                          for x in y.split() }
-            found_subdir_objects = 'subdir-objects' in automake_options
-            if self.config['destdir']:
-                base = self.config['destdir']
-            else:
-                base = '.'
-            if not found_subdir_objects and isfile(joinpath(base, 'Makefile.am')):
-                pattern = re.compile(r'^AUTOMAKE_OPTIONS[\t ]*=(.*)$', re.MULTILINE)
-                with open(joinpath(base, 'Makefile.am'), encoding='utf-8') as file:
-                    data = file.read()
-                automake_options = pattern.findall(data)
-                if automake_options:
-                    automake_options = { x
-                                         for y in automake_options
-                                         for x in y.split() }
                     found_subdir_objects = 'subdir-objects' in automake_options
+            if not found_subdir_objects:
+                if self.config['destdir']:
+                    base = self.config['destdir']
+                else:
+                    base = '.'
+                if isfile(joinpath(base, 'Makefile.am')):
+                    with open(joinpath(base, 'Makefile.am'), encoding='utf-8') as file:
+                        data = file.read()
+                    pattern = re.compile(r'^AUTOMAKE_OPTIONS[\t ]*=(.*)$', re.MULTILINE)
+                    automake_options = pattern.findall(data)
+                    if automake_options:
+                        automake_options = { x
+                                             for y in automake_options
+                                             for x in y.split() }
+                        found_subdir_objects = 'subdir-objects' in automake_options
             if not found_subdir_objects:
                 raise GLError(21, None)
 
-- 
2.34.1

Reply via email to