Skip to content

Make Python re strings in tools/*.py be raw to avoid escape sequence warnings #2530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tools/check_board_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def read_defines_from(header_file, defines_dict):
if m:
validity_stack.pop()
continue

if validity_stack[-1]:
# look for "#include "foo.h"
m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line)
Expand Down Expand Up @@ -220,12 +220,12 @@ def read_defines_from(header_file, defines_dict):
line = re.sub(r"(?<=\S)\s*//.*$", "", line)

# look for board-detection comment
if re.match("^\s*// For board detection", line):
if re.match(r"^\s*// For board detection", line):
board_detection_is_next = True
continue

# check include-suggestion
m = re.match("^\s*// This header may be included by other board headers as \"(.+?)\"", line)
m = re.match(r"^\s*// This header may be included by other board headers as \"(.+?)\"", line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give the raw string ^\s*// This ... as \"(.+?)\", but the desired result is ^\s*// This ... as "(.+?)" without the \ before the ". In my PR I worked around this using r""".....""" which avoids the need for escaping the ".

if m:
include_suggestion = m.group(1)
if include_suggestion == expected_include_suggestion:
Expand Down Expand Up @@ -300,7 +300,7 @@ def read_defines_from(header_file, defines_dict):
if m:
validity_stack.pop()
continue

if validity_stack[-1]:
# look for "#include "foo.h"
m = re.match(r"""^\s*#include\s+"(.+?)"\s*$""", line)
Expand Down Expand Up @@ -484,7 +484,7 @@ def read_defines_from(header_file, defines_dict):
pins[define.resolved_value] = [define]

# check for invalid DEFAULT mappings
m = re.match("^(PICO_DEFAULT_([A-Z0-9]+))_([A-Z0-9]+)_PIN$", name)
m = re.match(r"^(PICO_DEFAULT_([A-Z0-9]+))_([A-Z0-9]+)_PIN$", name)
if m:
instance_name = m.group(1)
interface = m.group(2)
Expand All @@ -506,7 +506,7 @@ def read_defines_from(header_file, defines_dict):
raise Exception("{}:{} {} is set to {} which isn't a valid pin for {} on {} {}".format(board_header, define.lineno, name, define.resolved_value, function, interface, instance_num))

# check that each used DEFAULT interface includes (at least) the expected pin-functions
m = re.match("^PICO_DEFAULT_([A-Z0-9]+)$", name)
m = re.match(r"^PICO_DEFAULT_([A-Z0-9]+)$", name)
if m:
interface = m.group(1)
if interface not in allowed_interfaces:
Expand Down
2 changes: 1 addition & 1 deletion tools/extract_cmake_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def ValidateAttrs(config_name, config_attrs, file_path, linenum):
elif BASE_CMAKE_CONFIG_RE.search(line):
m = CMAKE_CONFIG_RE.match(line)
if not m:
if re.match("^\s*#\s*# ", line):
if re.match(r"^\s*#\s*# ", line):
logger.info("Possible misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line))
else:
raise Exception("Found misformatted {} at {}:{} ({})".format(BASE_CMAKE_CONFIG_NAME, file_path, linenum, line))
Expand Down
2 changes: 1 addition & 1 deletion tools/extract_cmake_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def process_commands(description, name, group, signature):
if any([';' in x for x in params]):
logger.error("{}:{} has a parameter description containing ';'".format(group, name))
# Check that all parameters are in the signature
signature_words = set(re.split('\W+', signature))
signature_words = set(re.split(r'\W+', signature))
for param in params:
param_name = param.split(' ', maxsplit=1)[0]
if param_name not in signature_words:
Expand Down