浏览代码

autoninja: fix strings with invalid escape sequences

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 <mark@chromium.org>
Reviewed-by: Philipp Wollermann <philwo@google.com>
Auto-Submit: Mark Mentovai <mark@chromium.org>
Mark Mentovai 11 月之前
父节点
当前提交
22df6f8e62
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      autoninja.py

+ 1 - 1
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()