I've applied the following patch adding a GLFileTable class as
discussed here:
https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00357.html
For the most part this just changes a dictionary in GLImport to an
actual class. So field initialization is done in GLFileTable.__init__()
and uses are changed like this:
filetable['all'] -> filetable.all_files
filetable['old'] -> filetable.old_files
This is beneficial since the fields can be individually typed. Since
old_files is a list[tuple[str, str]] where the tuple is:
(rewritten-file-name, old-file-name)
# for example, using gl_M4_BASE([glm4])
('glm4/gnulib-cache.m4', 'm4/gnulib-cache.m4')
while all_files only contains 'm4/gnulib-cache.m4'.
I've also used this class in GLTestDir since there are obvious ways to
reduce code duplication there. Specifically the rewrite_filename
stuff in GLImport.prepare() and GLTestDir.execute().
Since I noticed some discussion about bootstrapping, I have focused a
bit more on Python version compatibility. Just so that I have *some*
idea of what will need to be changed if there is ever a need.
+class GLFileTable:
+'''The GLFileTable class stores file information for the duration of the
+operation being executed.'''
+
+all_files: list[str]
+old_files: list[tuple[str, str]]
+new_files: list[tuple[str, str]]
+added_files: list[str]
+removed_files: list[str]
This syntax was introduced in Python 3.6 which is okay for our
dependency on Python 3.7. For older versions they can be removed or be
placed in comments [1]. I've gone with it since I imagine there will
be bigger fish to fry by lowering the version dependency.
[1] https://peps.python.org/pep-0484/#type-comments
CollinFrom 962397de1dc64f44c5736be14efd9ffb95c93c65 Mon Sep 17 00:00:00 2001
From: Collin Funk
Date: Wed, 24 Apr 2024 16:04:25 -0700
Subject: [PATCH] gnulib-tool.py: Add a new GLFileTable class.
* pygnulib/GLFileTable.py: New file. Define the GLFileTable class with
five attributes which can be individually typed.
* pygnulib/GLTestDir.py (GLTestDir.execute): Use the GLFileTable class.
* pygnulib/GLImport.py (GLImport.gnulib_comp, GLImport.prepare)
(GLImport.execute): Likewise. Update type hints and doc strings.
---
ChangeLog | 9
pygnulib/GLFileTable.py | 36 ++
pygnulib/GLImport.py| 102 +++-
pygnulib/GLTestDir.py | 18 +++
4 files changed, 103 insertions(+), 62 deletions(-)
create mode 100644 pygnulib/GLFileTable.py
diff --git a/ChangeLog b/ChangeLog
index 676aaef0be..ee17881d2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-04-24 Collin Funk
+
+ gnulib-tool.py: Add a new GLFileTable class.
+ * pygnulib/GLFileTable.py: New file. Define the GLFileTable class with
+ five attributes which can be individually typed.
+ * pygnulib/GLTestDir.py (GLTestDir.execute): Use the GLFileTable class.
+ * pygnulib/GLImport.py (GLImport.gnulib_comp, GLImport.prepare)
+ (GLImport.execute): Likewise. Update type hints and doc strings.
+
2024-04-24 Paul Eggert
largefile: port to C++
diff --git a/pygnulib/GLFileTable.py b/pygnulib/GLFileTable.py
new file mode 100644
index 00..6180e0d318
--- /dev/null
+++ b/pygnulib/GLFileTable.py
@@ -0,0 +1,36 @@
+# Copyright (C) 2002-2024 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+from __future__ import annotations
+
+
+class GLFileTable:
+'''The GLFileTable class stores file information for the duration of the
+operation being executed.'''
+
+all_files: list[str]
+old_files: list[tuple[str, str]]
+new_files: list[tuple[str, str]]
+added_files: list[str]
+removed_files: list[str]
+
+def __init__(self, all_files: list[str]) -> None:
+'''Create a GLFileTable with initialized fields.
+- all_files, a list of all files being operated on.'''
+self.all_files = all_files
+self.old_files = []
+self.new_files = []
+self.added_files = []
+self.removed_files = []
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 0bab7ca150..cf1ebd10ec 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -46,6 +46,7 @@
from .GLFileSystem import GLFileAssistant
from .GLMakefileTable import GLMakefileTable
from .GLEmiter import GLEmiter
+from .GLF