>From 52a5f9e36e331ab48bdb1f113988fd4b02cb7495 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 2 Apr 2024 13:42:53 +0200 Subject: [PATCH 4/4] gnulib-tool: Remove unused variables. * pygnulib/GLConfig.py: Remove unused variables. * pygnulib/GLEmiter.py: Likewise. * pygnulib/GLFileSystem.py: Likewise. * pygnulib/GLImport.py: Likewise. * pygnulib/GLInfo.py: Likewise. * pygnulib/GLModuleSystem.py: Likewise. * pygnulib/GLTestDir.py: Likewise. * pygnulib/main.py: Likewise. * gnulib-tool.sh (func_emit_tests_Makefile_am): Remove unused variable perhapsLT. --- ChangeLog | 12 ++++++++++ gnulib-tool.sh | 2 -- pygnulib/GLConfig.py | 13 +++++------ pygnulib/GLEmiter.py | 8 ------- pygnulib/GLFileSystem.py | 13 +++++------ pygnulib/GLImport.py | 46 ++------------------------------------ pygnulib/GLInfo.py | 1 - pygnulib/GLModuleSystem.py | 18 +++++---------- pygnulib/GLTestDir.py | 12 +++------- pygnulib/main.py | 2 +- 10 files changed, 34 insertions(+), 93 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3efa3fab71..5c51c94166 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2024-04-02 Bruno Haible + gnulib-tool: Remove unused variables. + * pygnulib/GLConfig.py: Remove unused variables. + * pygnulib/GLEmiter.py: Likewise. + * pygnulib/GLFileSystem.py: Likewise. + * pygnulib/GLImport.py: Likewise. + * pygnulib/GLInfo.py: Likewise. + * pygnulib/GLModuleSystem.py: Likewise. + * pygnulib/GLTestDir.py: Likewise. + * pygnulib/main.py: Likewise. + * gnulib-tool.sh (func_emit_tests_Makefile_am): Remove unused variable + perhapsLT. + gnulib-tool.py: Remove no-op statements. * pygnulib/GLConfig.py (GLConfig.update): Remove no-op statement. diff --git a/gnulib-tool.sh b/gnulib-tool.sh index 6b12542adc..197744d8ed 100755 --- a/gnulib-tool.sh +++ b/gnulib-tool.sh @@ -4173,11 +4173,9 @@ func_emit_tests_Makefile_am () witness_macro="$1" if test "$libtool" = true; then libext=la - perhapsLT=LT sed_eliminate_LDFLAGS="$sed_noop" else libext=a - perhapsLT= sed_eliminate_LDFLAGS='/^lib_LDFLAGS[ ]*+=/d' fi # Replace NMD, so as to remove redundant "$(MKDIR_P) '.'" invocations. diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index de720488c9..63d1d06b1c 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -251,9 +251,6 @@ class GLConfig(object): def __getitem__(self, y: str) -> str | float | int | bool | CopyAction | list[str] | None: '''x.__getitem__(y) <==> x[y]''' if y in self.table: - result = self.table[y] - if type(y) is list: - result = list(self.table[y]) if y == "auxdir": if self.table['auxdir']: return self.table['auxdir'] @@ -546,7 +543,7 @@ class GLConfig(object): for module in modules: try: # Try to add each module self.addModule(module) - except TypeError as error: + except TypeError: self.table['modules'] = old_modules raise TypeError('each module must be a string') except GLError: @@ -592,7 +589,7 @@ class GLConfig(object): for module in modules: try: # Try to add each module self.addAvoid(module) - except TypeError as error: + except TypeError: self.table['avoids'] = old_avoids raise TypeError('each module must be a string') except GLError: @@ -637,7 +634,7 @@ class GLConfig(object): for file in files: try: # Try to add each file self.addFile(file) - except TypeError as error: + except TypeError: self.table['files'] = old_files raise TypeError('each file must be a string') except GLError: @@ -695,7 +692,7 @@ class GLConfig(object): for category in categories: try: # Try to enable each category self.enableInclTestCategory(category) - except TypeError as error: + except TypeError: self.table['incl_test_categories'] = old_categories raise TypeError('each category must be one of TESTS integers') else: # if type of categories is not list or tuple @@ -743,7 +740,7 @@ class GLConfig(object): for category in categories: try: # Try to enable each category self.enableExclTestCategory(category) - except TypeError as error: + except TypeError: self.table['excl_test_categories'] = old_categories raise TypeError('each category must be one of TESTS integers') else: # if type of categories is not list or tuple diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index aff00eddf6..186d94bb92 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -308,7 +308,6 @@ class GLEmiter(object): if type(replace_auxdir) is not bool: raise TypeError('replace_auxdir must be a bool, not %s' % type(replace_auxdir).__name__) - auxdir = self.config['auxdir'] conddeps = self.config['conddeps'] macro_prefix = self.config['macro_prefix'] emit = '' @@ -742,7 +741,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [ witness_c_macro = self.config['witness_c_macro'] include_guard_prefix = self.config['include_guard_prefix'] module_indicator_prefix = self.config.getModuleIndicatorPrefix() - ac_version = self.config['ac_version'] destfile = os.path.normpath(destfile) emit = '' @@ -1030,29 +1028,23 @@ AC_DEFUN([%V1%_LIBSOURCES], [ sourcebase = self.config['sourcebase'] libname = self.config['libname'] m4base = self.config['m4base'] - pobase = self.config['pobase'] testsbase = self.config['testsbase'] gnu_make = self.config['gnu_make'] - makefile_name = self.config['makefile_name'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] - podomain = self.config['podomain'] conddeps = self.config['conddeps'] witness_c_macro = self.config['witness_c_macro'] include_guard_prefix = self.config['include_guard_prefix'] module_indicator_prefix = self.config.getModuleIndicatorPrefix() - ac_version = self.config['ac_version'] libtests = self.config['libtests'] single_configure = self.config['single_configure'] emit = '' if libtool: libext = 'la' - perhapsLT = 'LT' eliminate_LDFLAGS = False else: # if not libtool libext = 'a' - perhapsLT = '' eliminate_LDFLAGS = True if for_test: # When creating a package for testing: Attempt to provoke failures, diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index 10b5ad6d59..40e7c7615d 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -110,7 +110,7 @@ class GLFileSystem(object): tempFile = joinpath(self.config['tempdir'], name) try: # Try to create directories os.makedirs(os.path.dirname(tempFile)) - except OSError as error: + except OSError: pass # Skip errors if directory exists if isfile(tempFile): os.remove(tempFile) @@ -120,7 +120,7 @@ class GLFileSystem(object): command = 'patch -s "%s" < "%s" >&2' % (tempFile, diff_in_localdir) try: # Try to apply patch sp.check_call(command, shell=True) - except sp.CalledProcessError as error: + except sp.CalledProcessError: raise GLError(2, name) result = (tempFile, True) else: @@ -260,7 +260,7 @@ class GLFileAssistant(object): else: # Move instead of linking. try: # Try to move file movefile(tmpfile, joinpath(destdir, rewritten)) - except Exception as error: + except Exception: raise GLError(17, original) else: # if self.config['dryrun'] print('Copy file %s' % rewritten) @@ -299,7 +299,7 @@ class GLFileAssistant(object): os.remove(backuppath) try: # Try to replace the given file movefile(basepath, backuppath) - except Exception as error: + except Exception: raise GLError(17, original) if self.filesystem.shouldLink(original, lookedup) == CopyAction.Symlink \ and not tmpflag and filecmp.cmp(lookedup, tmpfile): @@ -313,7 +313,7 @@ class GLFileAssistant(object): if os.path.exists(basepath): os.remove(basepath) copyfile(tmpfile, joinpath(destdir, rewritten)) - except Exception as error: + except Exception: raise GLError(17, original) else: # if self.config['dryrun'] if already_present: @@ -337,14 +337,13 @@ class GLFileAssistant(object): xoriginal = substart('tests=lib/', 'lib/', original) lookedup, tmpflag = self.filesystem.lookup(xoriginal) tmpfile = self.tmpfilename(rewritten) - sed_transform_lib_file = self.transformers.get('lib') sed_transform_build_aux_file = self.transformers.get('aux') sed_transform_main_lib_file = self.transformers.get('main') sed_transform_testsrelated_lib_file = self.transformers.get('tests') try: # Try to copy lookedup file to tmpfile copyfile(lookedup, tmpfile) ensure_writable(tmpfile) - except Exception as error: + except Exception: raise GLError(15, lookedup) # Don't process binary files with sed. if not (original.endswith(".class") or original.endswith(".mo")): diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 0adfd8a73c..05ce82b7ac 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -381,7 +381,6 @@ class GLImport(object): '''Return command-line invocation comment.''' modules = self.config.getModules() avoids = self.config.getAvoids() - destdir = self.config.getDestDir() localpath = self.config.getLocalPath() auxdir = self.config.getAuxDir() sourcebase = self.config.getSourceBase() @@ -402,7 +401,6 @@ class GLImport(object): witness_c_macro = self.config.getWitnessCMacro() podomain = self.config.getPoDomain() vc_files = self.config.checkVCFiles() - verbose = self.config.getVerbosity() # Command-line invocation printed in a comment in generated gnulib-cache.m4. actioncmd = '# gnulib-tool --import' @@ -605,29 +603,17 @@ class GLImport(object): if type(gentests) is not bool: raise TypeError(f'gentests should be a bool, not {type(gentests).__name__}') emit = '' - assistant = self.assistant moduletable = self.moduletable - destdir = self.config['destdir'] auxdir = self.config['auxdir'] sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] - pobase = self.config['pobase'] - docbase = self.config['docbase'] testsbase = self.config['testsbase'] - lgpl = self.config['lgpl'] libname = self.config['libname'] - gnu_make = self.config['gnu_make'] - makefile_name = self.config['makefile_name'] - conddeps = self.config['conddeps'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] - podomain = self.config['podomain'] witness_c_macro = self.config['witness_c_macro'] configure_ac = self.config['configure_ac'] - vc_files = self.config['vc_files'] libtests = self.config['libtests'] - modules = [ str(module) - for module in moduletable['base'] ] emit += '# DO NOT EDIT! GENERATED AUTOMATICALLY!\n' emit += self.emitter.copyright_notice() emit += '''# @@ -820,24 +806,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix '''Make all preparations before the execution of the code. Returns filetable and sed transformers, which change the license.''' destdir = self.config['destdir'] - auxdir = self.config['auxdir'] modules = list(self.config['modules']) - sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] - pobase = self.config['pobase'] - docbase = self.config['docbase'] - testsbase = self.config['testsbase'] lgpl = self.config['lgpl'] - libname = self.config['libname'] - makefile_name = self.config['makefile_name'] - conddeps = self.config['conddeps'] - libtool = self.config['libtool'] - macro_prefix = self.config['macro_prefix'] - podomain = self.config['podomain'] - witness_c_macro = self.config['witness_c_macro'] - vc_files = self.config['vc_files'] - configure_ac = self.config['configure_ac'] - ac_version = self.config['ac_version'] verbose = self.config['verbosity'] base_modules = sorted(set([ self.modulesystem.find(m) for m in modules ])) @@ -895,7 +866,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Check license incompatibilities. listing = list() compatibilities = dict() - incompatibilities = '' compatibilities['all'] = ['GPLv2+ build tool', 'GPLed build tool', 'public domain', 'unlimited', 'unmodifiable license text'] @@ -1007,26 +977,18 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix raise KeyError('filetable must contain key %s' % repr(key)) destdir = self.config['destdir'] auxdir = self.config['auxdir'] - modules = list(self.config['modules']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] pobase = self.config['pobase'] docbase = self.config['docbase'] testsbase = self.config['testsbase'] - lgpl = self.config['lgpl'] libname = self.config['libname'] makefile_name = self.config['makefile_name'] tests_makefile_name = self.config['tests_makefile_name'] automake_subdir = self.config['automake_subdir'] - conddeps = self.config['conddeps'] - libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] - podomain = self.config['podomain'] - witness_c_macro = self.config['witness_c_macro'] vc_files = self.config['vc_files'] configure_ac = self.config['configure_ac'] - ac_version = self.config['ac_version'] - verbose = self.config['verbosity'] actioncmd = self.actioncmd() # Determine whether to put anything into $testsbase. @@ -1056,7 +1018,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if not self.config['dryrun']: try: # Try to create directory os.makedirs(directory) - except Exception as error: + except Exception: raise GLError(13, directory) else: # if self.config['dryrun'] print('Create directory %s' % directory) @@ -1081,7 +1043,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if os.path.exists(backup): os.remove(backup) movefile(path, '%s~' % path) - except Exception as error: + except Exception: raise GLError(14, file) else: # if self.config['dryrun'] print('Remove file %s (backup in %s~)' % (path, path)) @@ -1119,9 +1081,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix filetable['added'] += self.assistant.getFiles() filetable['added'] = sorted(set(filetable['added'])) - # Determine include_guard_prefix. - include_guard_prefix = self.config['include_guard_prefix'] - # Default the source makefile name to Makefile.am. if makefile_name: source_makefile_am = makefile_name @@ -1139,7 +1098,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Setup list of Makefile.am edits that are to be performed afterwards. # Some of these edits apply to files that we will generate; others are # under the responsibility of the developer. - makefile_am_edits = dict() if source_makefile_am == 'Makefile.am': sourcebase_dir = os.path.dirname(sourcebase) sourcebase_base = os.path.basename(sourcebase) diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index ff96e93999..4dd8dd6e35 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -120,7 +120,6 @@ class GLInfo(object): result = result.rstrip(os.linesep) return result # gnulib copy without versioning information. - first_changelog_line = None with codecs.open(os.path.join(DIRS['root'], 'ChangeLog'), 'rb', 'UTF-8') as file: line = file.readline() first_changelog_line = line.rstrip() diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index ba92d8a933..c0ea65676f 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -130,7 +130,6 @@ class GLModuleSystem(object): of os.walk() function and re module. However, it takes too much time to complete, so this version uses subprocess to run shell commands.''' result = '' - listing = list() localpath = self.config['localpath'] find_args = ['find', 'modules', '-type', 'f', '-print'] @@ -489,8 +488,7 @@ class GLModule(object): return self.sections.get('Files', '') def getFiles(self) -> list[str]: - '''Return list of files. - GLConfig: ac_version.''' + '''Return list of files.''' if 'files' not in self.cache: snippet = self.getFiles_Raw() result = [ line.strip() @@ -575,7 +573,7 @@ class GLModule(object): def getAutomakeSnippet(self) -> str: '''Get automake snippet. - GLConfig: auxdir, ac_version.''' + GLConfig: auxdir.''' result = '' conditional = self.getAutomakeSnippet_Conditional() if conditional.strip(): @@ -591,9 +589,8 @@ class GLModule(object): def getAutomakeSnippet_Unconditional(self) -> str: '''Return unconditional automake snippet. - GLConfig: auxdir, ac_version.''' + GLConfig: auxdir''' auxdir = self.config['auxdir'] - ac_version = self.config['ac_version'] result = '' if 'makefile-unconditional' not in self.cache: if self.getName().endswith('-tests'): @@ -1015,9 +1012,7 @@ class GLModuleTable(object): def add_dummy(self, modules: list[GLModule]) -> list[GLModule]: '''Add dummy package to list of modules if dummy package is needed. If not, return original list of modules. - GLConfig: auxdir, ac_version, conddeps.''' - auxdir = self.config['auxdir'] - ac_version = self.config['ac_version'] + GLConfig: conddeps.''' conddeps = self.config['conddeps'] for module in modules: if type(module) is not GLModule: @@ -1053,9 +1048,7 @@ class GLModuleTable(object): def filelist(self, modules: list[GLModule]) -> list[str]: '''Determine the final file list for the given list of modules. - The list of modules must already include dependencies. - GLConfig: ac_version.''' - ac_version = self.config['ac_version'] + The list of modules must already include dependencies.''' filelist = list() for module in modules: if type(module) is not GLModule: @@ -1074,7 +1067,6 @@ class GLModuleTable(object): files in lib/* go into $sourcebase/ if they are in the main file list but into $testsbase/ if they are in the tests-related file list. Furthermore lib/dummy.c can be in both.''' - ac_version = self.config['ac_version'] main_filelist = self.filelist(main_modules) tests_filelist = self.filelist(tests_modules) tests_filelist = [ file.replace('lib/', 'tests=lib/', 1) if file.startswith('lib/') else file diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index f0fe993c58..12fe486859 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -111,7 +111,7 @@ class GLTestDir(object): if not os.path.exists(self.testdir): try: # Try to create directory os.mkdir(self.testdir) - except Exception as error: + except Exception: raise GLError(19, self.testdir) self.emitter = GLEmiter(self.config) self.filesystem = GLFileSystem(self.config) @@ -172,14 +172,10 @@ class GLTestDir(object): auxdir = self.config['auxdir'] sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] - pobase = self.config['pobase'] - docbase = self.config['docbase'] testsbase = self.config['testsbase'] libname = self.config['libname'] libtool = self.config['libtool'] - witness_c_macro = self.config['witness_c_macro'] single_configure = self.config['single_configure'] - include_guard_prefix = self.config['include_guard_prefix'] macro_prefix = self.config['macro_prefix'] verbose = self.config['verbosity'] @@ -417,7 +413,6 @@ class GLTestDir(object): subdirs = [sourcebase, m4base] subdirs_with_configure_ac = list() - testsbase_append = False inctests = self.config.checkInclTestCategory(TESTS['tests']) if inctests: directory = joinpath(self.testdir, testsbase) @@ -540,7 +535,6 @@ class GLTestDir(object): subdirs_with_configure_ac += [testsbase] subdirs += [testsbase] - testsbase_append = True # Create Makefile.am. emit = '## Process this file with automake to produce Makefile.in.\n\n' @@ -905,7 +899,7 @@ class GLMegaTestDir(object): if not os.path.exists(self.megatestdir): try: # Try to create directory os.mkdir(self.megatestdir) - except Exception as error: + except Exception: raise GLError(19, self.megatestdir) self.emitter = GLEmiter(self.config) self.filesystem = GLFileSystem(self.config) @@ -1033,7 +1027,7 @@ class GLMegaTestDir(object): if not isdir('build-aux'): print('executing mkdir build-aux') os.mkdir('build-aux') - except Exception as error: + except Exception: pass args = [UTILS['autoconf']] constants.execute(args, verbose) diff --git a/pygnulib/main.py b/pygnulib/main.py index a57e5b04a3..c6a6bd3241 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -1100,7 +1100,7 @@ def main() -> None: sp.call([UTILS['make']]) sp.call([UTILS['make'], 'check']) sp.call([UTILS['make'], 'distclean']) - except Exception as error: + except Exception: sys.exit(1) args = ['find', '.', '-type', 'f', '-print'] remaining = sp.check_output(args).decode(ENCS['shell']) -- 2.34.1