← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:re-raw-strings into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:re-raw-strings into launchpad-buildd:master.

Commit message:
Ensure that regex patterns with \-escapes are raw strings

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/383320

This fixes a number of DeprecationWarnings with Python >= 3.6.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:re-raw-strings into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 6ce8ca1..f5e69eb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,7 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
   * Work around /proc/self/fd-related test hang on Python >= 3.3.
   * Adjust tests to avoid making assumptions about dict iteration order.
   * Open temporary files in text mode in more cases.
+  * Ensure that regex patterns with \-escapes are raw strings.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 28 Apr 2020 10:19:27 +0100
 
diff --git a/lpbuildd/binarypackage.py b/lpbuildd/binarypackage.py
index 7a94ec5..664f459 100644
--- a/lpbuildd/binarypackage.py
+++ b/lpbuildd/binarypackage.py
@@ -34,33 +34,33 @@ class SBuildExitCodes:
 
 
 APT_MISSING_DEP_PATTERNS = [
-    'but [^ ]* is to be installed',
-    'but [^ ]* is installed',
-    'but it is not installable',
-    'but it is a virtual package',
+    r'but [^ ]* is to be installed',
+    r'but [^ ]* is installed',
+    r'but it is not installable',
+    r'but it is a virtual package',
     ]
 
 
 APT_DUBIOUS_DEP_PATTERNS = [
-    'but it is not installed',
-    'but it is not going to be installed',
+    r'but it is not installed',
+    r'but it is not going to be installed',
     ]
 
 
 class BuildLogRegexes:
     """Build log regexes for performing actions based on regexes, and extracting dependencies for auto dep-waits"""
     GIVENBACK = [
-        ("^E: There are problems and -y was used without --force-yes"),
+        (r"^E: There are problems and -y was used without --force-yes"),
         ]
     MAYBEDEPFAIL = [
-        'The following packages have unmet dependencies:\n'
-        '.* Depends: [^ ]*( \([^)]*\))? (%s)\n'
-        % '|'.join(APT_DUBIOUS_DEP_PATTERNS),
+        r'The following packages have unmet dependencies:\n'
+        r'.* Depends: [^ ]*( \([^)]*\))? (%s)\n'
+        % r'|'.join(APT_DUBIOUS_DEP_PATTERNS),
         ]
     DEPFAIL = {
-        'The following packages have unmet dependencies:\n'
-        '.* Depends: (?P<p>[^ ]*( \([^)]*\))?) (%s)\n'
-        % '|'.join(APT_MISSING_DEP_PATTERNS): "\g<p>",
+        r'The following packages have unmet dependencies:\n'
+        r'.* Depends: (?P<p>[^ ]*( \([^)]*\))?) (%s)\n'
+        % r'|'.join(APT_MISSING_DEP_PATTERNS): r"\g<p>",
         }
 
 
@@ -347,7 +347,7 @@ class BinaryPackageBuildManager(DebianBuildManager):
             return self.deferGatherResults()
 
         log_patterns = []
-        stop_patterns = [["^Toolchain package versions:", re.M]]
+        stop_patterns = [[r"^Toolchain package versions:", re.M]]
 
         # We don't distinguish attempted and failed.
         if success == SBuildExitCodes.ATTEMPTED:
@@ -365,7 +365,7 @@ class BinaryPackageBuildManager(DebianBuildManager):
                 except IOError:
                     pass
                 tail = log.read(4096)
-            if re.search("^Fail-Stage: install-deps$", tail, re.M):
+            if re.search(r"^Fail-Stage: install-deps$", tail, re.M):
                 for rx in BuildLogRegexes.MAYBEDEPFAIL:
                     log_patterns.append([rx, re.M | re.S])
                 for rx in BuildLogRegexes.DEPFAIL:
