From 3bb200bba143ca21eda2f6f7415f3778c54f9cc9 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Thu, 11 Apr 2024 11:27:34 -0700 Subject: [PATCH] gnulib-tool.py: Remove redundant backslashes from regexps. * pygnulib/GLTestDir.py (GLTestDir.execute): Don't backslash ']' when it is outside of a set. * pygnulib/GLImport.py (GLImport.__init__): Don't use a backslash when ']' is at the start of a '[...]' set. Don't backslash special characters in a '[...]' set since they have their meaning dropped. * pygnulib/main.py (main): Likewise. --- ChangeLog | 10 ++++++++++ pygnulib/GLImport.py | 4 ++-- pygnulib/GLTestDir.py | 4 ++-- pygnulib/main.py | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 553533499b..f416f5c8f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-04-11 Collin Funk + + gnulib-tool.py: Remove redundant backslashes from regexps. + * pygnulib/GLTestDir.py (GLTestDir.execute): Don't backslash ']' when it + is outside of a set. + * pygnulib/GLImport.py (GLImport.__init__): Don't use a backslash when + ']' is at the start of a '[...]' set. Don't backslash special characters + in a '[...]' set since they have their meaning dropped. + * pygnulib/main.py (main): Likewise. + 2024-04-11 Collin Funk gnulib-tool.py: Simplify regular expressions. diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 46beb7e2a6..b200c7b250 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -93,7 +93,7 @@ class GLImport: self.cache.setAuxDir('.') with codecs.open(self.config.getAutoconfFile(), 'rb', 'UTF-8') as file: data = file.read() - pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^\]"\$`\\\)]+).*?$', re.MULTILINE) + pattern = re.compile(r'^AC_CONFIG_AUX_DIR\([\[ ]*([^]"$`\\)]+).*?$', re.MULTILINE) match = pattern.search(data) if match: self.cache.setAuxDir(match.group(1)) @@ -261,7 +261,7 @@ class GLImport: if self.config['destdir']: with open(self.config['configure_ac'], encoding='utf-8') as file: data = file.read() - pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^\]\)]*).*$', re.MULTILINE) + pattern = re.compile(r'^.*AM_INIT_AUTOMAKE\([\[ ]*([^])]*).*$', re.MULTILINE) configure_ac_automake_options = pattern.findall(data) if configure_ac_automake_options: automake_options = { x diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index f6ab4f9d2e..5fd4197e52 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -463,7 +463,7 @@ class GLTestDir: for line in snippet.split('\n') if line.strip() ] snippet = lines_to_multiline(lines) - pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M) + pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)]\)', re.M) snippet = pattern.sub(r'\1', snippet) snippet = snippet.strip() snippets.append(snippet) @@ -577,7 +577,7 @@ class GLTestDir: for line in snippet.split('\n') if line.strip() ] snippet = lines_to_multiline(lines) - pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)\]\)', re.M) + pattern = re.compile(r'AC_REQUIRE\(\[([^()]*)]\)', re.M) snippet = pattern.sub(r'\1', snippet) snippet = snippet.strip() snippets.append(snippet) diff --git a/pygnulib/main.py b/pygnulib/main.py index f8d082705d..5fec0ccc4a 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -927,7 +927,7 @@ def main() -> None: configure_ac_data = file.read() guessed_m4dirs = [] - pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^\]"\$`\\\)]*).*$', re.MULTILINE) + pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^]"$`\\)]*).*$', re.MULTILINE) match = pattern.findall(configure_ac_data) # Append the match to guessed_m4dirs. if match: @@ -1015,7 +1015,7 @@ def main() -> None: # No Makefile.am! Oh well. Look at the last generated aclocal.m4. filepath = joinpath(destdir, 'aclocal.m4') if isfile(filepath): - pattern = re.compile(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) -- 2.39.5