]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gnulib-tool.py: Simplify use of GLModuleTable accessors.
authorCollin Funk <collin.funk1@gmail.com>
Tue, 9 Apr 2024 07:01:49 +0000 (00:01 -0700)
committerBruno Haible <bruno@clisp.org>
Tue, 9 Apr 2024 12:40:05 +0000 (14:40 +0200)
* pygnulib/GLModuleSystem.py (GLModuleTable.__getitem__): Remove
function.
* pygnulib/GLImport.py (GLImport.gnulib_cache, GLImport.gnulib_comp)
(GLImport.execute): Use function calls on the GLModuleTable to access
module lists instead of using keys to emulate a dictionary.

ChangeLog
pygnulib/GLImport.py
pygnulib/GLModuleSystem.py

index c258cdfb3d9667b45b8fdf6b1640b34c7f53f956..b08142ab38794d308fe7af7a7e5761dddcd05940 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-04-09  Collin Funk  <collin.funk1@gmail.com>
+
+       gnulib-tool.py: Simplify use of GLModuleTable accessors.
+       * pygnulib/GLModuleSystem.py (GLModuleTable.__getitem__): Remove
+       function.
+       * pygnulib/GLImport.py (GLImport.gnulib_cache, GLImport.gnulib_comp)
+       (GLImport.execute): Use function calls on the GLModuleTable to access
+       module lists instead of using keys to emulate a dictionary.
+
 2024-04-09  Bruno Haible  <bruno@clisp.org>
 
        totalorder, totalorderf: Avoid miscompilation by clang on OpenBSD/i386.
index f890c07a865af89d06789e67636b01dc64099f6e..4a6f7c48b8933efb70ff8ef5d0164129878b1414 100644 (file)
@@ -524,7 +524,7 @@ class GLImport:
         witness_c_macro = self.config['witness_c_macro']
         vc_files = self.config['vc_files']
         modules = [ str(module)
-                    for module in moduletable['base'] ]
+                    for module in moduletable.getBaseModules() ]
         avoids = self.config['avoids']
         emit += self.emitter.copyright_notice()
         emit += '''#
@@ -630,8 +630,8 @@ AC_DEFUN([%s_EARLY],
   m4_pattern_allow([^gl_ES$])dnl a valid locale name
   m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
   m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable\n''' % (configure_ac, macro_prefix)
-        emit += self.emitter.preEarlyMacros(True, '  ', moduletable['final'])
-        for module in moduletable['final']:
+        emit += self.emitter.preEarlyMacros(True, '  ', moduletable.getFinalModules())
+        for module in moduletable.getFinalModules():
             emit += '  # Code from module %s:\n' % str(module)
             snippet = module.getAutoconfEarlySnippet()
             lines = [ line
@@ -677,7 +677,7 @@ AC_DEFUN([%s_INIT],
         if witness_c_macro:
             emit += '  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [%s])\n' % witness_c_macro
         # Emit main autoconf snippets.
-        emit += self.emitter.autoconfSnippets(moduletable['main'], moduletable['main'],
+        emit += self.emitter.autoconfSnippets(moduletable.getMainModules(), moduletable.getMainModules(),
                                               moduletable, 0, True, False, True, replace_auxdir)
         if witness_c_macro:
             emit += '  m4_popdef([gl_MODULE_INDICATOR_CONDITION])\n'
@@ -700,7 +700,8 @@ AC_DEFUN([%s_INIT],
         emit += '  m4_pushdef([gl_MODULE_INDICATOR_CONDITION], '
         emit += '[$gl_module_indicator_condition])\n'
         # Emit tests autoconf snippets.
-        emit += self.emitter.autoconfSnippets(moduletable['tests'], moduletable['main'] + moduletable['tests'],
+        emit += self.emitter.autoconfSnippets(moduletable.getTestsModules(),
+                                              moduletable.getMainModules() + moduletable.getTestsModules(),
                                               moduletable, 0, True, True, True, replace_auxdir)
         emit += '  m4_popdef([gl_MODULE_INDICATOR_CONDITION])\n'
         emit += self.emitter.initmacro_end('%stests' % macro_prefix, gentests)
@@ -1271,8 +1272,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         # can run 'autoconf -t', which reads gnulib-comp.m4.
         basename = joinpath(sourcebase, source_makefile_am)
         tmpfile = self.assistant.tmpfilename(basename)
-        emit = self.emitter.lib_Makefile_am(basename,
-                                            self.moduletable['main'], self.moduletable, self.makefiletable,
+        emit = self.emitter.lib_Makefile_am(basename, self.moduletable.getMainModules(),
+                                            self.moduletable, self.makefiletable,
                                             actioncmd, for_test)
         if automake_subdir:
             emit = sp.run([joinpath(DIRS['root'], 'build-aux/prefix-gnulib-mk'), '--from-gnulib-tool',
@@ -1299,8 +1300,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         if gentests:
             basename = joinpath(testsbase, tests_makefile_am)
             tmpfile = self.assistant.tmpfilename(basename)
-            emit = self.emitter.tests_Makefile_am(basename,
-                                                  self.moduletable['tests'], self.moduletable, self.makefiletable,
+            emit = self.emitter.tests_Makefile_am(basename, self.moduletable.getTestsModules(),
+                                                  self.moduletable, self.makefiletable,
                                                   '%stests_WITNESS' % macro_prefix, for_test)
             with codecs.open(tmpfile, 'wb', 'UTF-8') as file:
                 file.write(emit)
@@ -1360,7 +1361,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         # - some may have been skipped through --avoid, and since the elements of
         # 'main' modules but not in 'base' modules can go away without explicit
         # notice - through changes in the module dependencies).
-        modules = sorted(set(self.moduletable['base']).intersection(self.moduletable['main']))
+        modules = sorted(set(self.moduletable.getBaseModules()).intersection(self.moduletable.getMainModules()))
         # First the #include <...> directives without #ifs, sorted for convenience,
         # then the #include "..." directives without #ifs, sorted for convenience,
         # then the #include directives that are surrounded by #ifs. Not sorted.
@@ -1388,7 +1389,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
 
         # Get link directives.
         links = [ module.getLink()
-                  for module in self.moduletable['main'] ]
+                  for module in self.moduletable.getMainModules() ]
         lines = [ line
                   for link in links
                   for line in link.split('\n')
index c2e20b801a11c87f5508cbcfbe63c37ef7e98c6d..3ba9b7f473b76e7a9932427340e024a078113a6c 100644 (file)
@@ -761,21 +761,6 @@ class GLModuleTable:
         result = '<pygnulib.GLModuleTable %s>' % hex(id(self))
         return result
 
-    def __getitem__(self, y: str) -> list[GLModule]:
-        '''x.__getitem__(y) <==> x[y]'''
-        if y == 'base':
-            return self.getBaseModules()
-        elif y == 'final':
-            return self.getFinalModules()
-        elif y == 'main':
-            return self.getMainModules()
-        elif y == 'tests':
-            return self.getTestsModules()
-        elif y == 'avoids':
-            return self.getAvoids()
-        else:  # if y is not in list
-            raise KeyError('GLModuleTable does not contain key: %s' % repr(y))
-
     def addConditional(self, parent: GLModule, module: GLModule, condition: str | bool) -> None:
         '''Add new conditional dependency from parent to module with condition.'''
         if type(parent) is not GLModule: