>From 362f779b9df810f67c2f32afc0cd8c0707862a8a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 4 Aug 2022 21:53:51 +0200 Subject: [PATCH 8/9] gnulib-tool.py: Coding style: Revisit line breaks. * gnulib-tool.py: Avoid line breaks at arbitrary points inside expressions. Use line breaks to clarify [... for ...] iterations. * pygnulib/*.py: Likewise. --- ChangeLog | 5 ++ gnulib-tool.py | 75 ++++++++++------- pygnulib/GLConfig.py | 3 +- pygnulib/GLEmiter.py | 132 +++++++++++++----------------- pygnulib/GLFileSystem.py | 18 ++--- pygnulib/GLImport.py | 155 ++++++++++++++++++++---------------- pygnulib/GLMakefileTable.py | 17 ++-- pygnulib/GLModuleSystem.py | 138 +++++++++++++++++++------------- pygnulib/GLTestDir.py | 131 +++++++++++++++++++----------- pygnulib/constants.py | 19 +++-- 10 files changed, 388 insertions(+), 305 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad8777ff95..c290fc0123 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2022-08-04 Bruno Haible + gnulib-tool.py: Coding style: Revisit line breaks. + * gnulib-tool.py: Avoid line breaks at arbitrary points inside + expressions. Use line breaks to clarify [... for ...] iterations. + * pygnulib/*.py: Likewise. + gnulib-tool.py: Simplify boolean setters. * pygnulib/GLConfig.py (setLibtool): New method, replaces enableLibtool and disableLibtool. diff --git a/gnulib-tool.py b/gnulib-tool.py index 6ca3647604..21c6789ba9 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -23,6 +23,9 @@ # Like PEP 8 , except # - Line length is not limited to 79 characters. # - Line breaking before or after binary operators? Better before, like in GNU. +# - Place line breaks to help reading the code: +# Avoid line breaks inside expressions, if they can be avoided. +# Do use line breaks to separate the parts of [ ... for ... ] iterations. # You can use this command to check the style: # $ pycodestyle --max-line-length=136 --ignore=E265,W503,E241,E711,E712,E201,E202,E221 gnulib-tool.py pygnulib/*.py @@ -388,7 +391,7 @@ def main(): # Parse the given arguments. Don't signal an error if non-option arguments # occur between or after options. - (cmdargs, unhandled) = parser.parse_known_args() + cmdargs, unhandled = parser.parse_known_args() # Handle --help and --version, ignoring all other options. if cmdargs.help != None: @@ -437,7 +440,9 @@ def main(): cmdargs.mode_xmaintainer, cmdargs.mode_copy_file, ] - overflow = [arg for arg in args if arg != None] + overflow = [ arg + for arg in args + if arg != None ] if len(overflow) > 1: message = '%s: Unable to combine different modes of work.\n' % constants.APP['name'] message += 'Try \'gnulib-tool --help\' for more information.\n' @@ -740,16 +745,14 @@ def main(): else: # if not isfile(filepath) filepath = joinpath(destdir, 'aclocal.m4') if isfile(filepath): - pattern = constants.compiler( - r'm4_include\(\[(.*?)\]\)') + pattern = constants.compiler(r'm4_include\(\[(.*?)\]\)') with codecs.open(filepath, 'rb', 'UTF-8') as file: m4dirs = pattern.findall(file.read()) - m4dirs = [os.path.dirname(m4dir) for m4dir in m4dirs] - m4dirs = \ - [ # Begin filtering - m4dir for m4dir in m4dirs \ - if isfile(joinpath(destdir, m4dir, 'gnulib-cache.m4')) - ] # Finish filtering + m4dirs = [ os.path.dirname(m4dir) + for m4dir in m4dirs ] + m4dirs = [ m4dir + for m4dir in m4dirs + if isfile(joinpath(destdir, m4dir, 'gnulib-cache.m4')) ] m4dirs = sorted(set(m4dirs)) if len(m4dirs) == 0: # First use of gnulib in a package. @@ -833,8 +836,9 @@ def main(): sys.exit(1) args = ['find', '.', '-type', 'f', '-print'] remaining = sp.check_output(args).decode(ENCS['shell']) - lines = [line.strip() - for line in remaining.split('\n') if line.strip()] + lines = [ line.strip() + for line in remaining.split('\n') + if line.strip() ] remaining = ' '.join(lines) if remaining: message = 'Remaining files: %s\n' % remaining @@ -861,8 +865,9 @@ def main(): sp.call([UTILS['make'], 'distclean']) args = ['find', '.', '-type', 'f', '-print'] remaining = sp.check_output(args).decode(ENCS['shell']) - lines = [line.strip() - for line in remaining.split('\n') if line.strip()] + lines = [ line.strip() + for line in remaining.split('\n') + if line.strip() ] remaining = ' '.join(lines) if remaining: message = 'Remaining files: %s\n' % remaining @@ -874,38 +879,44 @@ def main(): elif mode == 'extract-description': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getDescription()) elif mode == 'extract-comment': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getComment()) elif mode == 'extract-status': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: status = module.getStatus() print('\n'.join(status)) elif mode == 'extract-notice': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getNotice()) elif mode == 'extract-applicability': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getApplicability()) elif mode == 'extract-filelist': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: files = module.getFiles() print('\n'.join(files)) @@ -919,7 +930,8 @@ def main(): sys.stderr.write(message) sys.exit(1) modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: dependencies = module.getDependencies() if dependencies: @@ -932,43 +944,50 @@ def main(): elif mode == 'extract-autoconf-snippet': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getAutoconfSnippet()) elif mode == 'extract-automake-snippet': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getAutomakeSnippet()) elif mode == 'extract-include-directive': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getInclude()) elif mode == 'extract-link-directive': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getLink()) elif mode == 'extract-license': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getLicense()) elif mode == 'extract-maintainer': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: print(module.getMaintainer()) elif mode == 'extract-tests-module': modulesystem = classes.GLModuleSystem(config) - modules = [modulesystem.find(module) for module in modules] + modules = [ modulesystem.find(module) + for module in modules ] for module in modules: if module.getTestsModule(): print(module.getTestsName()) diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 00bfbdf4fb..039b4f012d 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -386,7 +386,8 @@ class GLConfig(object): raise TypeError('localpath element must be a string, not %s' % type(dir).__name__) else: raise TypeError('localpath must be a list, not %s' % type(localpath).__name__) - self.table['localpath'] = [ remove_trailing_slashes(dir) for dir in localpath ] + self.table['localpath'] = [ remove_trailing_slashes(dir) + for dir in localpath ] def resetLocalPath(self): '''Reset a list of local override directories where to look up files diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 4e4ce4a053..c95d109423 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -153,7 +153,9 @@ class GLEmiter(object): snippet = module.getAutoconfSnippet() snippet = snippet.replace('${gl_include_guard_prefix}', include_guard_prefix) - lines = [line for line in snippet.split('\n') if line.strip()] + lines = [ line + for line in snippet.split('\n') + if line.strip() ] snippet = '%s\n' % '\n'.join(lines) transformer = fileassistant.transformers.get('aux', '') pattern = compiler('(^.*?$)', re.S | re.M) @@ -172,8 +174,8 @@ class GLEmiter(object): snippet = snippet.replace('gl_libdeps', 'gltests_libdeps') snippet = snippet.replace('gl_ltlibdeps', 'gltests_ltlibdeps') if disable_gettext: - snippet = snippet.replace('AM_GNU_GETTEXT([external])', 'dnl you must \ -add AM_GNU_GETTEXT([external]) or similar to configure.ac.') + snippet = snippet.replace('AM_GNU_GETTEXT([external])', + 'dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac.') else: # Don't indent AM_GNU_GETTEXT_VERSION line, as that confuses # autopoint through at least GNU gettext version 0.18.2. @@ -181,8 +183,7 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') emit += snippet if str(module) == 'alloca' and libtool and not disable_libtool: emit += 'changequote(,)dnl\n' - emit += "LTALLOCA=`echo \"$ALLOCA\" | sed -e 's/\\.[^.]* /.lo \ -/g;s/\\.[^.]*$/.lo/'`\n" + emit += "LTALLOCA=`echo \"$ALLOCA\" | sed -e 's/\\.[^.]* /.lo /g;s/\\.[^.]*$/.lo/'`\n" emit += 'changequote([, ])dnl\n' emit += 'AC_SUBST([LTALLOCA])' if replace_auxdir: @@ -190,7 +191,9 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') repl = 'AC_CONFIG_FILES([\\1:%s/\\2])' % auxdir pattern = compiler(regex, re.S | re.M) emit = pattern.sub(repl, emit) - lines = [line for line in emit.split('\n') if line.strip()] + lines = [ line + for line in emit.split('\n') + if line.strip() ] emit = '%s\n' % '\n'.join(lines) emit = constants.nlconvert(emit) return emit @@ -312,15 +315,16 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') disable_libtool, disable_gettext, replace_auxdir, ' ') emit += ' %s=true\n' % shellvar dependencies = module.getDependencies() - depmodules = [pair[0] for pair in dependencies] + depmodules = [ pair[0] + for pair in dependencies ] # Intersect dependencies with the modules list. - depmodules = [ - dep for dep in depmodules if dep in modules] + depmodules = [ dep + for dep in depmodules + if dep in modules ] for depmodule in depmodules: if moduletable.isConditional(depmodule): shellfunc = depmodule.getShellFunc() - condition = moduletable.getCondition( - module, depmodule) + condition = moduletable.getCondition(module, depmodule) if condition != None: emit += ' if %s; then\n' % condition emit += ' %s\n' % shellfunc @@ -344,9 +348,10 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') if solution: condname = module.getConditionalName() shellvar = module.getShellVar() - emit += ' AM_CONDITIONAL([%s], [$%s])\n' % ( - condname, shellvar) - lines = [line for line in emit.split('\n') if line.strip()] + emit += ' AM_CONDITIONAL([%s], [$%s])\n' % (condname, shellvar) + lines = [ line + for line in emit.split('\n') + if line.strip() ] emit = '%s\n' % '\n'.join(lines) emit = constants.nlconvert(emit) return emit @@ -403,10 +408,8 @@ add AM_GNU_GETTEXT([external]) or similar to configure.ac.') XGETTEXT_OPTIONS = \\ --keyword=_ --flag=_:1:pass-c-format \\ --keyword=N_ --flag=N_:1:pass-c-format \\ - --keyword='proper_name:1,"This is a proper name. See the gettext manual, \ -section Names."' \\ - --keyword='proper_name_utf8:1,"This is a proper name. See the gettext \ -manual, section Names."' \\ + --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \\ + --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \\ --flag=error:3:c-format --flag=error_at_line:5:c-format # This is the copyright holder that gets inserted into the header of the @@ -448,8 +451,11 @@ USE_MSGCTXT = no\n""" emit = '' sourcebase = self.config['sourcebase'] sourcebase = '%s%s' % (self.sourcebase, os.path.sep) - files = [substart('lib/', sourcebase, file) for file in files] - files = [file for file in files if file.startswith(sourcebase)] + files = [ substart('lib/', sourcebase, file) + for file in files ] + files = [ file + for file in files + if file.startswith(sourcebase) ] emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n" emit += "%s\n" % self.copyright_notice() emit += "# List of files which contain translatable strings.\n" @@ -526,8 +532,7 @@ USE_MSGCTXT = no\n""" fi done])dnl m4_if(m4_sysval, [0], [], - [AC_FATAL([expected source file, required through AC_LIBSOURCES, not \ -found])]) + [AC_FATAL([expected source file, required through AC_LIBSOURCES, not found])]) ]) m4_popdef([GL_MODULE_INDICATOR_PREFIX]) m4_popdef([GL_MACRO_PREFIX]) @@ -542,8 +547,7 @@ found])]) if test -n "$%V1%_LIBOBJS"; then # Remove the extension. sed_drop_objext='s/\.o$//;s/\.obj$//' - for i in `for i in $%V1%_LIBOBJS; do echo "$i"; done | sed -e \ -"$sed_drop_objext" | sort | uniq`; do + for i in `for i in $%V1%_LIBOBJS; do echo "$i"; done | sed -e "$sed_drop_objext" | sort | uniq`; do %V1%_libobjs="$%V1%_libobjs $i.$ac_objext" %V1%_ltlibobjs="$%V1%_ltlibobjs $i.lo" done @@ -687,42 +691,34 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if not module.isTests(): # Get conditional snippet, edit it and save to amsnippet1. amsnippet1 = module.getAutomakeSnippet_Conditional() - amsnippet1 = amsnippet1.replace( - 'lib_LIBRARIES', 'lib%_LIBRARIES') - amsnippet1 = amsnippet1.replace( - 'lib_LTLIBRARIES', 'lib%_LTLIBRARIES') + amsnippet1 = amsnippet1.replace('lib_LIBRARIES', 'lib%_LIBRARIES') + amsnippet1 = amsnippet1.replace('lib_LTLIBRARIES', 'lib%_LTLIBRARIES') if LD_flags: - pattern = compiler( - 'lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M) + pattern = compiler('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M) amsnippet1 = pattern.sub('', amsnippet1) pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M) amsnippet1 = pattern.sub('%s_%s_\\1' % (libname, libext), amsnippet1) - amsnippet1 = amsnippet1.replace( - '$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') - amsnippet1 = amsnippet1.replace( - 'lib%_LIBRARIES', 'lib_LIBRARIES') - amsnippet1 = amsnippet1.replace( - 'lib%_LTLIBRARIES', 'lib_LTLIBRARIES') + amsnippet1 = amsnippet1.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') + amsnippet1 = amsnippet1.replace('lib%_LIBRARIES', 'lib_LIBRARIES') + amsnippet1 = amsnippet1.replace('lib%_LTLIBRARIES', 'lib_LTLIBRARIES') if check_PROGRAMS: - amsnippet1 = amsnippet1.replace( - 'check_PROGRAMS', 'noinst_PROGRAMS') + amsnippet1 = amsnippet1.replace('check_PROGRAMS', 'noinst_PROGRAMS') amsnippet1 = amsnippet1.replace('${gl_include_guard_prefix}', include_guard_prefix) if str(module) == 'alloca': amsnippet1 += '%s_%s_LIBADD += @%sALLOCA@\n' % (libname, libext, perhapsLT) amsnippet1 += '%s_%s_DEPENDENCIES += @%sALLOCA@\n' % (libname, libext, perhapsLT) - amsnippet1 = constants.combine_lines_matching( - compiler('%s_%s_SOURCES' % (libname, libext)), - amsnippet1) + amsnippet1 = constants.combine_lines_matching(compiler('%s_%s_SOURCES' % (libname, libext)), + amsnippet1) # Get unconditional snippet, edit it and save to amsnippet2. amsnippet2 = module.getAutomakeSnippet_Unconditional() pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M) amsnippet2 = pattern.sub('%s_%s_\\1' % (libname, libext), amsnippet2) - amsnippet2 = amsnippet2.replace( - '$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') + amsnippet2 = amsnippet2.replace('$(GNULIB_', + '$(' + module_indicator_prefix + '_GNULIB_') if not (amsnippet1 + amsnippet2).isspace(): allsnippets += '## begin gnulib module %s\n' % str(module) if conddeps: @@ -733,13 +729,12 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if conddeps: allsnippets += 'endif\n' allsnippets += amsnippet2 - allsnippets += '## end gnulib module %s\n\n' % str( - module) + allsnippets += '## end gnulib module %s\n\n' % str(module) # Test whether there are some source files in subdirectories. for file in module.getFiles(): - if file.startswith('lib/') and file.endswith('.c') and \ - file.count('/') > 1: + if (file.startswith('lib/') and file.endswith('.c') + and file.count('/') > 1): uses_subdirs = True break if not makefile: @@ -964,22 +959,17 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if flag: snippet = module.getAutomakeSnippet() snippet = snippet.replace('lib_LIBRARIES', 'lib%_LIBRARIES') - snippet = snippet.replace( - 'lib_LTLIBRARIES', 'lib%_LTLIBRARIES') + snippet = snippet.replace('lib_LTLIBRARIES', 'lib%_LTLIBRARIES') if LD_flags: - pattern = compiler( - 'lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M) + pattern = compiler('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M) snippet = pattern.sub('', snippet) pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M) snippet = pattern.sub('libtests_a_\\1', snippet) - snippet = snippet.replace( - '$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') + snippet = snippet.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') snippet = snippet.replace('lib%_LIBRARIES', 'lib_LIBRARIES') - snippet = snippet.replace( - 'lib%_LTLIBRARIES', 'lib_LTLIBRARIES') + snippet = snippet.replace('lib%_LTLIBRARIES', 'lib_LTLIBRARIES') if check_PROGRAMS: - snippet = snippet.replace( - 'check_PROGRAMS', 'noinst_PROGRAMS') + snippet = snippet.replace('check_PROGRAMS', 'noinst_PROGRAMS') snippet = snippet.replace('${gl_include_guard_prefix}', include_guard_prefix) # Check if module is 'alloca'. @@ -997,26 +987,20 @@ AC_DEFUN([%V1%_LIBSOURCES], [ islongrun = True break if not islongrun: - snippet = snippet.replace( - '\n\nEXTRA_DIST', '\nEXTRA_DIST') - main_snippets += '## begin gnulib module %s\n' % str( - module) + snippet = snippet.replace('\n\nEXTRA_DIST', '\nEXTRA_DIST') + main_snippets += '## begin gnulib module %s\n' % str(module) main_snippets += snippet - main_snippets += '## end gnulib module %s\n\n' % str( - module) + main_snippets += '## end gnulib module %s\n\n' % str(module) else: # if islongrunning - snippet = snippet.replace( - '\n\nEXTRA_DIST', '\nEXTRA_DIST') - longrun_snippets += '## begin gnulib module %s\n' % str( - module) + snippet = snippet.replace('\n\nEXTRA_DIST', '\nEXTRA_DIST') + longrun_snippets += '## begin gnulib module %s\n' % str(module) longrun_snippets += snippet - longrun_snippets += '## end gnulib module %s\n' % str( - module) + longrun_snippets += '## end gnulib module %s\n' % str(module) # Test whether there are some source files in subdirectories. for file in module.getFiles(): - if file.startswith('lib/') and file.endswith('.c') and \ - file.count('/') > 1: + if (file.startswith('lib/') and file.endswith('.c') + and file.count('/') > 1): uses_subdirs = True break @@ -1028,8 +1012,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ subdir_options = ' subdir-objects' emit += 'AUTOMAKE_OPTIONS = 1.9.6 foreign%s\n\n' % subdir_options if for_test and not single_configure: - emit += 'ACLOCAL_AMFLAGS = -I %s/%s\n\n' % ( - testsbase_inverse, m4base) + emit += 'ACLOCAL_AMFLAGS = -I %s/%s\n\n' % (testsbase_inverse, m4base) # Nothing is being added to SUBDIRS; nevertheless the existence of this # variable is needed to avoid an error from automake: @@ -1056,8 +1039,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ # * https://debbugs.gnu.org/11030 # So we need this workaround. pattern = compiler('^pkgdata_DATA *\\+=', re.S | re.M) - if bool(pattern.findall(main_snippets)) or \ - bool(pattern.findall(longrun_snippets)): + if bool(pattern.findall(main_snippets)) or bool(pattern.findall(longrun_snippets)): emit += 'pkgdata_DATA =\n' emit += 'EXTRA_DIST =\n' diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index a1d1520f7c..7bec0f9e6e 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -191,8 +191,8 @@ class GLFileAssistant(object): Return the name of a temporary file (file is relative to destdir).''' if type(path) is not str: - raise TypeError( - 'path must be a string, not %s' % (type(path).__name__)) + raise TypeError('path must be a string, not %s' + % (type(path).__name__)) if not self.config['dryrun']: # Put the new contents of $file in a file in the same directory (needed # to guarantee that an 'mv' to "$destdir/$file" works). @@ -215,8 +215,8 @@ class GLFileAssistant(object): Set the name of the original file which will be used.''' if type(original) is not str: - raise TypeError( - 'original must be a string, not %s' % (type(original).__name__)) + raise TypeError('original must be a string, not %s' + % (type(original).__name__)) self.original = original def setRewritten(self, rewritten): @@ -224,8 +224,8 @@ class GLFileAssistant(object): Set the name of the rewritten file which will be used.''' if type(rewritten) is not str: - raise TypeError( - 'rewritten must be a string, not %s' % type(rewritten).__name__) + raise TypeError('rewritten must be a string, not %s' + % type(rewritten).__name__) self.rewritten = rewritten def addFile(self, file): @@ -263,8 +263,7 @@ class GLFileAssistant(object): print('Copying file %s' % rewritten) if self.filesystem.shouldLink(original, lookedup) == CopyAction.Symlink \ and not tmpflag and filecmp.cmp(lookedup, tmpfile): - constants.link_if_changed( - lookedup, joinpath(destdir, rewritten)) + constants.link_if_changed(lookedup, joinpath(destdir, rewritten)) else: # if any of these conditions is not met try: # Try to move file movefile(tmpfile, joinpath(destdir, rewritten)) @@ -348,8 +347,7 @@ class GLFileAssistant(object): 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', '') + sed_transform_testsrelated_lib_file = self.transformers.get('tests', '') try: # Try to copy lookedup file to tmpfile copyfile(lookedup, tmpfile) except Exception as error: diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 68965d6841..1d014d68d2 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -78,8 +78,7 @@ class GLImport(object): if type(config) is not GLConfig: raise TypeError('config must have GLConfig type, not %s' % repr(config)) - if type(mode) is int and \ - MODES['import'] <= mode <= MODES['update']: + if type(mode) is int and MODES['import'] <= mode <= MODES['update']: self.mode = mode else: # if mode is not int or is not 0-3 raise TypeError('mode must be 0 <= mode <= 3, not %s' @@ -114,7 +113,8 @@ class GLImport(object): pattern = compiler(r'.*AC_PREREQ\((.*?)\)', re.S | re.M) versions = cleaner(pattern.findall(data)) if versions: - version = sorted(set([float(version) for version in versions]))[-1] + version = sorted(set([ float(version) + for version in versions ]))[-1] self.config.setAutoconfVersion(version) if version < 2.59: raise GLError(4, version) @@ -171,7 +171,8 @@ class GLImport(object): data = data.replace('gl_WITH_ALL_TESTS', '') # Find string values result = dict(pattern.findall(data)) - values = cleaner([result.get(key, '') for key in keys]) + values = cleaner([ result.get(key, '') + for key in keys ]) tempdict = dict(zip(keys, values)) if 'gl_LGPL' in tempdict: lgpl = cleaner(tempdict['gl_LGPL']) @@ -204,8 +205,7 @@ class GLImport(object): if tempdict['gl_PO_DOMAIN']: self.cache.setPoDomain(cleaner(tempdict['gl_PO_DOMAIN'])) if tempdict['gl_WITNESS_C_MACRO']: - self.cache.setWitnessCMacro( - cleaner(tempdict['gl_WITNESS_C_MACRO'])) + self.cache.setWitnessCMacro(cleaner(tempdict['gl_WITNESS_C_MACRO'])) # Get cached filelist from gnulib-comp.m4. destdir, m4base = self.config.getDestDir(), self.config.getM4Base() @@ -227,8 +227,7 @@ class GLImport(object): self.config.setLocalPath(localpath) if self.mode != MODES['import']: - if self.cache['m4base'] and \ - (self.config['m4base'] != self.cache['m4base']): + if self.cache['m4base'] and (self.config['m4base'] != self.cache['m4base']): raise GLError(5, m4base) # Perform actions with modules. In --add-import, append each given module @@ -239,7 +238,9 @@ class GLImport(object): if self.mode == MODES['add-import']: modules = sorted(set(new + old)) elif self.mode == MODES['remove-import']: - modules = [module for module in old if module in new] + modules = [ module + for module in old + if module in new ] elif self.mode == MODES['update']: modules = self.cache.getModules() @@ -280,13 +281,14 @@ class GLImport(object): Replace auxdir, docbase, sourcebase, m4base and testsbase from default to their version from cached config.''' if type(files) is not list: - raise TypeError( - 'files argument must has list type, not %s' % type(files).__name__) + raise TypeError('files argument must has list type, not %s' + % type(files).__name__) for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') files = sorted(set(files)) - files = ['%s%s' % (file, os.path.sep) for file in files] + files = [ '%s%s' % (file, os.path.sep) + for file in files ] auxdir = self.cache['auxdir'] docbase = self.cache['docbase'] sourcebase = self.cache['sourcebase'] @@ -305,8 +307,7 @@ class GLImport(object): elif file.startswith('tests/'): path = constants.substart('tests/', '%s/' % testsbase, file) elif file.startswith('tests=lib/'): - path = constants.substart( - 'tests=lib/', '%s/' % testsbase, file) + path = constants.substart('tests=lib/', '%s/' % testsbase, file) elif file.startswith('top/'): path = constants.substart('top/', '', file) else: # file is not a special file @@ -321,8 +322,8 @@ class GLImport(object): Replace auxdir, docbase, sourcebase, m4base and testsbase from default to their version from config.''' if type(files) is not list: - raise TypeError( - 'files argument must has list type, not %s' % type(files).__name__) + raise TypeError('files argument must has list type, not %s' + % type(files).__name__) for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') @@ -345,8 +346,7 @@ class GLImport(object): elif file.startswith('tests/'): path = constants.substart('tests/', '%s/' % testsbase, file) elif file.startswith('tests=lib/'): - path = constants.substart( - 'tests=lib/', '%s/' % testsbase, file) + path = constants.substart('tests=lib/', '%s/' % testsbase, file) elif file.startswith('top/'): path = constants.substart('top/', '', file) else: # file is not a special file @@ -492,7 +492,8 @@ class GLImport(object): podomain = self.config['podomain'] witness_c_macro = self.config['witness_c_macro'] vc_files = self.config['vc_files'] - modules = [str(module) for module in moduletable['base']] + modules = [ str(module) + for module in moduletable['base'] ] avoids = self.config['avoids'] emit += self.emiter.copyright_notice() emit += '''# @@ -576,7 +577,8 @@ class GLImport(object): configure_ac = self.config['configure_ac'] vc_files = self.config['vc_files'] libtests = self.config['libtests'] - modules = [str(module) for module in moduletable['base']] + modules = [ str(module) + for module in moduletable['base'] ] emit += '# DO NOT EDIT! GENERATED AUTOMATICALLY!\n' emit += self.emiter.copyright_notice() emit += '''# @@ -601,8 +603,8 @@ AC_DEFUN([%s_EARLY], for module in moduletable['main']: # Test whether there are some source files in subdirectories. for file in module.getFiles(): - if file.startswith('lib/') and file.endswith('.c') and \ - file.count('/') > 1: + if (file.startswith('lib/') and file.endswith('.c') + and file.count('/') > 1): uses_subdirs = True break if uses_subdirs: @@ -610,8 +612,9 @@ AC_DEFUN([%s_EARLY], for module in moduletable['final']: emit += ' # Code from module %s:\n' % str(module) snippet = module.getAutoconfSnippet_Early() - lines = [line for line in snippet.split( - constants.NL) if line != ''] + lines = [ line + for line in snippet.split(constants.NL) + if line != '' ] if lines: emit += ' %s\n' % '\n '.join(lines) emit += '])\n' @@ -653,9 +656,7 @@ AC_DEFUN([%s_INIT], # See . emit += 'changequote(,)dnl\n' emit += ' %stests_WITNESS=' % macro_prefix - emit += 'IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr \ -abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e \ -\'s/[^A-Z0-9_]/_/g\'`_GNULIB_TESTS\n' + emit += 'IN_`echo "${PACKAGE-$PACKAGE_TARNAME}" | LC_ALL=C tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | LC_ALL=C sed -e \'s/[^A-Z0-9_]/_/g\'`_GNULIB_TESTS\n' emit += 'changequote([, ])dnl\n' emit += ' AC_SUBST([%stests_WITNESS])\n' % macro_prefix emit += ' gl_module_indicator_condition=$%stests_WITNESS\n' % macro_prefix @@ -694,13 +695,13 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix This method is used to determine ignore argument for _update_ignorelist_ method and then call it.''' destdir = self.config['destdir'] - if isdir(joinpath(destdir, 'CVS')) or \ - isdir(joinpath(destdir, directory, 'CVS')) or \ - isfile(joinpath(destdir, directory, '.cvsignore')): + if (isdir(joinpath(destdir, 'CVS')) + or isdir(joinpath(destdir, directory, 'CVS')) + or isfile(joinpath(destdir, directory, '.cvsignore'))): self._update_ignorelist_(directory, '.cvsignore', dirs_added, dirs_removed) - if isdir(joinpath(destdir, '.git')) or \ - isfile(joinpath(destdir, directory, '.gitignore')): + if (isdir(joinpath(destdir, '.git')) + or isfile(joinpath(destdir, directory, '.gitignore'))): self._update_ignorelist_(directory, '.gitignore', dirs_added, dirs_removed) @@ -721,11 +722,18 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix with codecs.open(srcpath, 'rb', 'UTF-8') as file: srcdata = file.read() dirs_ignore = sorted(set(srcdata.split('\n'))) - dirs_ignore = [line for line in dirs_ignore if line.strip()] + dirs_ignore = [ line + for line in dirs_ignore + if line.strip() ] srcdata = '\n'.join(sorted(set(dirs_ignore))).strip() - dirs_ignore += [d for d in dirs_added if d not in dirs_ignore] - dirs_ignore = [d for d in dirs_ignore if d in dirs_removed] - dirs_ignore = ['%s%s' % (anchor, d) for d in dirs_ignore] + dirs_ignore += [ d + for d in dirs_added + if d not in dirs_ignore ] + dirs_ignore = [ d + for d in dirs_ignore + if d in dirs_removed ] + dirs_ignore = [ '%s%s' % (anchor, d) + for d in dirs_ignore ] dirs_ignore = sorted(set(dirs_ignore)) destdata = '\n'.join(sorted(set(dirs_ignore))).strip() if srcdata != destdata: @@ -742,7 +750,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if not self.config['dryrun']: print('Creating %s' % srcpath) dirs_added = sorted(set(dirs_added)) - dirs_added = ['%s%s' % (anchor, d) for d in dirs_added] + dirs_added = [ '%s%s' % (anchor, d) + for d in dirs_added ] if ignore == '.cvsignore': dirs_added = ['.deps', '.dirstamp'] + dirs_added with codecs.open(srcpath, 'wb', 'UTF-8') as file: @@ -775,8 +784,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix 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])) + base_modules = sorted(set([ self.modulesystem.find(m) + for m in modules ])) # Perform transitive closure. final_modules = self.moduletable.transitive_closure(base_modules) @@ -797,8 +806,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix print(' %s' % module) # Separate modules into main_modules and tests_modules. - modules = self.moduletable.transitive_closure_separately( - base_modules, final_modules) + modules = \ + self.moduletable.transitive_closure_separately(base_modules, final_modules) main_modules, tests_modules = modules # Transmit base_modules, final_modules, main_modules and tests_modules. @@ -873,7 +882,8 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix s/Library General Public License/General Public License/g s/version 2\\(.1\\)\\{0,1\\}\\([ ,]\\)/version 3\\2/g''' sed_transform_lib_file = '' - if 'config-h' in [str(module) for module in main_modules]: + if 'config-h' in [ str(module) + for module in main_modules ]: sed_transform_lib_file += ''' s/^#ifdef[\t ]*HAVE_CONFIG_H[\t ]*$/#if 1/ ''' @@ -926,8 +936,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Determine the final file lists. main_filelist, tests_filelist = \ self.moduletable.filelist_separately(main_modules, tests_modules) - filelist = sorted( - set(main_filelist + tests_filelist), key=str.lower) + filelist = sorted(set(main_filelist + tests_filelist), key=str.lower) if not filelist: raise GLError(12, None) @@ -1017,11 +1026,15 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix dirs = list() if pobase: dirs += [pobase] - if [file for file in filetable['all'] if file.startswith('doc/')]: + if [ file + for file in filetable['all'] + if file.startswith('doc/') ]: dirs += [docbase] dirs += [sourcebase, m4base, auxdir] - dirs += [os.path.dirname(pair[0]) for pair in filetable['new']] - dirs = sorted(set([joinpath(destdir, d) for d in dirs])) + dirs += [ os.path.dirname(pair[0]) + for pair in filetable['new'] ] + dirs = sorted(set([ joinpath(destdir, d) + for d in dirs ])) for directory in dirs: if not isdir(directory): print('Creating directory %s' % directory) @@ -1038,7 +1051,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Files which are in filetable['old'] and not in filetable['new']. # They will be removed and added to filetable['removed'] list. - pairs = [f for f in filetable['old'] if f not in filetable['old']] + pairs = [ f + for f in filetable['old'] + if f not in filetable['old'] ] pairs = sorted(set(pairs), key=lambda t: tuple(t[0].lower())) files = sorted(set(pair[0] for pair in pairs)) for file in files: @@ -1060,7 +1075,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Files which are in filetable['new'] and not in filetable['old']. # They will be added/updated and added to filetable['added'] list. already_present = False - pairs = [f for f in filetable['new'] if f not in filetable['old']] + pairs = [ f + for f in filetable['new'] + if f not in filetable['old'] ] pairs = sorted(set(pairs)) for pair in pairs: original = pair[1] @@ -1072,7 +1089,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Files which are in filetable['new'] and in filetable['old']. # They will be added/updated and added to filetable['added'] list. already_present = True - pairs = [f for f in filetable['new'] if f in filetable['old']] + pairs = [ f + for f in filetable['new'] + if f in filetable['old'] ] pairs = sorted(set(pairs)) for pair in pairs: original = pair[1] @@ -1104,8 +1123,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if makefile_am == 'Makefile.am': sourcebase_dir = os.path.dirname(sourcebase) sourcebase_base = os.path.basename(sourcebase) - self.makefiletable.editor( - sourcebase_dir, 'SUBDIRS', sourcebase_base) + self.makefiletable.editor(sourcebase_dir, 'SUBDIRS', sourcebase_base) if pobase: pobase_dir = os.path.dirname(pobase) pobase_base = os.path.basename(pobase) @@ -1114,8 +1132,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if makefile_am == 'Makefile.am': testsbase_dir = os.path.dirname(testsbase) testsbase_base = os.path.basename(testsbase) - self.makefiletable.editor( - testsbase_dir, 'SUBDIRS', testsbase_base) + self.makefiletable.editor(testsbase_dir, 'SUBDIRS', testsbase_base) self.makefiletable.editor('', 'ACLOCAL_AMFLAGS', '-I %s' % m4base) self.makefiletable.parent() @@ -1152,8 +1169,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix lookedup, flag = filesystem.lookup(path) movefile(lookedup, tmpfile) basename = joinpath(pobase, file) - filename, backup, flag = self.assistant.super_update( - basename, tmpfile) + filename, backup, flag = self.assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: print('Updating %s (backup in %s)' % (filename, backup)) @@ -1174,8 +1190,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix emit = self.emiter.po_Makevars() with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(emit) - filename, backup, flag = self.assistant.super_update( - basename, tmpfile) + filename, backup, flag = self.assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: print('Updating %s (backup in %s)' % (filename, backup)) @@ -1196,8 +1211,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(self.emiter.po_POTFILES_in(filetable['all'])) basename = joinpath(pobase, 'POTFILES.in') - filename, backup, flag = self.assistant.super_update( - basename, tmpfile) + filename, backup, flag = self.assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: print('Updating %s (backup in %s)' % (filename, backup)) @@ -1233,8 +1247,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix data += '\n'.join(files) with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(data) - filename, backup, flag = self.assistant.super_update( - basename, tmpfile) + filename, backup, flag = self.assistant.super_update(basename, tmpfile) if flag == 1: print('Updating %s (backup in %s)' % (filename, backup)) elif flag == 2: @@ -1309,8 +1322,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix actioncmd, for_test) with codecs.open(tmpfile, 'wb', 'UTF-8') as file: file.write(emit) - filename, backup, flag = self.assistant.super_update( - basename, tmpfile) + filename, backup, flag = self.assistant.super_update(basename, tmpfile) if flag == 1: if not self.config['dryrun']: print('Updating %s (backup in %s)' % (filename, backup)) @@ -1356,10 +1368,10 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix # Finish the work. print('Finished.\n') - print('You may need to add #include directives \ -for the following .h files.') - modules = sorted(set([module for module in self.moduletable['base'] - if module in self.moduletable['main']])) + print('You may need to add #include directives for the following .h files.') + modules = sorted(set([ module + for module in self.moduletable['base'] + if module in self.moduletable['main'] ])) # 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. @@ -1380,12 +1392,15 @@ for the following .h files.') includes_angles = sorted(set(includes_angles)) includes_quotes = sorted(set(includes_quotes)) includes = includes_angles + includes_quotes + includes_if - includes = [include for include in includes if include.split()] + includes = [ include + for include in includes + if include.split() ] for include in includes: print(' %s' % include) # Get link directives. - links = [module.getLink() for module in self.moduletable['main']] + links = [ module.getLink() + for module in self.moduletable['main'] ] ulinks = list() for link in links: for lib in link: diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index f3a8b9cccf..c4fb6d195a 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -74,14 +74,11 @@ class GLMakefileTable(object): This method is used to remember that ${dir}Makefile.am needs to be edited to that ${var} mentions ${val}.''' if type(dir) is not str: - raise TypeError( - 'dir must be a string, not %s' % (type(dir).__name__)) + raise TypeError('dir must be a string, not %s' % (type(dir).__name__)) if type(var) is not str: - raise TypeError( - 'var must be a string, not %s' % (type(var).__name__)) + raise TypeError('var must be a string, not %s' % (type(var).__name__)) if type(val) is not str: - raise TypeError( - 'val must be a string, not %s' % (type(val).__name__)) + raise TypeError('val must be a string, not %s' % (type(val).__name__)) dictionary = {'dir': dir, 'var': var, 'val': val} self.table += [dictionary] @@ -104,10 +101,10 @@ class GLMakefileTable(object): else: # if makefile mfx = makefile dir2 = '' - while dir1 and \ - (joinpath(self.config['destdir'], dir1, mfd) - or joinpath(dir1, mfd) == joinpath(sourcebase, mfx) - or (inctests and joinpath(dir1, mfd) == joinpath(testsbase, mfx))): + while (dir1 + and (joinpath(self.config['destdir'], dir1, mfd) + or joinpath(dir1, mfd) == joinpath(sourcebase, mfx) + or (inctests and joinpath(dir1, mfd) == joinpath(testsbase, mfx)))): dir2 = joinpath(os.path.basename(dir1), dir2) dir1 = os.path.dirname(dir1) self.editor(dir1, 'EXTRA_DIST', joinpath(dir2, 'gnulib-cache.m4')) diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 9c8e2eb266..eb5b544594 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -80,8 +80,8 @@ class GLModuleSystem(object): Check whether the given module exists. GLConfig: localpath.''' if type(module) is not str: - raise TypeError( - 'module must be a string, not %s' % type(module).__name__) + raise TypeError('module must be a string, not %s' + % type(module).__name__) localpath = self.config['localpath'] result = False badnames = ['ChangeLog', 'COPYING', 'README', 'TEMPLATE', @@ -90,8 +90,8 @@ class GLModuleSystem(object): result = isfile(joinpath(DIRS['modules'], module)) if not result: for localdir in localpath: - if isdir(joinpath(localdir, 'modules')) \ - and isfile(joinpath(localdir, 'modules', module)): + if (isdir(joinpath(localdir, 'modules')) + and isfile(joinpath(localdir, 'modules', module))): result = True break return result @@ -101,8 +101,8 @@ class GLModuleSystem(object): Find the given module.''' if type(module) is not str: - raise TypeError( - 'module must be a string, not %s' % type(module).__name__) + raise TypeError('module must be a string, not %s' + % type(module).__name__) if self.exists(module): path, istemp = self.filesystem.lookup(joinpath('modules', module)) result = GLModule(self.config, path, istemp) @@ -168,7 +168,9 @@ class GLModuleSystem(object): result = sed.stdout.read().decode("UTF-8") stdin.close() os.remove(path) - listing = [line for line in result.split('\n') if line.strip()] + listing = [ line + for line in result.split('\n') + if line.strip() ] listing = sorted(set(listing)) return listing @@ -363,11 +365,9 @@ Include:|Link:|License:|Maintainer:)' Return the automake conditional name. GLConfig: macro_prefix.''' macro_prefix = self.config['macro_prefix'] - nonascii = \ - [ # Begin to filter non-ascii chars - char for char in self.getName() if char not in \ - 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' - ] # Finish to filter non-ascii chars + nonascii = [ char + for char in self.getName() + if char not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' ] if nonascii: name = self.getName().encode(ENCS['default']) name = hashlib.md5(name).hexdigest() @@ -429,7 +429,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -440,7 +441,9 @@ Include:|Link:|License:|Maintainer:)' if findflag: break parts += [line] - result = [part.strip() for part in parts if part.strip()] + result = [ part.strip() + for part in parts + if part.strip() ] self.cache['status'] = list(result) return list(self.cache['status']) @@ -455,7 +458,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -481,7 +485,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -492,7 +497,8 @@ Include:|Link:|License:|Maintainer:)' if findflag: break parts += [line] - parts = [part.strip() for part in parts] + parts = [ part.strip() + for part in parts ] result = ''.join(parts) if not result.strip(): if self.getName().endswith('-tests'): @@ -517,7 +523,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -528,7 +535,9 @@ Include:|Link:|License:|Maintainer:)' if findflag: break parts += [line] - result = [part.strip() for part in parts if part.strip()] + result = [ part.strip() + for part in parts + if part.strip() ] result += [joinpath('m4', '00gnulib.m4')] result += [joinpath('m4', 'zzgnulib.m4')] result += [joinpath('m4', 'gnulib-common.m4')] @@ -548,7 +557,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -560,12 +570,16 @@ Include:|Link:|License:|Maintainer:)' break parts += [line] modules = ''.join(parts) - modules = [line for line in modules.split( - '\n') if line.strip()] - modules = [ - module for module in modules if not module.startswith('#')] + modules = [ line + for line in modules.split('\n') + if line.strip() ] + modules = [ module + for module in modules + if not module.startswith('#') ] for line in modules: - split = [part for part in line.split(' ') if part.strip()] + split = [ part + for part in line.split(' ') + if part.strip() ] if len(split) == 1: module = line.strip() condition = None @@ -587,7 +601,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -613,7 +628,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -653,7 +669,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -689,19 +706,22 @@ Include:|Link:|License:|Maintainer:)' # TODO: unconditional automake snippet for nontests modules snippet = self.getAutomakeSnippet_Conditional() snippet = constants.combine_lines(snippet) - pattern = compiler( - '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) + pattern = compiler('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) mentioned_files = pattern.findall(snippet) if mentioned_files != list(): mentioned_files = mentioned_files[-1].split(' ') - mentioned_files = [f.strip() for f in mentioned_files] - mentioned_files = [f for f in mentioned_files if f != ''] + mentioned_files = [ f.strip() + for f in mentioned_files ] + mentioned_files = [ f + for f in mentioned_files + if f != '' ] mentioned_files = sorted(set(mentioned_files)) all_files = self.getFiles() lib_files = filter_filelist(constants.NL, all_files, 'lib/', '', 'lib/', '').split(constants.NL) - extra_files = [ - f for f in lib_files if f not in mentioned_files] + extra_files = [ f + for f in lib_files + if f not in mentioned_files ] extra_files = sorted(set(extra_files)) if extra_files != [''] and extra_files: result += 'EXTRA_DIST += %s' % ' '.join(extra_files) @@ -720,8 +740,7 @@ Include:|Link:|License:|Maintainer:)' buildaux_files = sorted(set(buildaux_files)) if buildaux_files != ['']: buildaux_files = ''.join(buildaux_files) - buildaux_files = joinpath( - '$(top_srcdir)', auxdir, buildaux_files) + buildaux_files = joinpath('$(top_srcdir)', auxdir, buildaux_files) result += 'EXTRA_DIST += %s' % buildaux_files result += '\n\n' # Synthesize an EXTRA_DIST augmentation also for the files from top/. @@ -748,7 +767,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -776,7 +796,8 @@ Include:|Link:|License:|Maintainer:)' if section in self.content: snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|' @@ -786,7 +807,9 @@ Include:|Link:|License:|Maintainer:)' if findflag: break parts += [line] - parts = [part.strip() for part in parts if part.strip()] + parts = [ part.strip() + for part in parts + if part.strip() ] # result = ' '.join(parts) self.cache['link'] = parts return self.cache['link'] @@ -844,7 +867,8 @@ Include:|Link:|License:|Maintainer:)' else: # if section in self.content snippet = self.content.split(section)[-1] snippet = snippet.replace('\r\n', '\n') - lines = ['%s\n' % line for line in snippet.split('\n')] + lines = [ '%s\n' % line + for line in snippet.split('\n') ] parts = list() for line in lines: regex = '^(Description|Comment|Status|Notice|Applicability|' @@ -1023,8 +1047,10 @@ class GLModuleTable(object): self.addUnconditional(module) conditional = self.isConditional(module) dependencies = module.getDependencies() - depmodules = [pair[0] for pair in dependencies] - conditions = [pair[1] for pair in dependencies] + depmodules = [ pair[0] + for pair in dependencies ] + conditions = [ pair[1] + for pair in dependencies ] if self.config.checkInclTestCategory(TESTS['tests']): testsname = module.getTestsName() if self.modulesystem.exists(testsname): @@ -1067,12 +1093,10 @@ class GLModuleTable(object): index = depmodules.index(depmodule) condition = conditions[index] if condition: - self.addConditional( - module, depmodule, condition) + self.addConditional(module, depmodule, condition) else: # if condition if conditional: - self.addConditional( - module, depmodule, True) + self.addConditional(module, depmodule, True) else: # if not conditional self.addUnconditional(module) listing = list() # Create empty list @@ -1117,8 +1141,12 @@ class GLModuleTable(object): main_modules = self.transitive_closure(basemodules) self.config.setInclTestCategory(TESTS['tests'], saved_inctests) tests_modules = \ - [m for m in finalmodules if m not in main_modules] \ - + [m for m in main_modules if m.getApplicability() != 'main'] + [ m + for m in finalmodules + if m not in main_modules ] \ + + [ m + for m in main_modules + if m.getApplicability() != 'main' ] tests_modules = sorted(set(tests_modules)) result = tuple([main_modules, tests_modules]) return result @@ -1137,8 +1165,7 @@ class GLModuleTable(object): raise TypeError('each module must be a GLModule instance') snippet = module.getAutomakeSnippet() snippet = constants.remove_backslash_newline(snippet) - pattern = compiler( - '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) + pattern = compiler('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M) files = pattern.findall(snippet) if files: # if source files were found files = files[-1].split(' ') @@ -1163,7 +1190,8 @@ class GLModuleTable(object): for module in modules: if type(module) is not GLModule: raise TypeError('each module must be a GLModule instance') - listings = [module.getFiles() for module in modules] + listings = [ module.getFiles() + for module in modules ] for listing in listings: for file in listing: if file not in filelist: @@ -1180,12 +1208,8 @@ class GLModuleTable(object): ac_version = self.config['ac_version'] main_filelist = self.filelist(main_modules) tests_filelist = self.filelist(tests_modules) - tests_filelist = \ - [ # Begin to sort filelist - file.replace('lib/', 'tests=lib/', 1) \ - if file.startswith('lib/') else file - for file in tests_filelist - ] # Finish to sort filelist + tests_filelist = [ file.replace('lib/', 'tests=lib/', 1) if file.startswith('lib/') else file + for file in tests_filelist ] result = tuple([main_filelist, tests_filelist]) return result diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index 285b94ba10..732a0590df 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -107,8 +107,8 @@ class GLTestDir(object): Replace auxdir, docbase, sourcebase, m4base and testsbase from default to their version from config.''' if type(files) is not list: - raise TypeError( - 'files argument must has list type, not %s' % type(files).__name__) + raise TypeError('files argument must have list type, not %s' + % type(files).__name__) for file in files: if type(file) is not str: raise TypeError('each file must be a string instance') @@ -131,8 +131,7 @@ class GLTestDir(object): elif file.startswith('tests/'): path = constants.substart('tests/', '%s/' % testsbase, file) elif file.startswith('tests=lib/'): - path = constants.substart( - 'tests=lib/', '%s/' % testsbase, file) + path = constants.substart('tests=lib/', '%s/' % testsbase, file) elif file.startswith('top/'): path = constants.substart('top/', '', file) else: # file is not a special file @@ -170,11 +169,13 @@ class GLTestDir(object): specified_modules = self.modulesystem.list() specified_modules = [module for module in specified_modules - if module not in ['config-h', 'non-recursive-gnulib-prefix-hack', 'ftruncate', 'mountlist', 'lib-ignore']] + if module not in ['config-h', 'non-recursive-gnulib-prefix-hack', + 'ftruncate', 'mountlist', 'lib-ignore']] # Canonicalize the list of specified modules. specified_modules = sorted(set(specified_modules)) - specified_modules = [self.modulesystem.find(m) for m in specified_modules] + specified_modules = [ self.modulesystem.find(m) + for m in specified_modules ] # Test modules which invoke AC_CONFIG_FILES cannot be used with # --with-tests --single-configure. Avoid them. @@ -271,21 +272,29 @@ class GLTestDir(object): if single_configure: # Add dummy package if it is needed. main_modules = moduletable.add_dummy(main_modules) - if 'dummy' in [str(module) for module in main_modules]: - main_modules = [m for m in main_modules if str(m) != 'dummy'] + if 'dummy' in [ str(module) + for module in main_modules ]: + main_modules = [ m + for m in main_modules + if str(m) != 'dummy' ] dummy = self.modulesystem.find('dummy') main_modules = sorted(set(main_modules)) + [dummy] if libtests: # if we need to use libtests.a tests_modules = moduletable.add_dummy(tests_modules) - if 'dummy' in [str(module) for module in tests_modules]: - tests_modules = [ - m for m in tests_modules if str(m) != 'dummy'] + if 'dummy' in [ str(module) + for module in tests_modules ]: + tests_modules = [ m + for m in tests_modules + if str(m) != 'dummy' ] dummy = self.modulesystem.find('dummy') tests_modules = sorted(set(tests_modules)) + [dummy] else: # if not single_configure modules = moduletable.add_dummy(modules) - if 'dummy' in [str(module) for module in modules]: - modules = [m for m in modules if str(m) != 'dummy'] + if 'dummy' in [ str(module) + for module in modules ]: + modules = [ m + for m in modules + if str(m) != 'dummy' ] dummy = self.modulesystem.find('dummy') modules = sorted(set(modules)) + [dummy] @@ -453,15 +462,17 @@ class GLTestDir(object): # if str(module) not in ['gnumakefile', 'maintainer-makefile'] else: snippet = module.getAutoconfSnippet_Early() - lines = [line for line in snippet.split( - '\n') if line.strip()] + lines = [ line + for line in snippet.split('\n') + if line.strip() ] snippet = '\n'.join(lines) - pattern = compiler( - 'AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M) + pattern = compiler('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M) snippet = pattern.sub('\\1', snippet) snippet = snippet.strip() snippets += [snippet] - snippets = [snippet for snippet in snippets if snippet.strip()] + snippets = [ snippet + for snippet in snippets + if snippet.strip()] emit += '%s\n' % '\n'.join(snippets) if libtool: emit += 'LT_INIT([win32-dll])\n' @@ -568,14 +579,17 @@ class GLTestDir(object): solution = module.isNonTests() if solution: snippet = module.getAutoconfSnippet_Early() - lines = [line for line in snippet.split('\n') if line.strip()] + lines = [ line + for line in snippet.split('\n') + if line.strip() ] snippet = '\n'.join(lines) - pattern = compiler( - 'AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M) + pattern = compiler('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M) snippet = pattern.sub('\\1', snippet) snippet = snippet.strip() snippets += [snippet] - snippets = [snippet for snippet in snippets if snippet.strip()] + snippets = [ snippet + for snippet in snippets + if snippet.strip() ] emit += '%s\n' % '\n'.join(snippets) if libtool: emit += 'LT_INIT([win32-dll])\n' @@ -744,24 +758,34 @@ class GLTestDir(object): regex_find += pattern.findall(snippet) pattern = compiler('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M) regex_find += pattern.findall(snippet) - regex_find = [line.strip() for line in regex_find if line.strip()] + regex_find = [ line.strip() + for line in regex_find + if line.strip() ] for part in regex_find: cleaned_files += \ - [line.strip() for line in part.split(' ') if line.strip()] + [ line.strip() + for line in part.split(' ') + if line.strip() ] # Extract the value of "BUILT_SOURCES += ...". Remove variable references # such $(FOO_H) because they don't refer to distributed files. regex_find = list() pattern = compiler('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M) regex_find += pattern.findall(snippet) - regex_find = [line.strip() for line in regex_find if line.strip()] + regex_find = [ line.strip() + for line in regex_find + if line.strip()] for part in regex_find: built_sources += \ - [line.strip() for line in part.split(' ') if line.strip()] - built_sources = [line for line in built_sources - if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line))] - distributed_built_sources = [file for file in built_sources - if file not in cleaned_files] + [ line.strip() + for line in part.split(' ') + if line.strip()] + built_sources = [ line + for line in built_sources + if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ] + distributed_built_sources = [ file + for file in built_sources + if file not in cleaned_files ] if inctests: # Likewise for built files in the $testsbase directory. @@ -774,13 +798,16 @@ class GLTestDir(object): regex_find = list() pattern = compiler('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M) regex_find += pattern.findall(snippet) - pattern = compiler( - '^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M) + pattern = compiler('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M) regex_find += pattern.findall(snippet) - regex_find = [line.strip() for line in regex_find if line.strip()] + regex_find = [ line.strip() + for line in regex_find + if line.strip() ] for part in regex_find: tests_cleaned_files += \ - [line.strip() for line in part.split(' ') if line.strip()] + [ line.strip() + for line in part.split(' ') + if line.strip() ] # Extract the value of "BUILT_SOURCES += ...". Remove variable references # such $(FOO_H) because they don't refer to distributed files. @@ -788,14 +815,20 @@ class GLTestDir(object): tests_built_sources = list() pattern = compiler('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M) regex_find += pattern.findall(snippet) - regex_find = [line.strip() for line in regex_find if line.strip()] + regex_find = [ line.strip() + for line in regex_find + if line.strip() ] for part in regex_find: tests_built_sources += \ - [line.strip() for line in part.split(' ') if line.strip()] - tests_built_sources = [line for line in tests_built_sources - if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line))] - tests_distributed_built_sources = [file for file in tests_built_sources - if file not in cleaned_files] + [ line.strip() + for line in part.split(' ') + if line.strip() ] + tests_built_sources = [ line + for line in tests_built_sources + if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ] + tests_distributed_built_sources = [ file + for file in tests_built_sources + if file not in cleaned_files] if distributed_built_sources or tests_distributed_built_sources: os.chdir(self.testdir) @@ -875,10 +908,12 @@ class GLMegaTestDir(object): Create a mega scratch package with the given modules one by one and all together.''' megasubdirs = list() - modules = [self.modulesystem.find(m) for m in self.config['modules']] + modules = [ self.modulesystem.find(m) + for m in self.config['modules'] ] if not modules: modules = self.modulesystem.list() - modules = [self.modulesystem.find(m) for m in modules] + modules = [ self.modulesystem.find(m) + for m in modules ] modules = sorted(set(modules)) # First, all modules one by one. @@ -889,8 +924,11 @@ class GLMegaTestDir(object): # Then, all modules all together. # Except config-h, which breaks all modules which use HAVE_CONFIG_H. - modules = [module for module in modules if str(module) != 'config-h'] - self.config.setModules([str(module) for module in modules]) + modules = [ module + for module in modules + if str(module) != 'config-h' ] + self.config.setModules([ str(module) + for module in modules ]) #GLTestDir(self.config, self.megatestdir).execute() megasubdirs += ['ALL'] @@ -918,8 +956,9 @@ class GLMegaTestDir(object): cvsdate = cvsdate.replace(key, repdict[key]) for key in repdict: cvsdate = cvsdate.replace(key, repdict[key]) - cvsdate = ''.join( - [date for date in cvsdate.split(' ') if date.strip()]) + cvsdate = ''.join([ date + for date in cvsdate.split(' ') + if date.strip() ]) cvsdate = '%s%s%s' % (cvsdate[4:], cvsdate[2:4], cvsdate[:2]) emit += '#!/bin/sh\n' emit += 'CVSDATE=%s\n' % cvsdate diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 70864f9f8d..7d59235007 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -253,9 +253,12 @@ def cleaner(sequence): for value in sequence] sequence = [value.replace('(', '').replace(')', '') for value in sequence] - sequence = [False if value == 'false' else value for value in sequence] - sequence = [True if value == 'true' else value for value in sequence] - sequence = [value.strip() for value in sequence] + sequence = [ False if value == 'false' else value + for value in sequence ] + sequence = [ True if value == 'true' else value + for value in sequence ] + sequence = [ value.strip() + for value in sequence ] return sequence @@ -362,11 +365,9 @@ def link_relative(src, dest): '''Like ln -s, except that src is given relative to the current directory (or absolute), not given relative to the directory of dest.''' if type(src) is not str: - raise TypeError( - 'src must be a string, not %s' % (type(src).__name__)) + raise TypeError('src must be a string, not %s' % (type(src).__name__)) if type(dest) is not str: - raise TypeError( - 'dest must be a string, not %s' % (type(dest).__name__)) + raise TypeError('dest must be a string, not %s' % (type(dest).__name__)) if src.startswith('/') or (len(src) >= 2 and src[1] == ':'): symlink_relative(src, dest) else: # if src is not absolute @@ -448,7 +449,9 @@ def nlremove(text): '''Remove empty lines from the source text.''' text = nlconvert(text) text = text.replace('\r\n', '\n') - lines = [line for line in text.split('\n') if line != ''] + lines = [ line + for line in text.split('\n') + if line != '' ] text = '\n'.join(lines) text = nlconvert(text) return text -- 2.34.1