autoninja: fix strings with invalid escape sequences

Since 61fad561d6 (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 61fad561d6 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 <mark@chromium.org>
Reviewed-by: Philipp Wollermann <philwo@google.com>
Auto-Submit: Mark Mentovai <mark@chromium.org>
changes/59/5859159/2
Mark Mentovai 10 months ago committed by LUCI CQ
parent d43a3eb748
commit 22df6f8e62

@ -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()

Loading…
Cancel
Save