From f807ad7947876b21c1d3396fb9b39357e8057ae9 Mon Sep 17 00:00:00 2001 From: John 'Warthog9' Hawley Date: Fri, 5 Apr 2024 10:04:13 -0700 Subject: [PATCH] fix: update regex matching to handle proper class escaping On Python 3.12 it's throwing compile warnings on the regex compiles: ``` spdx/verify-spdx-headers:8: SyntaxWarning: invalid escape sequence '\s' SPDX = re.compile(f'SPDX-License-Identifier:\s+({SLUG.pattern})') spdx/verify-spdx-headers:21: SyntaxWarning: invalid escape sequence '\s' pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\\s*$" spdx/verify-spdx-headers:21: SyntaxWarning: invalid escape sequence '\s' pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\s*$" ``` This escapes the the '\s' to be '\\s' instead as that is compliant, seems to compile correctly, and makes the warning go away. Quick checking on my own repos seemed to not break anything. Signed-off-by: John 'Warthog9' Hawley --- verify-spdx-headers | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/verify-spdx-headers b/verify-spdx-headers index 58ef007..e353645 100755 --- a/verify-spdx-headers +++ b/verify-spdx-headers @@ -5,7 +5,7 @@ import os import re SLUG = re.compile('[a-zA-Z0-9.-]+') -SPDX = re.compile(f'SPDX-License-Identifier:\s+({SLUG.pattern})') +SPDX = re.compile(f'SPDX-License-Identifier:\\s+({SLUG.pattern})') class Language: def __init__(self, *comments, shebang=False): @@ -18,7 +18,7 @@ class Language: if isinstance(comment, tuple): (init, fini) = comment - pattern = f"^{init}\s*{SPDX.pattern}\s*{fini}\s*$" + pattern = f"^{init}\\s*{SPDX.pattern}\\s*{fini}\\s*$" self.__match.append(re.compile(pattern)) def license(self, path):