* pygnulib/constants.py (compiler): Remove function.
* gnulib-tool.py: Use re.compile directly instead.
* pygnulib/*.py: Likewise.
+2022-08-05 Bruno Haible <bruno@clisp.org>
+
+ gnulib-tool.py: Simplify.
+ * pygnulib/constants.py (compiler): Remove function.
+ * gnulib-tool.py: Use re.compile directly instead.
+ * pygnulib/*.py: Likewise.
+
2022-08-04 Bruno Haible <bruno@clisp.org>
gnulib-tool.py: Fix typo.
UTILS = constants.UTILS
MODES = constants.MODES
TESTS = constants.TESTS
-compiler = constants.compiler
joinpath = constants.joinpath
copyfile = constants.copyfile
isabs = os.path.isabs
else: # if not isfile(filepath)
filepath = joinpath(destdir, 'aclocal.m4')
if isfile(filepath):
- pattern = constants.compiler(r'm4_include\(\[(.*?)\]\)')
+ pattern = re.compile(r'm4_include\(\[(.*?)\]\)')
with codecs.open(filepath, 'rb', 'UTF-8') as file:
m4dirs = pattern.findall(file.read())
m4dirs = [ os.path.dirname(m4dir)
# Define global constants
#===============================================================================
TESTS = constants.TESTS
-compiler = constants.compiler
joinpath = constants.joinpath
isfile = os.path.isfile
normpath = os.path.normpath
if line.strip() ]
snippet = '%s\n' % '\n'.join(lines)
transformer = fileassistant.transformers.get('aux', '')
- pattern = compiler('(^.*?$)', re.S | re.M)
+ pattern = re.compile('(^.*?$)', re.S | re.M)
snippet = pattern.sub('%s\\1' % indentation, snippet)
if transformer:
args = ['sed', '-e', transformer]
else:
# Don't indent AM_GNU_GETTEXT_VERSION line, as that confuses
# autopoint through at least GNU gettext version 0.18.2.
- snippet = compiler('^ *AM_GNU_GETTEXT_VERSION').sub('AM_GNU_GETTEXT_VERSION', snippet)
+ snippet = re.compile('^ *AM_GNU_GETTEXT_VERSION').sub('AM_GNU_GETTEXT_VERSION', snippet)
emit += snippet
if str(module) == 'alloca' and libtool and not disable_libtool:
emit += 'changequote(,)dnl\n'
if replace_auxdir:
regex = 'AC_CONFIG_FILES\\(\\[(.*?)\\:build-aux/(.*?)\\]\\)'
repl = 'AC_CONFIG_FILES([\\1:%s/\\2])' % auxdir
- pattern = compiler(regex, re.S | re.M)
+ pattern = re.compile(regex, re.S | re.M)
emit = pattern.sub(repl, emit)
lines = [ line
for line in emit.split('\n')
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 = re.compile('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
amsnippet1 = pattern.sub('', amsnippet1)
- pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
+ pattern = re.compile('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_')
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 = constants.combine_lines_matching(re.compile('%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)
+ pattern = re.compile('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
amsnippet2 = pattern.sub('%s_%s_\\1' % (libname, libext),
amsnippet2)
amsnippet2 = amsnippet2.replace('$(GNULIB_',
# * https://debbugs.gnu.org/10997
# * https://debbugs.gnu.org/11030
# So we need this workaround.
- pattern = compiler('^pkgdata_DATA *\\+=', re.S | re.M)
+ pattern = re.compile('^pkgdata_DATA *\\+=', re.S | re.M)
if pattern.findall(allsnippets):
emit += 'pkgdata_DATA =\n'
emit += 'EXTRA_DIST =\n'
insnippets = False
inmakefile = False
regex = '^[a-zA-Z0-9_]*_%sLIBRARIES *\\+{0,1}= *%s.%s' % (perhapsLT, libname, libext)
- pattern = compiler(regex, re.S | re.M)
+ pattern = re.compile(regex, re.S | re.M)
insnippets = bool(pattern.findall(allsnippets))
# Then test if $sourcebase/Makefile.am (if it exists) specifies it.
path = joinpath(sourcebase, 'Makefile.am')
snippet = snippet.replace('lib_LIBRARIES', 'lib%_LIBRARIES')
snippet = snippet.replace('lib_LTLIBRARIES', 'lib%_LTLIBRARIES')
if LD_flags:
- pattern = compiler('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('lib_LDFLAGS[\t ]*\\+=(.*?)$', re.S | re.M)
snippet = pattern.sub('', snippet)
- pattern = compiler('lib_([A-Z][A-Z](?:.*?))', re.S | re.M)
+ pattern = re.compile('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('lib%_LIBRARIES', 'lib_LIBRARIES')
# * https://debbugs.gnu.org/10997
# * https://debbugs.gnu.org/11030
# So we need this workaround.
- pattern = compiler('^pkgdata_DATA *\\+=', re.S | re.M)
+ pattern = re.compile('^pkgdata_DATA *\\+=', re.S | re.M)
if bool(pattern.findall(main_snippets)) or bool(pattern.findall(longrun_snippets)):
emit += 'pkgdata_DATA =\n'
#===============================================================================
MODES = constants.MODES
TESTS = constants.TESTS
-compiler = constants.compiler
joinpath = constants.joinpath
cleaner = constants.cleaner
copyfile2 = constants.copyfile2
self.config.setAutoconfFile(path)
with codecs.open(path, 'rb', 'UTF-8') as file:
data = file.read()
- pattern = compiler(r'^AC_CONFIG_AUX_DIR\((.*?)\)$', re.S | re.M)
+ pattern = re.compile(r'^AC_CONFIG_AUX_DIR\((.*?)\)$', re.S | re.M)
match = pattern.findall(data)
if match:
result = cleaner(match)[0]
self.cache.setAuxDir(joinpath(self.config['destdir'], result))
- pattern = compiler(r'A[CM]_PROG_LIBTOOL', re.S | re.M)
+ pattern = re.compile(r'A[CM]_PROG_LIBTOOL', re.S | re.M)
guessed_libtool = bool(pattern.findall(data))
if self.config['auxdir'] == None:
self.config.setAuxDir(self.cache['auxdir'])
# Guess autoconf version.
- pattern = compiler(r'.*AC_PREREQ\((.*?)\)', re.S | re.M)
+ pattern = re.compile(r'.*AC_PREREQ\((.*?)\)', re.S | re.M)
versions = cleaner(pattern.findall(data))
if versions:
version = sorted(set([ float(version)
data = file.read()
# Create regex object and keys.
- pattern = compiler('^(gl_.*?)\\((.*?)\\)$', re.S | re.M)
+ pattern = re.compile('^(gl_.*?)\\((.*?)\\)$', re.S | re.M)
keys = \
[
'gl_LOCAL_DIR', 'gl_MODULES', 'gl_AVOID', 'gl_SOURCE_BASE',
with codecs.open(path, 'rb', 'UTF-8') as file:
data = file.read()
regex = 'AC_DEFUN\\(\\[%s_FILE_LIST\\], \\[(.*?)\\]\\)' % self.cache['macro_prefix']
- pattern = compiler(regex, re.S | re.M)
+ pattern = re.compile(regex, re.S | re.M)
self.cache.setFiles(pattern.findall(data)[-1].strip().split())
# The self.config['localpath'] defaults to the cached one. Recall that
notice = notice.strip()
if notice:
print('Notice from module %s:' % str(module))
- pattern = compiler('^(.*?)$', re.S | re.M)
+ pattern = re.compile('^(.*?)$', re.S | re.M)
notice = pattern.sub(' \\1', notice)
print(notice)
with codecs.open(configure_ac, 'rb', 'UTF-8') as file:
data = file.read()
match_result1 = \
- bool(compiler('^ *AC_PROG_CC_STDC', re.S | re.M).findall(data))
+ bool(re.compile('^ *AC_PROG_CC_STDC', re.S | re.M).findall(data))
match_result2 = \
- bool(compiler('^ *AC_PROG_CC_C99', re.S | re.M).findall(data))
+ bool(re.compile('^ *AC_PROG_CC_C99', re.S | re.M).findall(data))
if match_result1:
position_early_after = 'AC_PROG_CC_STDC'
elif match_result2:
DIRS = constants.DIRS
ENCS = constants.ENCS
TESTS = constants.TESTS
-compiler = constants.compiler
joinpath = constants.joinpath
isdir = os.path.isdir
isfile = os.path.isfile
'''GLModule.getName() -> str
Return the name of the module.'''
- pattern = compiler(joinpath('modules', '(.*?)$'))
+ pattern = re.compile(joinpath('modules', '(.*?)$'))
result = pattern.findall(self.module)[0]
return result
result = ''
else: # if section in self.content
pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex)
- pattern = compiler(pattern, re.S | re.M)
+ pattern = re.compile(pattern, re.S | re.M)
result = pattern.findall(self.content)
if type(result) is list:
if not result:
result = ''
else: # if section in self.content
pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex)
- pattern = compiler(pattern, re.S | re.M)
+ pattern = re.compile(pattern, re.S | re.M)
result = pattern.findall(self.content)
if type(result) is list:
if not result:
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
# 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 = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
mentioned_files = pattern.findall(snippet)
if mentioned_files != list():
mentioned_files = mentioned_files[-1].split(' ')
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
parts += [line]
result = ''.join(parts)
result = result.strip()
- pattern = compiler('^(["<].*?[>"])', re.S | re.M)
+ pattern = re.compile('^(["<].*?[>"])', re.S | re.M)
result = pattern.sub('#include \\1', result)
self.cache['include'] = result
return self.cache['include']
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
result = ''
else: # if section in self.content
pattern = '^%s[\t ]*(.*?)%s' % (section, self.regex)
- pattern = compiler(pattern, re.S | re.M)
+ pattern = re.compile(pattern, re.S | re.M)
result = pattern.findall(self.content)
if type(result) is list:
if not result:
regex = '^(Description|Comment|Status|Notice|Applicability|'
regex += 'Files|Depends-on|configure\\.ac-early|configure\\.ac|'
regex += 'Makefile\\.am|Include|Link|License|Maintainer):$'
- pattern = compiler(regex)
+ pattern = re.compile(regex)
findflag = pattern.findall(line)
if findflag:
break
if self.config['conddeps']:
automake_snippet = \
module.getAutomakeSnippet_Conditional()
- pattern = compiler('^if')
+ pattern = re.compile('^if')
if not pattern.findall(automake_snippet):
self.addUnconditional(module)
conditional = self.isConditional(module)
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 = re.compile('^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
files = pattern.findall(snippet)
if files: # if source files were found
files = files[-1].split(' ')
DIRS = constants.DIRS
UTILS = constants.UTILS
TESTS = constants.TESTS
-compiler = constants.compiler
joinpath = constants.joinpath
copyfile = constants.copyfile
movefile = constants.movefile
notice = module.getNotice()
if notice:
print('Notice from module %s:' % str(module))
- pattern = compiler('^(.*?)$', re.S | re.M)
+ pattern = re.compile('^(.*?)$', re.S | re.M)
notice = pattern.sub(' \\1', notice)
print(notice)
else: # if not single_configure
notice = module.getNotice()
if notice:
print('Notice from module %s:' % str(module))
- pattern = compiler('^(.*?)$', re.S | re.M)
+ pattern = re.compile('^(.*?)$', re.S | re.M)
notice = pattern.sub(' \\1', notice)
print(notice)
for line in snippet.split('\n')
if line.strip() ]
snippet = '\n'.join(lines)
- pattern = compiler('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
+ pattern = re.compile('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
snippet = pattern.sub('\\1', snippet)
snippet = snippet.strip()
snippets += [snippet]
for line in snippet.split('\n')
if line.strip() ]
snippet = '\n'.join(lines)
- pattern = compiler('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
+ pattern = re.compile('AC_REQUIRE\\(\\[([^()].*?)\\]\\)', re.S | re.M)
snippet = pattern.sub('\\1', snippet)
snippet = snippet.strip()
snippets += [snippet]
# Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
regex_find = list()
- pattern = compiler('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
- pattern = compiler('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
for line in regex_find
# 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)
+ pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
for line in regex_find
if line.strip()]
built_sources = [ line
for line in built_sources
- if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ]
+ if not bool(re.compile('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ]
distributed_built_sources = [ file
for file in built_sources
if file not in cleaned_files ]
# Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
regex_find = list()
- pattern = compiler('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
- pattern = compiler('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
for line in regex_find
# such $(FOO_H) because they don't refer to distributed files.
regex_find = list()
tests_built_sources = list()
- pattern = compiler('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M)
+ pattern = re.compile('^BUILT_SOURCES[\t ]*\\+=(.*?)$', re.S | re.M)
regex_find += pattern.findall(snippet)
regex_find = [ line.strip()
for line in regex_find
if line.strip() ]
tests_built_sources = [ line
for line in tests_built_sources
- if not bool(compiler('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ]
+ if not bool(re.compile('[$]\\([A-Za-z0-9_]*\\)$').findall(line)) ]
tests_distributed_built_sources = [ file
for file in tests_built_sources
if file not in cleaned_files]
sys.exit(retcode)
-def compiler(pattern, flags=0):
- '''Compile regex pattern depending on version of Python.'''
- pattern = re.compile(pattern, flags)
- return pattern
-
-
def cleaner(sequence):
'''Clean string or list of strings after using regex.'''
if type(sequence) is str:
listing = list()
for filename in filelist:
if filename.startswith(prefix) and filename.endswith(suffix):
- pattern = compiler('^%s(.*?)%s$'
- % (removed_prefix, removed_suffix))
+ pattern = re.compile('^%s(.*?)%s$'
+ % (removed_prefix, removed_suffix))
result = pattern.sub('%s\\1%s'
% (added_prefix, added_suffix), filename)
listing += [result]