bug-gnulib
[Top][All Lists]
Advanced

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

gnulib-tool.py: Simplify data structures for dependencies.


From: Collin Funk
Subject: gnulib-tool.py: Simplify data structures for dependencies.
Date: Fri, 19 Apr 2024 12:37:57 -0700
User-agent: Mozilla Thunderbird

Hi Bruno,

Previously I suggested using defaultdict to remove the base
initialization case for dictionaries. But you noted a mistake I made
in my patch [1]:

> It's a nice Python class. But the use of defaultdict(list) makes only
> the two lines
> 
>             if str(module) not in self.dependers:
>                 self.dependers[str(module)] = []
> 
> redundant. It does not make the line
> 
>             if str(parent) not in self.dependers[str(module)]:
> 
> redundant. self.dependers[str(module)] should not contain duplicates.

Patch 0001 does the same but uses a set instead of checking for
membership in a list. The sets in self.dependers[str(module)] seems
relatively small atleast with ./test-emacs-1.sh so there won't be a
noticeable difference. But I think it is more clear.

Also, am I missing something or are the sets/lists at
self.dependers[str(module)] unused? Maybe it is due to translating
this section of code from associative arrays in bash/other shells? I'm
not very familiar so that is just a guess on my part.

Patch 0002 changes the str(module) inserted into lists in that section
of code to directly use the GLModule object. For accessing the
conditionals dictionaries we can use a tuple:

    (parent, module)

instead of a string like gnulib-tool.sh:

    '%s---%s' % (str(parent), str(module))

This makes this part of the code use GLModule's __hash__ method for
lookups instead of a string. A tuple containing all hashable elements
is also hashable so we can use that as the key.

Currently since GLModule.__hash__ only uses the module name, this has
the same meaning as the previous code. The benefit is that if in a
decade Gnulib wants more complex dependencies, you no longer have to
figure out how to fit it in a string. The only downside I can think of
is you can no longer grep for "---" to find the same section of code
in gnulib-tool.sh.

Also the str(module) sort of makes things harder to read. It is mostly
my fault that we have three ways to get a GLModule objects name:

    str(module)
    module.name
    module.getName()

which are all used in various places...

[1] https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00112.html

Collin

Attachment: 0001-gnulib-tool.py-Simplify-data-structures-for-dependen.patch
Description: Text Data

Attachment: 0002-gnulib-tool.py-Make-use-of-GLModule-s-__hash__-metho.patch
Description: Text Data


reply via email to

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