From 22df6f8e622dc3e8df8dc8b5d3e3503b169af78e Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Fri, 13 Sep 2024 16:08:45 +0000 Subject: [PATCH] autoninja: fix strings with invalid escape sequences MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 61fad561d63c (https://chromium-review.googlesource.com/c/5848450, 2024-09-11), autoninja under Python 3.12 presents these warnings: ``` …/autoninja.py:73: SyntaxWarning: invalid escape sequence '\s' m = re.match('instance\s*=\s*projects/([^/]*)/instances/.*', line) …/autoninja.py:92: SyntaxWarning: invalid escape sequence '\s' m = re.match('SISO_PROJECT=\s*(\S*)\s*', line) ``` This warning appears in Python 3.12 ([1], [2], [3]). '\s' and '\S' are not valid escape sequences in strings. r'\s' and r'\S' are valid in regular expressions, but outside of raw strings, they would need to be written as '\\s' and '\\S'. There is no reason to not use raw strings in this case, so the new regular expression pattern strings introduced in 61fad561d63c are changed to raw strings. [1] https://docs.python.org/3/whatsnew/3.12.html#:~:text=A%20backslash%2Dcharacter%20pair%20that%20is%20not%20a%20valid%20escape%20sequence%20now%20generates%20a%20SyntaxWarning%2C%20instead%20of%20DeprecationWarning. [2] https://github.com/python/cpython/issues/98401 [3] https://github.com/python/cpython/pull/99011 Bug: b/364318216 Change-Id: I0f237976fe9c39208541ae78205f5bdbf126fa82 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5859159 Commit-Queue: Mark Mentovai Reviewed-by: Philipp Wollermann Auto-Submit: Mark Mentovai --- autoninja.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoninja.py b/autoninja.py index 7e57e4fc3..dc3354640 100755 --- a/autoninja.py +++ b/autoninja.py @@ -62,7 +62,7 @@ def _reclient_rbe_project(): """Returns RBE project used by reclient.""" instance = os.environ.get('RBE_instance') if instance: - m = re.match(instance, 'projects/([^/]*)/instances/.*') + m = re.match(instance, r'projects/([^/]*)/instances/.*') if m: return m[1] reproxy_cfg_path = reclient_helper.find_reclient_cfg()