Hi Bruno,

On 2/24/24 5:25 PM, Bruno Haible wrote:
> None of the 'sort' invocations in gnulib-tool are covered by an
> entry in the gnulib-tool.py.TODO file. Therefore the most promising
> approach to finding the cause of the difference is to
>   - go through all 'sort' invocations in gnulib-tool,
>   - find the corresponding place in pygnulib/ and see whether
>     sorting happens there as well or has been forgotten.

Thank you for the advice and for looking over all of these patches. I
think that this patch should be a solution to the issue as long as I
am understanding gnulib-tool correctly.

>From what I could understand, it seems that upon seeing that the mode
is "import", the specified_modules is set with the unsorted list of
modules [1]. Then that variable is sorted before it is used [2]. Could
you confirm that I am understanding this correctly?

If so, I feel that this patch should be the correct way to handle it.
My initial ideas where to sort the modules in main() before the
GLConfig object was created, or to modify the GLConfig class's methods
which are used to set the modules in use. I think the second option is
less likely to be broken by future changes. The changes involve using
a set and sorted() to substitute `sort -u'.

[1] https://git.savannah.gnu.org/cgit/gnulib.git/tree/gnulib-tool#n5085
[2] https://git.savannah.gnu.org/cgit/gnulib.git/tree/gnulib-tool#n5268
From 93d4e7698afc92e3b257c2a0b2050540357edc96 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sat, 24 Feb 2024 19:05:51 -0800
Subject: [PATCH] gnulib-tool.py: Handle the sorting of modules correctly.

See discussion at
<https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00219.html>

* pygnulib/GLConfig.py (GLConfig.addModule, CLConfig.setModules): Use a
sorted set when adding modules to replicate "sort -u" used by
gnulib-tool.
* pygnulib/GLImport.py (GLImport.actioncmd): Don't sort modules when
constructing actioncmd as GLConfig handles it for us.
---
 ChangeLog            | 11 +++++++++++
 pygnulib/GLConfig.py |  6 ++++--
 pygnulib/GLImport.py |  4 ++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1910933eb7..a616db7e09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-02-24  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Handle the sorting of modules correctly.
+	See discussion at
+	<https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00219.html>
+	* pygnulib/GLConfig.py (GLConfig.addModule, CLConfig.setModules): Use a
+	sorted set when adding modules to replicate "sort -u" used by
+	gnulib-tool.
+	* pygnulib/GLImport.py (GLImport.actioncmd): Don't sort modules when
+	constructing actioncmd as GLConfig handles it for us.
+
 2024-02-24  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 28.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index bdebf243cc..03da6f8e3c 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -476,7 +476,7 @@ class GLConfig(object):
         '''Add the module to the modules list.'''
         if type(module) is str:
             if module not in self.table['modules']:
-                self.table['modules'] += [module]
+                self.table['modules'] = sorted(list(set(self.table['modules'] + [module])))
         else:  # if module has not str type
             raise TypeError('module must be a string, not %s'
                             % type(module).__name__)
@@ -499,7 +499,9 @@ class GLConfig(object):
         if type(modules) is list or type(modules) is tuple:
             old_modules = self.table['modules']
             self.table['modules'] = list()
-            for module in modules:
+            # Canonicalize the list of specified modules.
+            # sort -u
+            for module in sorted(set(modules)):
                 try:  # Try to add each module
                     self.addModule(module)
                 except TypeError as error:
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index c69a33deb7..9b08e7e4b6 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -438,9 +438,9 @@ class GLImport(object):
         elif vc_files == False:
             actioncmd += ' \\\n#  --no-vc-files'
         if len(avoids) > 0:
-            actioncmd += ''.join([f" \\\n#  --avoid={x}" for x in sorted(avoids)])
+            actioncmd += ''.join([f" \\\n#  --avoid={x}" for x in avoids])
         if len(modules) > 0:
-            actioncmd += ''.join([f" \\\n#  {x}" for x in sorted(modules)])
+            actioncmd += ''.join([f" \\\n#  {x}" for x in modules])
         return actioncmd
 
     def relative_to_destdir(self, dir):
-- 
2.39.2

Reply via email to