diff mbox series

[yocto-autobuilder-helper,1/3] scripts: send_qa_email: fix invalid regex syntax warning

Message ID 20240621155723.33600-2-alexis.lothore@bootlin.com
State New
Headers show
Series scripts: send_qa_email: skip regression report when missing base or target | expand

Commit Message

Alexis Lothoré June 21, 2024, 3:57 p.m. UTC
From: Alexis Lothoré <alexis.lothore@bootlin.com>

When send_qa_email is executed with python >= 3.12, the following warnings
are emitted:

/home/alexis/src/yocto_ci/yocto-autobuilder-helper/./scripts/send_qa_email.py:22: SyntaxWarning: invalid escape sequence '\d'
  p = re.compile('\d{8}-\d+')
/home/alexis/src/yocto_ci/yocto-autobuilder-helper/./scripts/send_qa_email.py:67: SyntaxWarning: invalid escape sequence '\/'
  tested_revision = re.match('refs\/tags\/.*\/\d+-g([a-f0-9]+)\/\d', latest_test_tag).group(1)

This warning has been introduced to replace the DeprecationWarning
initially raised on such escape code in string regex. Python 3.12 changelog
([1]) states that raw string must be used in this case. Update both
send_qa_email and its tests file.

[1] https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
 scripts/send_qa_email.py      | 4 ++--
 scripts/test_send_qa_email.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/scripts/send_qa_email.py b/scripts/send_qa_email.py
index 8d9250d555d4..e258fa131fcb 100755
--- a/scripts/send_qa_email.py
+++ b/scripts/send_qa_email.py
@@ -19,7 +19,7 @@  TEST_RESULTS_REPOSITORY_URL="git@push.yoctoproject.org:yocto-testresults"
 TEST_RESULTS_DRY_RUN_REPOSITORY_URL="git://git.yoctoproject.org/yocto-testresults"
 
 def is_release_version(version):
-    p = re.compile('\d{8}-\d+')
+    p = re.compile(r'\d{8}-\d+')
     return version is not None and p.match(version) is None
 
 def get_previous_tag(targetrepodir, version):
@@ -64,7 +64,7 @@  def get_last_tested_rev_on_branch(branch, test_results_url, log):
     tags_list = subprocess.check_output(["git", "ls-remote", "--refs", "-t", test_results_url, "refs/tags/" + branch + "/*"]).decode('utf-8').strip()
     latest_test_tag=tags_list.splitlines()[-1].split()[1]
     # From test results tag, extract Poky revision
-    tested_revision = re.match('refs\/tags\/.*\/\d+-g([a-f0-9]+)\/\d', latest_test_tag).group(1)
+    tested_revision = re.match(r'refs\/tags\/.*\/\d+-g([a-f0-9]+)\/\d', latest_test_tag).group(1)
     log.info(f"Last tested revision on branch {branch} is {tested_revision}")
     return tested_revision
 
diff --git a/scripts/test_send_qa_email.py b/scripts/test_send_qa_email.py
index 415d8cbbbccd..64ae80a1852d 100755
--- a/scripts/test_send_qa_email.py
+++ b/scripts/test_send_qa_email.py
@@ -31,8 +31,8 @@  class TestVersion(unittest.TestCase):
         {"input": {"version": "4.1_M1.rc1"}, "expected": "yocto-4.0"},
         {"input": {"version": "4.1_M1.rc4"}, "expected": "yocto-4.0"},
         {"input": {"version": "4.1.rc4"}, "expected": "yocto-4.0"},
-        {"input": {"version": "yocto-5.0_M1.rc1"}, "expected": "yocto-4.3(\.\d)?"},
-        {"input": {"version": "yocto-5.0_M1.rc2"}, "expected": "yocto-4.3(\.\d)?"},
+        {"input": {"version": "yocto-5.0_M1.rc1"}, "expected": r"yocto-4.3(\.\d)?"},
+        {"input": {"version": "yocto-5.0_M1.rc2"}, "expected": r"yocto-4.3(\.\d)?"},
         {"input": {"version": "yocto-5.0_M2.rc1"}, "expected": "5.0_M1"},
     ]