+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).
# 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
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'])
# 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
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()
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]
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'))
import platform
import tempfile
import subprocess as sp
+import __main__ as interpreter
#===============================================================================
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
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.
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.