From 3ca340c6a56d25e3e87786d12c04fcab2f8d0973 Mon Sep 17 00:00:00 2001 From: Collin Funk 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 + + 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 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