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
From 3ca340c6a56d25e3e87786d12c04fcab2f8d0973 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@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.fu...@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.fu...@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
From fef3a610332a955c6ca29fdecdcb719fde4f7162 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@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.fu...@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.fu...@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