bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-tool.py: Add a new GLFileTable class.


From: Collin Funk
Subject: gnulib-tool.py: Add a new GLFileTable class.
Date: Wed, 24 Apr 2024 16:41:09 -0700
User-agent: Mozilla Thunderbird

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

Collin

Attachment: 0001-gnulib-tool.py-Add-a-new-GLFileTable-class.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]