Skip to content

Commit 49b2bfe

Browse files
committed
Fix deprecation warnings for escape characters and local test failure
1 parent cf9ea39 commit 49b2bfe

File tree

12 files changed

+55
-54
lines changed

12 files changed

+55
-54
lines changed

wpiformat/test/test_licenseupdate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_licenseupdate():
166166
os.linesep + file_appendix)
167167
test.add_output(
168168
"/* Company Name */" + os.linesep + \
169-
"/* Copyright (c) 1992-2018 Company Name. All Rights Reserved. */" + os.linesep + \
169+
"/* Copyright (c) 1992-" + year + " Company Name. All Rights Reserved. */" + os.linesep + \
170170
os.linesep + file_appendix, True, True)
171171

172172
# Ensure excluded files won't be processed

wpiformat/wpiformat/bracecomment.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def run_pipeline(self, config_file, name, lines):
1616
linesep = Task.get_linesep(lines)
1717
output = ""
1818

19-
brace_prefix = "(?P<prefix>(extern|namespace)\s+[\w\"]*)"
20-
brace_postfix = "[ \t]*/(/|\*)[^\r\n]*"
19+
brace_prefix = r"(?P<prefix>(extern|namespace)\s+[\w\"]*)"
20+
brace_postfix = r"[ \t]*/(/|\*)[^\r\n]*"
2121

2222
brace_regex = regex.compile(
23-
r"/\*|\*/|//|\\\\|\\\"|\"|\\'|'|" + linesep + "|" + \
24-
"(" + brace_prefix + "\s*)?{|" # "{" with optional prefix
25-
"}(" + brace_postfix + ")?") # "}" with optional comment postfix
23+
r"/\*|\*/|//|\\\\|\\\"|\"|\\'|'|" + linesep + r"|" + \
24+
r"(" + brace_prefix + r"\s*)?{|" # "{" with optional prefix
25+
r"}(" + brace_postfix + r")?") # "}" with optional comment postfix
2626

2727
name_stack = []
2828
brace_count = 0

wpiformat/wpiformat/cidentlist.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def run_pipeline(self, config_file, name, lines):
3636
#
3737
# "def\\s+\w+" matches preprocessor directives "#ifdef" and "#ifndef" so
3838
# their contents aren't used as a return type.
39-
preproc_str = "#else|#endif|"
40-
comment_str = "/\*|\*/|//|" + linesep + "|"
39+
preproc_str = r"#else|#endif|"
40+
comment_str = r"/\*|\*/|//|" + linesep + r"|"
4141
string_str = r"\\\\|\\\"|\"|"
4242
char_str = r"\\'|'|"
43-
extern_str = "(?P<ext_decl>extern \"C(\+\+)?\")\s+(?P<ext_brace>\{)?|"
44-
braces_str = "\{|\}|;|def\s+\w+|\w+\s+\w+\s*(?P<paren>\(\))"
45-
postfix_str = "(?=\s*(;|\{))"
43+
extern_str = r"(?P<ext_decl>extern \"C(\+\+)?\")\s+(?P<ext_brace>\{)?|"
44+
braces_str = r"\{|\}|;|def\s+\w+|\w+\s+\w+\s*(?P<paren>\(\))"
45+
postfix_str = r"(?=\s*(;|\{))"
4646
token_regex = regex.compile(preproc_str + comment_str + string_str +
4747
char_str + extern_str + braces_str +
4848
postfix_str)

wpiformat/wpiformat/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def regex(self, *args):
8080

8181
if len(group_contents) == 0:
8282
# If regex string is empty, make regex match nothing
83-
return regex.compile("a^")
83+
return regex.compile(r"a^")
8484
else:
85-
return regex.compile("|".join(group_contents))
85+
return regex.compile(r"|".join(group_contents))
8686

