From 9d3be090167bf818850aaf01fb08edfdda2896e0 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Tue, 9 Apr 2024 00:01:49 -0700 Subject: [PATCH] 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. --- ChangeLog | 9 +++++++++ pygnulib/GLImport.py | 23 ++++++++++++----------- pygnulib/GLModuleSystem.py | 15 --------------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82c9899294..342f232d60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-04-09 Collin Funk + + 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-08 Collin Funk gnulib-tool.py: Use single-quotes for strings, part 2. diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index f890c07a86..4a6f7c48b8 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -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') diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index c2e20b801a..3ba9b7f473 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -761,21 +761,6 @@ class GLModuleTable: result = '' % 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: -- 2.44.0