Hi Collin,

> Thanks. I've attached a *very* rough patch that I think works
> similarly to gnulib-tool.sh if you would like to take a look at it.

Looks pretty good. I'm applying it, together with a follow-up below:

- Your ability to work with misnamed variables is amazing. But
  nonetheless let's make an effort to find better names :)

- Python has enough string processing primitives that we don't need
  to write conditional expressions like
    line if not line.endswith('\n') else line[:-1]

  (I also tried to move the removal of the newlines into the readlines()
  invocation, but that does not work:
  https://github.com/python/cpython/issues/52876 )

> I'm not sure the best way to test it. When using
> GNULIB_TOOL_IMPL=sh+py on Inetutils I get only this now:
> 
> diff --git a/home/collin/.local/src/inetutils/m4/gnulib-comp.m4 
> b/home/collin/.local/src/glpyVG0WNy/m4/gnulib-comp.m4
> index 5c38ac18..4fe2c5ce 100644
> --- a/home/collin/.local/src/inetutils/m4/gnulib-comp.m4
> +++ b/home/collin/.local/src/glpyVG0WNy/m4/gnulib-comp.m4
> @@ -42,6 +42,7 @@ AC_DEFUN([gl_EARLY],
>    AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
>    AC_REQUIRE([gl_PROG_AR_RANLIB])
>  
> +  AC_REQUIRE([AM_PROG_CC_C_O])
>    # Code from module absolute-header:
>    # Code from module alignasof:
>    # Code from module alignof:
> 
> Before this change I had an extra '.gitignore~'.

Looks pretty good!

Bruno


2024-03-25  Bruno Haible  <br...@clisp.org>

        gnulib-tool.py: Tweak last change.
        * pygnulib/GLImport.py (GLImport._update_ignorelist_): Rename some local
        variables. Use rstrip built-in function.

diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 0fe465f1de..882f1993af 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -805,25 +805,27 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                 with codecs.open(joinpath(destdir, srcpath), 'rb', 'UTF-8') as 
file:
                     original_lines = file.readlines()
                 # Clean the newlines but not trailing whitespace.
-                original_lines = [ line if not line.endswith('\n') else 
line[:-1]
+                original_lines = [ line.rstrip('\n')
                                    for line in original_lines ]
-                dirs_ignore = { constants.substart(anchor, '', filename)
-                                for filename in original_lines
-                                if filename.strip() }
-                dirs_added = set(files_added).difference(dirs_ignore)
-                dirs_removed = set(files_removed)
-                if dirs_added or dirs_removed:
+                already_listed_filenames = { constants.substart(anchor, '', 
filename)
+                                             for filename in original_lines
+                                             if filename.strip() }
+                filenames_to_add = 
set(files_added).difference(already_listed_filenames)
+                filenames_to_remove = set(files_removed)
+                if filenames_to_add or filenames_to_remove:
                     if not self.config['dryrun']:
                         print('Updating %s (backup in %s)' % (srcpath, 
backupname))
                         copyfile2(joinpath(destdir, srcpath), 
joinpath(destdir, backupname))
                         new_lines = original_lines + [ f'{anchor}{filename}'
-                                                       for filename in 
sorted(dirs_added) ]
+                                                       for filename in 
sorted(filenames_to_add) ]
                         if anchor != '':
-                            dirs_removed = dirs_removed.union({ 
f'{anchor}{filename}'
-                                                                for filename 
in dirs_removed })
+                            lines_to_remove = filenames_to_remove.union({ 
f'{anchor}{filename}'
+                                                                          for 
filename in filenames_to_remove })
+                        else:
+                            lines_to_remove = filenames_to_remove
                         new_lines = [ line
                                       for line in new_lines
-                                      if line not in dirs_removed ]
+                                      if line not in lines_to_remove ]
                         with codecs.open(joinpath(destdir, srcpath), 'wb', 
'UTF-8') as file:
                             file.write(lines_to_multiline(new_lines))
                     else:  # if self.config['dryrun']




Reply via email to