]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Use mainstream coding style.
authorBruno Haible <bruno@clisp.org>
Fri, 29 Jul 2022 14:35:28 +0000 (16:35 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 29 Jul 2022 14:35:28 +0000 (16:35 +0200)
* 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
gnulib-tool.py
pygnulib/GLEmiter.py
pygnulib/GLImport.py
pygnulib/GLMakefileTable.py
pygnulib/constants.py

index 5ebb0f1dc2cd7c33681cc9c295eb0e3c6fd31f35..20cf23f499641300da56c864e5c1120171eded2b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-07-29  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        gnulib-tool.py: Fix error (regression 2021-04-11).
index f81501b9c07827a29240e8879e77f826e5d4ba42..860487a934027808b8e81b72a0089bc3976a7a69 100755 (executable)
 # 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 <https://peps.python.org/pep-0008/>, 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'])
index 6d523bda3c5b3942dc744ccca20662c8a110dae7..3009214c9d1d237db687aa7d0c3c9ddc2e5066ef 100644 (file)
@@ -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()
index 4fa00259e7b4c628ac63094dfe04683dc643eb1a..3acf94c46310974984d6c8a5629cef575c7cde60 100644 (file)
@@ -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]
index 74e6fe7d7dfda737356b87bd70963c17e9498d31..1e848395d0b42c7fc159d6c1c3f1ed432bd97be4 100644 (file)
@@ -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'))
index 39fe08f002ee72bb61f3d2566fa0791edfdb7027..7b37a5241cce74644145ceb0374af73afb72694f 100644 (file)
@@ -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.