8787
def is_c_file(self, name):
8888
"""Returns True if file is either C header or C source file.

wpiformat/wpiformat/includeguard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def run_pipeline(self, config_file, name, lines):
2626
output_list = lines_list
2727

2828
state = State.FINDING_IFNDEF
29-
ifndef_regex = regex.compile("#ifndef \w+", regex.ASCII)
30-
define_regex = regex.compile("#define \w+", regex.ASCII)
29+
ifndef_regex = regex.compile(r"#ifndef \w+", regex.ASCII)
30+
define_regex = regex.compile(r"#define \w+", regex.ASCII)
3131

3232
if_preproc_count = 0
3333
for i in range(len(lines_list)):
@@ -96,9 +96,9 @@ def make_include_guard(self, config_file, name):
9696
include_root) and len(include_root) > len(prefix):
9797
prefix = include_root
9898
guard_path += guard_root[len(prefix):]
99-
return (regex.sub("[^a-zA-Z0-9]", "_", guard_path).upper() +
99+
return (regex.sub(r"[^a-zA-Z0-9]", "_", guard_path).upper() +
100100
"_").lstrip("_")
101101

102102
# No include guard roots matched, so append full name
103103
guard_path += guard_root
104-
return regex.sub("[^a-zA-Z0-9]", "_", guard_path).upper() + "_"
104+
return regex.sub(r"[^a-zA-Z0-9]", "_", guard_path).upper() + "_"

wpiformat/wpiformat/includeorder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self):
3434
]
3535

3636
# Header type 1: C system headers
37-
self.c_sys_regex = regex.compile("<[a-z][A-Za-z0-9/_-]*\.h>")
37+
self.c_sys_regex = regex.compile(r"<[a-z][A-Za-z0-9/_-]*\.h>")
3838

3939
# Header type 2: C++ standard library headers
4040
self.cpp_std = [
@@ -61,13 +61,13 @@ def __init__(self):
6161
#
6262
# Header type 4: Project headers
6363
# They use double quotes (all other headers)
64-
self.header_regex = regex.compile("(?P<comment>//\s*)?"
65-
"\#include\s*"
66-
"(?P<header>"
67-
"(?P<open_bracket><|\")"
68-
"(?P<name>[^>\"]*)"
69-
"(?P<close_bracket>>|\"))"
70-
"(?P<postfix>.*)$")
64+
self.header_regex = regex.compile(r"(?P<comment>//\s*)?"
65+
r"\#include\s*"
66+
r"(?P<header>"
67+
r"(?P<open_bracket><|\")"
68+
r"(?P<name>[^>\"]*)"
69+
r"(?P<close_bracket>>|\"))"
70+
r"(?P<postfix>.*)$")
7171

7272
def should_process_file(self, config_file, name):
7373
return config_file.is_c_file(name) or config_file.is_cpp_file(name)

wpiformat/wpiformat/javaclass.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def run_pipeline(self, config_file, name, lines):
1818
pos = 0
1919

2020
# Match two or more line separators
21-
token_str = "/\*|\*/|//|" + linesep + "|class\s[\w\d\s]*{" + linesep + "(?P<extra>(" + linesep + ")+)"
21+
token_str = r"/\*|\*/|//|" + linesep + r"|class\s[\w\d\s]*{" + \
22+
linesep + r"(?P<extra>(" + linesep + r")+)"
2223
token_regex = regex.compile(token_str)
2324

2425
in_multicomment = False

wpiformat/wpiformat/jni.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ def map_jni_type(self, type_name):
6262
def run_pipeline(self, config_file, name, lines):
6363
linesep = Task.get_linesep(lines)
6464

65-
regex_str_sig = "(/\*(?>(.|\n)*?\*/)\s+)?" + \
66-
"JNIEXPORT\s+(?P<ret>\w+)\s+JNICALL\s+" + \
67-
"(?P<func>Java_\w+)\s*\(\s*" + \
68-
"(?P<env_type>JNIEnv\s*\*\s*)" + \
69-
"(?P<env_name>\w+)?,\s*jclass\s*(?P<jclass_name>\w*)?"
65+
regex_str_sig = r"(/\*(?>(.|\n)*?\*/)\s+)?" + \
66+
r"JNIEXPORT\s+(?P<ret>\w+)\s+JNICALL\s+" + \
67+
r"(?P<func>Java_\w+)\s*\(\s*" + \
68+
r"(?P<env_type>JNIEnv\s*\*\s*)" + \
69+
r"(?P<env_name>\w+)?,\s*jclass\s*(?P<jclass_name>\w*)?"
7070
regex_sig = regex.compile(regex_str_sig)
7171

72-
regex_str_func = "Java_(?P<class>\w+)_(?P<method>[^_]+)$"
72+
regex_str_func = r"Java_(?P<class>\w+)_(?P<method>[^_]+)$"
7373
regex_func = regex.compile(regex_str_func)
7474

7575
# Matches a comma followed by the type, an optional variable name, and
7676
# an optional closing parenthesis
77-
regex_str_arg = (", \s* (?P<arg>(?P<arg_type>[\w\*]+)(\s+ \w+)?)|\)\s*"
78-
"(?P<trailing>{|;)")
77+
regex_str_arg = (r", \s* (?P<arg>(?P<arg_type>[\w\*]+)(\s+ \w+)?)|\)\s*"
78+
r"(?P<trailing>{|;)")
7979
regex_arg = regex.compile(regex_str_arg, regex.VERBOSE)
8080

8181
output = ""

wpiformat/wpiformat/licenseupdate.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def __try_regex(self, lines, license_template):
4040

4141
# Convert the license template to a regex
4242
license_rgxstr = "^" + linesep.join(license_template)
43-
license_rgxstr = license_rgxstr.replace("*", "\*").replace(
44-
".", "\.").replace("(", "\(").replace(")", "\)").replace(
43+
license_rgxstr = license_rgxstr.replace("*", r"\*").replace(
44+
".", r"\.").replace("(", r"\(").replace(")", r"\)").replace(
4545
"{year}",
46-
"(?P<year>[0-9]+)(-[0-9]+)?").replace("{padding}", "[ ]*")
46+
r"(?P<year>[0-9]+)(-[0-9]+)?").replace("{padding}", "[ ]*")
4747
license_rgx = regex.compile(license_rgxstr, regex.M)
4848

4949
# Compare license
@@ -82,7 +82,7 @@ def __try_string_search(self, lines, license_template):
8282
license_end = 0
8383

8484
# Regex for tokenizing on comment boundaries
85-
token_regex = regex.compile("/\*|\*/|^//")
85+
token_regex = regex.compile(r"/\*|\*/|^//")
8686

8787
in_multiline_comment = False
8888
for line in stripped_lines:
@@ -114,7 +114,7 @@ def __try_string_search(self, lines, license_template):
114114
appendix_part = \
115115
linesep + linesep.join(stripped_lines[license_end:]).lstrip()
116116

117-
year_regex = regex.compile("Copyright \(c\)(?>.*?\s(20..))")
117+
year_regex = regex.compile(r"Copyright \(c\)(?>.*?\s(20..))")
118118
for line in license_part.split(linesep):
119119
match = year_regex.search(line)
120120
# If license contains copyright pattern, extract the first year

wpiformat/wpiformat/stdlib.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ def __init__(self, name, func_names=set(), type_regexes=[],
2424
self.func_names = func_names
2525
self.add_prefix = add_prefix
2626

27-
regex_prefix = ""
27+
regex_prefix = r""
2828
if add_prefix:
29-
self.prefix = "std::"
30-
self.type_sub = "std::\g<1>"
31-
regex_prefix = ""
29+
self.prefix = r"std::"
30+
self.type_sub = r"std::\g<1>"
31+
regex_prefix = r""
3232
else:
33-
self.prefix = ""
34-
self.type_sub = "\g<1>"
35-
regex_prefix = "std::"
33+
self.prefix = r""
34+
self.type_sub = r"\g<1>"
35+
regex_prefix = r"std::"
3636

3737
if func_names != []:
3838
# Matches C standard library function uses. C standard library
@@ -42,9 +42,9 @@ def __init__(self, name, func_names=set(), type_regexes=[],
4242
self.func_regex = regex.compile(
4343
# Preceded by nonword character and spaces, comma, arithmetic
4444
# operators, or "("
45-
"(?:[^\w]\s+|,|\(|\+|-|\*|/)" + regex_prefix +
46-
"([a-z][a-z0-9]*)" + # C stdlib function name
47-
"(?:\()" # Followed by open parenthesis
45+
r"(?:[^\w]\s+|,|\(|\+|-|\*|/)" + regex_prefix +
46+
r"([a-z][a-z0-9]*)" + # C stdlib function name
47+
r"(?:\()" # Followed by open parenthesis
4848
)
4949
else:
5050
self.func_regex = None
@@ -54,13 +54,13 @@ def __init__(self, name, func_names=set(), type_regexes=[],
5454

5555
# Preceded by beginning of file, "<" (template), " ", ",", "(", or
5656
# line separator and optional spaces
57-
lookbehind = "(?<=^|\<| |,|\(|\n)"
57+
lookbehind = r"(?<=^|\<| |,|\(|\n)"
5858

59-
type_names = regex_prefix + "(" + "|".join(type_regexes) + ")"
59+
type_names = regex_prefix + r"(" + r"|".join(type_regexes) + r")"
6060

6161
# Followed by optional spaces and ">", ")", ",", ";", or pointer
6262
# asterisks
63-
lookahead = "(?=(\s*(\>|\)|,|;|\*+))|\s)"
63+
lookahead = r"(?=(\s*(\>|\)|,|;|\*+))|\s)"
6464

6565
self.type_regex = regex.compile(lookbehind + type_names + lookahead)
6666
else:

0 commit comments

Comments
 (0)