diff mbox series

[layerindex-web,2/3] tools: use raw strings for regular expressions

Message ID 20261017183209.90930-2-tim.orling@konsulko.com
State New
Headers show
Series [layerindex-web,1/3] layerindex: use raw strings for regular expressions | expand

Commit Message

Tim Orling Oct. 17, 2026, 6:32 p.m. UTC
Fix the remaining "invalid escape sequence" warnings in the layerindex
and rrs tools, which the test suite does not import. Python 3.12 turns
these into SyntaxWarnings and a future release will make them errors.
The resulting pattern strings are unchanged.

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 layerindex/tools/import_layer.py       | 2 +-
 layerindex/tools/import_otherdistro.py | 6 +++---
 rrs/tools/common.py                    | 4 ++--
 rrs/tools/rrs_maintainer_history.py    | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/layerindex/tools/import_layer.py b/layerindex/tools/import_layer.py
index 0b203c3..0547223 100755
--- a/layerindex/tools/import_layer.py
+++ b/layerindex/tools/import_layer.py
@@ -205,7 +205,7 @@  def get_layer_type_choices():
     return (help_str, choices)
 
 def main():
-    valid_layer_name = re.compile('[-\w]+$')
+    valid_layer_name = re.compile(r'[-\w]+$')
 
     parser = optparse.OptionParser(
         usage = """
diff --git a/layerindex/tools/import_otherdistro.py b/layerindex/tools/import_otherdistro.py
index f6ee395..2a39fb4 100755
--- a/layerindex/tools/import_otherdistro.py
+++ b/layerindex/tools/import_otherdistro.py
@@ -52,8 +52,8 @@  def update_recipe_file(path, recipe, repodir, raiseexceptions=False):
     # yes, yes, I know this is all crude as hell, but it gets the job done.
     # At the end of the day we are scraping the spec file, we aren't trying to build it
 
-    pnum_re = re.compile('-p[\s]*([0-9]+)')
-    configure_re = re.compile('[/%]configure\s')
+    pnum_re = re.compile(r'-p[\s]*([0-9]+)')
+    configure_re = re.compile(r'[/%]configure\s')
 
     try:
         logger.debug('Updating recipe %s' % path)
@@ -294,7 +294,7 @@  def update_recipe_file(path, recipe, repodir, raiseexceptions=False):
                     patchsplit = line.split()
                     if '-P' in line:
                         # Old style
-                        patchid = re.search('-P[\s]*([0-9]+)', line)
+                        patchid = re.search(r'-P[\s]*([0-9]+)', line)
                         if patchid:
                             patchid = patchid.groups()[0]
                         else:
diff --git a/rrs/tools/common.py b/rrs/tools/common.py
index 1ce5dd5..0cac1f7 100644
--- a/rrs/tools/common.py
+++ b/rrs/tools/common.py
@@ -146,7 +146,7 @@  def get_recipe_pv_without_srcpv(pv, uri_type):
     sfx = ''
 
     if uri_type == 'git':
-        git_regex = re.compile("(?P<pfx>(v|r|))(?P<ver>((\d+[\.\-_]*)+))(?P<sfx>(\+|)(git|)(r|)(AUTOINC|)(\+|))(?P<rev>.*)")
+        git_regex = re.compile(r"(?P<pfx>(v|r|))(?P<ver>((\d+[\.\-_]*)+))(?P<sfx>(\+|)(git|)(r|)(AUTOINC|)(\+|))(?P<rev>.*)")
         m = git_regex.match(pv)
 
         if m:
@@ -154,7 +154,7 @@  def get_recipe_pv_without_srcpv(pv, uri_type):
             pfx = m.group('pfx')
             sfx = m.group('sfx')
     else:
-        regex = re.compile("(?P<pfx>(v|r|))(?P<ver>((\w+[\.\-_]*)+))")
+        regex = re.compile(r"(?P<pfx>(v|r|))(?P<ver>((\w+[\.\-_]*)+))")
         m = regex.match(pv)
         if m:
             pv = m.group('ver')
diff --git a/rrs/tools/rrs_maintainer_history.py b/rrs/tools/rrs_maintainer_history.py
index c509e5a..6465ac7 100755
--- a/rrs/tools/rrs_maintainer_history.py
+++ b/rrs/tools/rrs_maintainer_history.py
@@ -37,7 +37,7 @@  MAINTAINERS_INCLUDE_PATH = 'conf/distro/include/maintainers.inc'
 """
 def get_recipe_maintainer(line, logger):
     import re
-    regex = re.compile('^RECIPE_MAINTAINER[:_]pn-(?P<pn>.*)\s=\s"(?P<name>.+) <(?P<email>.*)>"$')
+    regex = re.compile(r'^RECIPE_MAINTAINER[:_]pn-(?P<pn>.*)\s=\s"(?P<name>.+) <(?P<email>.*)>"$')
 
     match = regex.search(line)
     if match: