>From f00ef30ee0a68bf91cfd081afc784cb8ffd00656 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 29 Jul 2022 16:35:28 +0200 Subject: [PATCH 1/5] gnulib-tool.py: Use mainstream coding style. * gnulib-tool.py: Clarify the coding style. Fix some pycodestyle warnings. * pygnulib/constants.py: Likewise. * pygnulib/GLEmiter.py: Likewise. * pygnulib/GLImport.py: Likewise. * pygnulib/GLMakefileTable.py: Likewise. --- ChangeLog | 10 ++++++++++ gnulib-tool.py | 10 ++++++++-- pygnulib/GLEmiter.py | 6 +++--- pygnulib/GLImport.py | 2 +- pygnulib/GLMakefileTable.py | 6 +++--- pygnulib/constants.py | 10 ++++++---- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ebb0f1dc2..20cf23f499 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2022-07-29 Bruno Haible + + gnulib-tool.py: Use mainstream coding style. + * gnulib-tool.py: Clarify the coding style. Fix some pycodestyle + warnings. + * pygnulib/constants.py: Likewise. + * pygnulib/GLEmiter.py: Likewise. + * pygnulib/GLImport.py: Likewise. + * pygnulib/GLMakefileTable.py: Likewise. + 2022-07-29 Bruno Haible gnulib-tool.py: Fix error (regression 2021-04-11). diff --git a/gnulib-tool.py b/gnulib-tool.py index f81501b9c0..860487a934 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -19,6 +19,13 @@ # This program is meant for authors or maintainers which want to import # modules from gnulib into their packages. +# CODING STYLE for this file and its companions: +# Like PEP 8 , except +# - Line length is not limited to 79 characters. +# - Line breaking before or after binary operators? Better before, like in GNU. +# You can use this command to check the style: +# $ pycodestyle --max-line-length=128 --ignore=E265,W503,E241,E711,E712 gnulib-tool.py pygnulib/*.py + #=============================================================================== # Define global imports @@ -993,8 +1000,7 @@ if __name__ == '__main__': with codecs.open(tempname, 'wb', 'UTF-8') as file: file.write(incompatibilities) sed_table = 's,^\\([^ ]*\\) ,\\1' + ' ' * 51 + ',\n' - sed_table += 's,^\\(' + '.' * 49 + \ - '[^ ]*\) *,' + ' ' * 17 + '\\1 ,' + sed_table += 's,^\\(' + '.' * 49 + '[^ ]*\\) *,' + ' ' * 17 + '\\1 ,' args = ['sed', '-e', sed_table, tempname] incompatibilities = sp.check_output( args).decode(ENCS['default']) diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 6d523bda3c..3009214c9d 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -516,7 +516,7 @@ USE_MSGCTXT = no\n""" # arguments. The check is performed only when autoconf is run from the # directory where the configure.ac resides; if it is run from a different # directory, the check is skipped. - emit += """\ + emit += r"""\ m4_ifval(%V1%_LIBSOURCES_LIST, [ m4_syscmd([test ! -d ]m4_defn([%V1%_LIBSOURCES_DIR])[ || for gl_file in ]%V1%_LIBSOURCES_LIST[ ; do @@ -733,8 +733,8 @@ AC_DEFUN([%V1%_LIBSOURCES], [ amsnippet1 += '%s_%s_DEPENDENCIES += @%sALLOCA@\n' % \ (libname, libext, perhapsLT) amsnippet1 = constants.combine_lines_matching( - compiler('%s_%s_SOURCES' % (libname, libext)), - amsnippet1) + compiler('%s_%s_SOURCES' % (libname, libext)), + amsnippet1) # Get unconditional snippet, edit it and save to amsnippet2. amsnippet2 = module.getAutomakeSnippet_Unconditional() diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 4fa00259e7..3acf94c463 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -105,7 +105,7 @@ class GLImport(object): self.config.setAuxDir(self.cache['auxdir']) # Guess autoconf version. - pattern = compiler('.*AC_PREREQ\((.*?)\)', re.S | re.M) + 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] diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index 74e6fe7d7d..1e848395d0 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -117,9 +117,9 @@ class GLMakefileTable(object): mfx = makefile dir2 = string() 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))): + (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/constants.py b/pygnulib/constants.py index 39fe08f002..7b37a5241c 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -13,6 +13,7 @@ import sys import platform import tempfile import subprocess as sp +import __main__ as interpreter #=============================================================================== @@ -68,7 +69,6 @@ ABCDEFGHIJKLMNOPQRSTUVWXYZ\ 0123456789' # Alphanumeric characters # Set ENCS dictionary -import __main__ as interpreter if not hasattr(interpreter, '__file__'): if sys.stdout.encoding != None: ENCS['default'] = sys.stdout.encoding @@ -443,12 +443,14 @@ def remove_backslash_newline(text): line to it.''' return text.replace('\\\n', '') + def combine_lines(text): '''Given a multiline string text, join lines by spaces: When a line ends in a backslash, remove the backslash and join the next line to it, inserting a space between them.''' return text.replace('\\\n', ' ') + def combine_lines_matching(pattern, text): '''Given a multiline string text, join lines by spaces, when the first such line matches a given RegexObject pattern. @@ -461,9 +463,9 @@ def combine_lines_matching(pattern, text): while match: (startpos, pos) = match.span() # Look how far the continuation lines extend. - pos = text.find('\n',pos) - while pos > 0 and text[pos-1] == '\\': - pos = text.find('\n',pos+1) + pos = text.find('\n', pos) + while pos > 0 and text[pos - 1] == '\\': + pos = text.find('\n', pos + 1) if pos < 0: pos = len(text) # Perform a combine_lines throughout the continuation lines. -- 2.34.1