bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Collin Funk <collin.funk1@gmail.com>
To: bug-gnulib@gnu.org
Subject: Re: gnulib-tool.py: Remove a redundant function.
Date: Sun, 14 Apr 2024 19:20:21 -0700	[thread overview]
Message-ID: <1b2f9946-96fb-40ea-bd9f-0466bc87456b@gmail.com> (raw)
In-Reply-To: <c7033250-db71-4b45-b9b8-6fac4075c511@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1089 bytes --]

On 4/14/24 6:23 PM, Collin Funk wrote:
> Also, I noticed we have:
> 
>          for src in old_files:
>              dest = self.rewrite_files([src])[-1]
>              old_table.append(tuple([dest, src]))
> 
> This is looping over a list, creating a new list with one item,
> calling GLImport.rewrite_files(), which then calls sorted(set(...))
> twice, and then appending the result to a list.
> 
> We should be able to create a new list from that function and zip()
> the two together. I'll submit another patch for that since it requires
> some sorting changes.

Patch 0002 does this. GLTestDir also has this rewrite_files() function
so I did the same there. Maybe it is worth making that a helper
function or using a base class in the future.

Also, the set() and list() calls around zip(...) are important since
zip() returns an iterator [1]. I've used whichever was most similar to
the previous code.

Patch 0003 removes a directories list that was unused. These are
created in the loop below it as files are written.

[1] https://docs.python.org/3/library/functions.html#zip

Collin