diff --git a/lpbuildd/builder.py b/lpbuildd/builder.py
index 2e2d392..c5ad197 100644
--- a/lpbuildd/builder.py
+++ b/lpbuildd/builder.py
@@ -47,9 +47,9 @@ def _sanitizeURLs(text_seq):
     """
     # This regular expression will be used to remove authentication
     # credentials from URLs.
-    password_re = re.compile('://([^:]+:[^@]+@)(\S+)')
+    password_re = re.compile(r'://([^:]+:[^@]+@)(\S+)')
     # Snap proxy passwords are UUIDs.
-    snap_proxy_auth_re = re.compile(',proxyauth=[^:]+:[A-Za-z0-9-]+')
+    snap_proxy_auth_re = re.compile(r',proxyauth=[^:]+:[A-Za-z0-9-]+')
 
     for line in text_seq:
         sanitized_line = password_re.sub(r'://\2', line)
diff --git a/lpbuildd/check_implicit_pointer_functions.py b/lpbuildd/check_implicit_pointer_functions.py
index f4a94cf..32e1fe6 100755
--- a/lpbuildd/check_implicit_pointer_functions.py
+++ b/lpbuildd/check_implicit_pointer_functions.py
@@ -38,19 +38,19 @@ import re
 import sys
 
 implicit_pattern = re.compile(
-    "([^:]*):(\d+):(\d+:)? warning: implicit declaration "
-    "of function [`']([^']*)'")
+    r"([^:]*):(\d+):(\d+:)? warning: implicit declaration "
+    r"of function [`']([^']*)'")
 pointer_pattern = re.compile(
-    "([^:]*):(\d+):(\d+:)? warning: "
-    + "("
-    +  "(assignment"
-    +  "|initialization"
-    +  "|return"
-    +  "|passing arg \d+ of `[^']*'"
-    +  "|passing arg \d+ of pointer to function"
-    +  ") makes pointer from integer without a cast"
-    + "|"
-    + "cast to pointer from integer of different size)")
+    r"([^:]*):(\d+):(\d+:)? warning: "
+    r"("
+     r"(assignment"
+     r"|initialization"
+     r"|return"
+     r"|passing arg \d+ of `[^']*'"
+     r"|passing arg \d+ of pointer to function"
+     r") makes pointer from integer without a cast"
+    r"|"
+    r"cast to pointer from integer of different size)")
 
 def main():
     last_implicit_filename = ""
diff --git a/lpbuildd/pottery/intltool.py b/lpbuildd/pottery/intltool.py
index 20d60f9..50030e0 100644
--- a/lpbuildd/pottery/intltool.py
+++ b/lpbuildd/pottery/intltool.py
@@ -255,7 +255,7 @@ class ConfigFile:
     def getVariable(self, name):
         """Search the file for a variable definition with this name."""
         pattern = re.compile(
-            "^%s[ \t]*=[ \t]*([^\s]*)" % re.escape(name), re.M)
+            r"^%s[ \t]*=[ \t]*([^\s]*)" % re.escape(name), re.M)
         result = pattern.search(self.content)
         if result is None:
             return None
@@ -264,7 +264,7 @@ class ConfigFile:
     def getFunctionParams(self, name):
         """Search file for a function call with this name, return parameters.
         """
-        pattern = re.compile("^%s\(([^)]*)\)" % re.escape(name), re.M)
+        pattern = re.compile(r"^%s\(([^)]*)\)" % re.escape(name), re.M)
         result = pattern.search(self.content)
         if result is None:
             return None
@@ -288,8 +288,8 @@ class Substitution(object):
     about the substitution style that is being used.
     """
 
-    autoconf_pattern = re.compile("@([^@]+)@")
-    makefile_pattern = re.compile("\$\(?([^\s\)]+)\)?")
+    autoconf_pattern = re.compile(r"@([^@]+)@")
+    makefile_pattern = re.compile(r"\$\(?([^\s\)]+)\)?")
 
     @staticmethod
     def get(variabletext):
diff --git a/lpbuildd/sourcepackagerecipe.py b/lpbuildd/sourcepackagerecipe.py
index f440748..4781847 100644
--- a/lpbuildd/sourcepackagerecipe.py
+++ b/lpbuildd/sourcepackagerecipe.py
@@ -105,8 +105,8 @@ class SourcePackageRecipeBuildManager(DebianBuildManager):
         elif retcode == RETCODE_FAILURE_INSTALL_BUILD_DEPS:
             if not self.alreadyfailed:
                 rx = (
-                    'The following packages have unmet dependencies:\n'
-                    '.*: Depends: ([^ ]*( \([^)]*\))?)')
+                    r'The following packages have unmet dependencies:\n'
+                    r'.*: Depends: ([^ ]*( \([^)]*\))?)')
                 _, mo = self.searchLogContents([[rx, re.M]])
                 if mo:
                     self._builder.depFail(mo.group(1))