[-- Attachment #2: 0002-gnulib-tool.py-Refactor-file-name-transformations.patch --]
[-- Type: text/x-patch, Size: 4633 bytes --]

From 3ca340c6a56d25e3e87786d12c04fcab2f8d0973 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Sun, 14 Apr 2024 18:55:36 -0700
Subject: [PATCH 2/3] gnulib-tool.py: Refactor file name transformations.

* pygnulib/GLImport.py (GLImport.rewrite_files): Don't sort and don't
remove duplicates.
(GLImport.prepare): Pass the the file list to rewrite_files and zip
it together the result.
* pygnulib/GLTestDir.py (GLTestDir.rewrite_files): Don't sort and don't
remove duplicates.
(GLTestDir.execute): Pass the the file list to rewrite_files and zip
it together the result.
---
 ChangeLog             | 12 ++++++++++++
 pygnulib/GLImport.py  | 15 +++------------
 pygnulib/GLTestDir.py |  8 ++------
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 82c4a5f838..cf52f56b19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-04-14  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Refactor file name transformations.
+	* pygnulib/GLImport.py (GLImport.rewrite_files): Don't sort and don't
+	remove duplicates.
+	(GLImport.prepare): Pass the the file list to rewrite_files and zip
+	it together the result.
+	* pygnulib/GLTestDir.py (GLTestDir.rewrite_files): Don't sort and don't
+	remove duplicates.
+	(GLTestDir.execute): Pass the the file list to rewrite_files and zip
+	it together the result.
+
 2024-04-14  Collin Funk  <collin.funk1@gmail.com>
 
 	gnulib-tool.py: Remove a redundant function.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 430691efbd..ceacfbb232 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -323,7 +323,6 @@ def rewrite_files(self, files: list[str]) -> list[str]:
         for file in files:
             if type(file) is not str:
                 raise TypeError('each file must be a string instance')
-        files = sorted(set(files))
         auxdir = self.config['auxdir']
         docbase = self.config['docbase']
         sourcebase = self.config['sourcebase']
@@ -348,7 +347,7 @@ def rewrite_files(self, files: list[str]) -> list[str]:
             else:  # file is not a special file
                 path = file
             result.append(os.path.normpath(path))
-        return sorted(set(result))
+        return result
 
     def actioncmd(self) -> str:
         '''Return command-line invocation comment.'''
@@ -918,16 +917,8 @@ def prepare(self) -> tuple[dict[str, list[str]], dict[str, str]]:
         transformers['aux'] = sed_transform_build_aux_file
         transformers['main'] = sed_transform_main_lib_file
         transformers['tests'] = sed_transform_testsrelated_lib_file
-        old_table = []
-        new_table = []
-        for src in old_files:
-            dest = self.rewrite_files([src])[-1]
-            old_table.append(tuple([dest, src]))
-        for src in new_files:
-            dest = self.rewrite_files([src])[-1]
-            new_table.append(tuple([dest, src]))
-        old_table = sorted(set(old_table))
-        new_table = sorted(set(new_table))
+        old_table = sorted(set(zip(self.rewrite_files(old_files), old_files)))
+        new_table = sorted(set(zip(self.rewrite_files(new_files), new_files)))
 
         # Prepare the filetable.
         filetable = dict()
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index a7709a1259..dee8d629dc 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -138,7 +138,6 @@ def rewrite_files(self, files: list[str]) -> list[str]:
         for file in files:
             if type(file) is not str:
                 raise TypeError('each file must be a string instance')
-        files = sorted(set(files))
         auxdir = self.config['auxdir']
         docbase = self.config['docbase']
         sourcebase = self.config['sourcebase']
@@ -163,7 +162,7 @@ def rewrite_files(self, files: list[str]) -> list[str]:
             else:  # file is not a special file
                 path = file
             result.append(os.path.normpath(path))
-        return sorted(set(result))
+        return result
 
     def execute(self) -> None:
         '''Create a scratch package with the given modules.'''
@@ -350,10 +349,7 @@ def execute(self) -> None:
         directories = sorted(set(directories))
 
         # Copy files or make symbolic links or hard links.
-        filetable = []
-        for src in filelist:
-            dest = self.rewrite_files([src])[-1]
-            filetable.append(tuple([dest, src]))
+        filetable = list(zip(self.rewrite_files(filelist), filelist))
         for row in filetable:
             src = row[1]
             dest = row[0]
-- 
2.44.0


[-- Attachment #3: 0003-gnulib-tool.py-Remove-an-unused-variable.patch --]
[-- Type: text/x-patch, Size: 1521 bytes --]

From fef3a610332a955c6ca29fdecdcb719fde4f7162 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.funk1@gmail.com>
Date: Sun, 14 Apr 2024 19:00:35 -0700
Subject: [PATCH 3/3] gnulib-tool.py: Remove an unused variable.

* pygnulib/GLTestDir.py (GLTestDir.execute): Remove the unused
directories variable.
---
 ChangeLog             | 6 ++++++
 pygnulib/GLTestDir.py | 5 -----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cf52f56b19..32e454d32e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-14  Collin Funk  <collin.funk1@gmail.com>
+
+	gnulib-tool.py: Remove an unused variable.
+	* pygnulib/GLTestDir.py (GLTestDir.execute): Remove the unused
+	directories variable.
+
 2024-04-14  Collin Funk  <collin.funk1@gmail.com>
 
 	gnulib-tool.py: Refactor file name transformations.
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index dee8d629dc..8ebe28b70a 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -343,11 +343,6 @@ def execute(self) -> None:
         filelist += ['build-aux/config.guess', 'build-aux/config.sub']
         filelist = sorted(set(filelist))
 
-        # Create directories.
-        directories = [os.path.dirname(file)
-                       for file in self.rewrite_files(filelist)]
-        directories = sorted(set(directories))
-
         # Copy files or make symbolic links or hard links.
         filetable = list(zip(self.rewrite_files(filelist), filelist))
         for row in filetable:
-- 
2.44.0


  reply	other threads:[~2024-04-15  2:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15  1:23 gnulib-tool.py: Remove a redundant function Collin Funk
2024-04-15  2:20 ` Collin Funk [this message]
2024-04-15 14:58   ` Bruno Haible
2024-04-15 15:24     ` Collin Funk
2024-04-16 15:09       ` Bruno Haible
2024-04-16 16:23         ` Collin Funk
2024-04-17  1:12         ` Refactoring rewrite_filename functions Collin Funk
2024-04-17  1:35           ` Bruno Haible
2024-04-17  2:08             ` Collin Funk
2024-04-17 14:03               ` Bruno Haible
2024-04-15 11:47 ` gnulib-tool.py: Remove a redundant function Bruno Haible
2024-04-15 14:07   ` Collin Funk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b2f9946-96fb-40ea-bd9f-0466bc87456b@gmail.com \
    --to=collin.funk1@gmail.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).