Message ID | 20230816122133.1231599-1-vishalc@linux.ibm.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | Fix invalid escape sequence warnings | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch, async |
bpf/vmtest-bpf-next-VM_Test-29 | success | Logs for veristat |
bpf/vmtest-bpf-next-PR | success | PR summary |
bpf/vmtest-bpf-next-VM_Test-0 | success | Logs for ShellCheck |
bpf/vmtest-bpf-next-VM_Test-3 | success | Logs for build for x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-4 | success | Logs for build for x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-5 | success | Logs for set-matrix |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for build for aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for build for s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-18 | success | Logs for test_progs_no_alu32_parallel on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-8 | success | Logs for test_maps on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-14 | success | Logs for test_progs_no_alu32 on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-24 | success | Logs for test_verifier on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-27 | success | Logs for test_verifier on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-22 | success | Logs for test_progs_parallel on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-21 | success | Logs for test_progs_parallel on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-28 | success | Logs for veristat |
bpf/vmtest-bpf-next-VM_Test-26 | success | Logs for test_verifier on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-16 | success | Logs for test_progs_no_alu32 on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-19 | success | Logs for test_progs_no_alu32_parallel on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-6 | success | Logs for test_maps on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-9 | success | Logs for test_maps on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-10 | success | Logs for test_progs on aarch64 with gcc |
bpf/vmtest-bpf-next-VM_Test-13 | success | Logs for test_progs on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-17 | success | Logs for test_progs_no_alu32 on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-12 | success | Logs for test_progs on x86_64 with gcc |
bpf/vmtest-bpf-next-VM_Test-20 | success | Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-23 | success | Logs for test_progs_parallel on x86_64 with llvm-16 |
bpf/vmtest-bpf-next-VM_Test-25 | success | Logs for test_verifier on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-15 | success | Logs for test_progs_no_alu32 on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-11 | success | Logs for test_progs on s390x with gcc |
bpf/vmtest-bpf-next-VM_Test-7 | success | Logs for test_maps on s390x with gcc |
On Wed, Aug 16, 2023 at 5:22 AM Vishal Chourasia <vishalc@linux.ibm.com> wrote: > > The Python script `bpf_doc.py` uses regular expressions with > backslashes in string literals, which results in SyntaxWarnings > during its execution. > > This patch addresses these warnings by converting relevant string > literals to raw strings, which interpret backslashes as literal > characters. This ensures that the regular expressions are parsed > correctly without causing any warnings. > > Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com> > Reported-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> > > --- > scripts/bpf_doc.py | 34 +++++++++++++++++----------------- > 1 file changed, 17 insertions(+), 17 deletions(-) > > diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py > index eaae2ce78381..dfd819c952b2 100755 > --- a/scripts/bpf_doc.py > +++ b/scripts/bpf_doc.py > @@ -59,9 +59,9 @@ class Helper(APIElement): > Break down helper function protocol into smaller chunks: return type, > name, distincts arguments. > """ > - arg_re = re.compile('((\w+ )*?(\w+|...))( (\**)(\w+))?$') > + arg_re = re.compile(r'((\w+ )*?(\w+|...))( (\**)(\w+))?$') > res = {} > - proto_re = re.compile('(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') > + proto_re = re.compile(r'(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') > > capture = proto_re.match(self.proto) > res['ret_type'] = capture.group(1) > @@ -114,11 +114,11 @@ class HeaderParser(object): > return Helper(proto=proto, desc=desc, ret=ret) > > def parse_symbol(self): > - p = re.compile(' \* ?(BPF\w+)$') > + p = re.compile(r' \* ?(BPF\w+)$') > capture = p.match(self.line) > if not capture: > raise NoSyscallCommandFound > - end_re = re.compile(' \* ?NOTES$') > + end_re = re.compile(r' \* ?NOTES$') > end = end_re.match(self.line) > if end: > raise NoSyscallCommandFound > @@ -133,7 +133,7 @@ class HeaderParser(object): > # - Same as above, with "const" and/or "struct" in front of type > # - "..." (undefined number of arguments, for bpf_trace_printk()) > # There is at least one term ("void"), and at most five arguments. > - p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') > + p = re.compile(r' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') > capture = p.match(self.line) > if not capture: > raise NoHelperFound > @@ -141,7 +141,7 @@ class HeaderParser(object): > return capture.group(1) > > def parse_desc(self, proto): > - p = re.compile(' \* ?(?:\t| {5,8})Description$') > + p = re.compile(r' \* ?(?:\t| {5,8})Description$') > capture = p.match(self.line) > if not capture: > raise Exception("No description section found for " + proto) > @@ -154,7 +154,7 @@ class HeaderParser(object): > if self.line == ' *\n': > desc += '\n' > else: > - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') > + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') > capture = p.match(self.line) > if capture: > desc_present = True > @@ -167,7 +167,7 @@ class HeaderParser(object): > return desc > > def parse_ret(self, proto): > - p = re.compile(' \* ?(?:\t| {5,8})Return$') > + p = re.compile(r' \* ?(?:\t| {5,8})Return$') > capture = p.match(self.line) > if not capture: > raise Exception("No return section found for " + proto) > @@ -180,7 +180,7 @@ class HeaderParser(object): > if self.line == ' *\n': > ret += '\n' > else: > - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') > + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') > capture = p.match(self.line) > if capture: > ret_present = True > @@ -219,12 +219,12 @@ class HeaderParser(object): > self.seek_to('enum bpf_cmd {', > 'Could not find start of bpf_cmd enum', 0) > # Searches for either one or more BPF\w+ enums > - bpf_p = re.compile('\s*(BPF\w+)+') > + bpf_p = re.compile(r'\s*(BPF\w+)+') > # Searches for an enum entry assigned to another entry, > # for e.g. BPF_PROG_RUN = BPF_PROG_TEST_RUN, which is > # not documented hence should be skipped in check to > # determine if the right number of syscalls are documented > - assign_p = re.compile('\s*(BPF\w+)\s*=\s*(BPF\w+)') > + assign_p = re.compile(r'\s*(BPF\w+)\s*=\s*(BPF\w+)') > bpf_cmd_str = '' > while True: > capture = assign_p.match(self.line) > @@ -239,7 +239,7 @@ class HeaderParser(object): > break > self.line = self.reader.readline() > # Find the number of occurences of BPF\w+ > - self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) > + self.enum_syscalls = re.findall(r'(BPF\w+)+', bpf_cmd_str) > > def parse_desc_helpers(self): > self.seek_to(helpersDocStart, > @@ -263,7 +263,7 @@ class HeaderParser(object): > self.seek_to('#define ___BPF_FUNC_MAPPER(FN, ctx...)', > 'Could not find start of eBPF helper definition list') > # Searches for one FN(\w+) define or a backslash for newline > - p = re.compile('\s*FN\((\w+), (\d+), ##ctx\)|\\\\') > + p = re.compile(r'\s*FN\((\w+), (\d+), ##ctx\)|\\\\') > fn_defines_str = '' > i = 0 > while True: > @@ -278,7 +278,7 @@ class HeaderParser(object): > break > self.line = self.reader.readline() > # Find the number of occurences of FN(\w+) > - self.define_unique_helpers = re.findall('FN\(\w+, \d+, ##ctx\)', fn_defines_str) > + self.define_unique_helpers = re.findall(r'FN\(\w+, \d+, ##ctx\)', fn_defines_str) > > def validate_helpers(self): > last_helper = '' > @@ -425,7 +425,7 @@ class PrinterRST(Printer): > try: > cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch', > '-L', > - '/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] > + r'/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] this one is not a regex, do we still need to change it? > date = subprocess.run(cmd, cwd=linuxRoot, > capture_output=True, check=True) > return date.stdout.decode().rstrip() > @@ -496,7 +496,7 @@ HELPERS > date=lastUpdate)) > > def print_footer(self): > - footer = ''' > + footer = r''' same here, not a regex string > EXAMPLES > ======== > > @@ -598,7 +598,7 @@ SEE ALSO > one_arg = '{}{}'.format(comma, a['type']) > if a['name']: > if a['star']: > - one_arg += ' {}**\ '.format(a['star'].replace('*', '\\*')) > + one_arg += r' {}**\ '.format(a['star'].replace('*', '\\*')) and this one as well? > else: > one_arg += '** ' > one_arg += '*{}*\\ **'.format(a['name']) > -- > 2.41.0 >
* Vishal Chourasia <vishalc@linux.ibm.com> [2023-08-16 17:51:33]: > The Python script `bpf_doc.py` uses regular expressions with > backslashes in string literals, which results in SyntaxWarnings > during its execution. > > This patch addresses these warnings by converting relevant string > literals to raw strings, which interpret backslashes as literal > characters. This ensures that the regular expressions are parsed > correctly without causing any warnings. > > Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com> > Reported-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Thanks, Works for me Tested-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
On 8/23/23 05:00, Andrii Nakryiko wrote: > On Wed, Aug 16, 2023 at 5:22 AM Vishal Chourasia <vishalc@linux.ibm.com> wrote: >> >> The Python script `bpf_doc.py` uses regular expressions with >> backslashes in string literals, which results in SyntaxWarnings >> during its execution. >> >> This patch addresses these warnings by converting relevant string >> literals to raw strings, which interpret backslashes as literal >> characters. This ensures that the regular expressions are parsed >> correctly without causing any warnings. >> >> Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com> >> Reported-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> >> >> --- >> scripts/bpf_doc.py | 34 +++++++++++++++++----------------- >> 1 file changed, 17 insertions(+), 17 deletions(-) >> >> diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py >> index eaae2ce78381..dfd819c952b2 100755 >> --- a/scripts/bpf_doc.py >> +++ b/scripts/bpf_doc.py >> @@ -59,9 +59,9 @@ class Helper(APIElement): >> Break down helper function protocol into smaller chunks: return type, >> name, distincts arguments. >> """ >> - arg_re = re.compile('((\w+ )*?(\w+|...))( (\**)(\w+))?$') >> + arg_re = re.compile(r'((\w+ )*?(\w+|...))( (\**)(\w+))?$') >> res = {} >> - proto_re = re.compile('(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') >> + proto_re = re.compile(r'(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') >> >> capture = proto_re.match(self.proto) >> res['ret_type'] = capture.group(1) >> @@ -114,11 +114,11 @@ class HeaderParser(object): >> return Helper(proto=proto, desc=desc, ret=ret) >> >> def parse_symbol(self): >> - p = re.compile(' \* ?(BPF\w+)$') >> + p = re.compile(r' \* ?(BPF\w+)$') >> capture = p.match(self.line) >> if not capture: >> raise NoSyscallCommandFound >> - end_re = re.compile(' \* ?NOTES$') >> + end_re = re.compile(r' \* ?NOTES$') >> end = end_re.match(self.line) >> if end: >> raise NoSyscallCommandFound >> @@ -133,7 +133,7 @@ class HeaderParser(object): >> # - Same as above, with "const" and/or "struct" in front of type >> # - "..." (undefined number of arguments, for bpf_trace_printk()) >> # There is at least one term ("void"), and at most five arguments. >> - p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') >> + p = re.compile(r' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') >> capture = p.match(self.line) >> if not capture: >> raise NoHelperFound >> @@ -141,7 +141,7 @@ class HeaderParser(object): >> return capture.group(1) >> >> def parse_desc(self, proto): >> - p = re.compile(' \* ?(?:\t| {5,8})Description$') >> + p = re.compile(r' \* ?(?:\t| {5,8})Description$') >> capture = p.match(self.line) >> if not capture: >> raise Exception("No description section found for " + proto) >> @@ -154,7 +154,7 @@ class HeaderParser(object): >> if self.line == ' *\n': >> desc += '\n' >> else: >> - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') >> + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') >> capture = p.match(self.line) >> if capture: >> desc_present = True >> @@ -167,7 +167,7 @@ class HeaderParser(object): >> return desc >> >> def parse_ret(self, proto): >> - p = re.compile(' \* ?(?:\t| {5,8})Return$') >> + p = re.compile(r' \* ?(?:\t| {5,8})Return$') >> capture = p.match(self.line) >> if not capture: >> raise Exception("No return section found for " + proto) >> @@ -180,7 +180,7 @@ class HeaderParser(object): >> if self.line == ' *\n': >> ret += '\n' >> else: >> - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') >> + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') >> capture = p.match(self.line) >> if capture: >> ret_present = True >> @@ -219,12 +219,12 @@ class HeaderParser(object): >> self.seek_to('enum bpf_cmd {', >> 'Could not find start of bpf_cmd enum', 0) >> # Searches for either one or more BPF\w+ enums >> - bpf_p = re.compile('\s*(BPF\w+)+') >> + bpf_p = re.compile(r'\s*(BPF\w+)+') >> # Searches for an enum entry assigned to another entry, >> # for e.g. BPF_PROG_RUN = BPF_PROG_TEST_RUN, which is >> # not documented hence should be skipped in check to >> # determine if the right number of syscalls are documented >> - assign_p = re.compile('\s*(BPF\w+)\s*=\s*(BPF\w+)') >> + assign_p = re.compile(r'\s*(BPF\w+)\s*=\s*(BPF\w+)') >> bpf_cmd_str = '' >> while True: >> capture = assign_p.match(self.line) >> @@ -239,7 +239,7 @@ class HeaderParser(object): >> break >> self.line = self.reader.readline() >> # Find the number of occurences of BPF\w+ >> - self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) >> + self.enum_syscalls = re.findall(r'(BPF\w+)+', bpf_cmd_str) >> >> def parse_desc_helpers(self): >> self.seek_to(helpersDocStart, >> @@ -263,7 +263,7 @@ class HeaderParser(object): >> self.seek_to('#define ___BPF_FUNC_MAPPER(FN, ctx...)', >> 'Could not find start of eBPF helper definition list') >> # Searches for one FN(\w+) define or a backslash for newline >> - p = re.compile('\s*FN\((\w+), (\d+), ##ctx\)|\\\\') >> + p = re.compile(r'\s*FN\((\w+), (\d+), ##ctx\)|\\\\') >> fn_defines_str = '' >> i = 0 >> while True: >> @@ -278,7 +278,7 @@ class HeaderParser(object): >> break >> self.line = self.reader.readline() >> # Find the number of occurences of FN(\w+) >> - self.define_unique_helpers = re.findall('FN\(\w+, \d+, ##ctx\)', fn_defines_str) >> + self.define_unique_helpers = re.findall(r'FN\(\w+, \d+, ##ctx\)', fn_defines_str) >> >> def validate_helpers(self): >> last_helper = '' >> @@ -425,7 +425,7 @@ class PrinterRST(Printer): >> try: >> cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch', >> '-L', >> - '/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] >> + r'/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] > > this one is not a regex, do we still need to change it? Indeed, it's essential to modify this aspect, especially since we're encountering warnings when compiling the kernel with Python 3.12. The choice between using an 'r'-prefixed string or manually escaping each backslash is largely a matter of preference. It's worth noting that the 'r' prefix is not only commonly employed for regular expressions but also in contexts where backslashes should be treated as literal characters rather than escape sequences. Should I send another patch escaping backslash for non regex string literals? >> date = subprocess.run(cmd, cwd=linuxRoot, >> capture_output=True, check=True) >> return date.stdout.decode().rstrip() >> @@ -496,7 +496,7 @@ HELPERS >> date=lastUpdate)) >> >> def print_footer(self): >> - footer = ''' >> + footer = r''' > > same here, not a regex string > >> EXAMPLES >> ======== >> >> @@ -598,7 +598,7 @@ SEE ALSO >> one_arg = '{}{}'.format(comma, a['type']) >> if a['name']: >> if a['star']: >> - one_arg += ' {}**\ '.format(a['star'].replace('*', '\\*')) >> + one_arg += r' {}**\ '.format(a['star'].replace('*', '\\*')) > > and this one as well? > >> else: >> one_arg += '** ' >> one_arg += '*{}*\\ **'.format(a['name']) >> -- >> 2.41.0 >>
diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index eaae2ce78381..dfd819c952b2 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -59,9 +59,9 @@ class Helper(APIElement): Break down helper function protocol into smaller chunks: return type, name, distincts arguments. """ - arg_re = re.compile('((\w+ )*?(\w+|...))( (\**)(\w+))?$') + arg_re = re.compile(r'((\w+ )*?(\w+|...))( (\**)(\w+))?$') res = {} - proto_re = re.compile('(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') + proto_re = re.compile(r'(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$') capture = proto_re.match(self.proto) res['ret_type'] = capture.group(1) @@ -114,11 +114,11 @@ class HeaderParser(object): return Helper(proto=proto, desc=desc, ret=ret) def parse_symbol(self): - p = re.compile(' \* ?(BPF\w+)$') + p = re.compile(r' \* ?(BPF\w+)$') capture = p.match(self.line) if not capture: raise NoSyscallCommandFound - end_re = re.compile(' \* ?NOTES$') + end_re = re.compile(r' \* ?NOTES$') end = end_re.match(self.line) if end: raise NoSyscallCommandFound @@ -133,7 +133,7 @@ class HeaderParser(object): # - Same as above, with "const" and/or "struct" in front of type # - "..." (undefined number of arguments, for bpf_trace_printk()) # There is at least one term ("void"), and at most five arguments. - p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') + p = re.compile(r' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$') capture = p.match(self.line) if not capture: raise NoHelperFound @@ -141,7 +141,7 @@ class HeaderParser(object): return capture.group(1) def parse_desc(self, proto): - p = re.compile(' \* ?(?:\t| {5,8})Description$') + p = re.compile(r' \* ?(?:\t| {5,8})Description$') capture = p.match(self.line) if not capture: raise Exception("No description section found for " + proto) @@ -154,7 +154,7 @@ class HeaderParser(object): if self.line == ' *\n': desc += '\n' else: - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') capture = p.match(self.line) if capture: desc_present = True @@ -167,7 +167,7 @@ class HeaderParser(object): return desc def parse_ret(self, proto): - p = re.compile(' \* ?(?:\t| {5,8})Return$') + p = re.compile(r' \* ?(?:\t| {5,8})Return$') capture = p.match(self.line) if not capture: raise Exception("No return section found for " + proto) @@ -180,7 +180,7 @@ class HeaderParser(object): if self.line == ' *\n': ret += '\n' else: - p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') + p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)') capture = p.match(self.line) if capture: ret_present = True @@ -219,12 +219,12 @@ class HeaderParser(object): self.seek_to('enum bpf_cmd {', 'Could not find start of bpf_cmd enum', 0) # Searches for either one or more BPF\w+ enums - bpf_p = re.compile('\s*(BPF\w+)+') + bpf_p = re.compile(r'\s*(BPF\w+)+') # Searches for an enum entry assigned to another entry, # for e.g. BPF_PROG_RUN = BPF_PROG_TEST_RUN, which is # not documented hence should be skipped in check to # determine if the right number of syscalls are documented - assign_p = re.compile('\s*(BPF\w+)\s*=\s*(BPF\w+)') + assign_p = re.compile(r'\s*(BPF\w+)\s*=\s*(BPF\w+)') bpf_cmd_str = '' while True: capture = assign_p.match(self.line) @@ -239,7 +239,7 @@ class HeaderParser(object): break self.line = self.reader.readline() # Find the number of occurences of BPF\w+ - self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) + self.enum_syscalls = re.findall(r'(BPF\w+)+', bpf_cmd_str) def parse_desc_helpers(self): self.seek_to(helpersDocStart, @@ -263,7 +263,7 @@ class HeaderParser(object): self.seek_to('#define ___BPF_FUNC_MAPPER(FN, ctx...)', 'Could not find start of eBPF helper definition list') # Searches for one FN(\w+) define or a backslash for newline - p = re.compile('\s*FN\((\w+), (\d+), ##ctx\)|\\\\') + p = re.compile(r'\s*FN\((\w+), (\d+), ##ctx\)|\\\\') fn_defines_str = '' i = 0 while True: @@ -278,7 +278,7 @@ class HeaderParser(object): break self.line = self.reader.readline() # Find the number of occurences of FN(\w+) - self.define_unique_helpers = re.findall('FN\(\w+, \d+, ##ctx\)', fn_defines_str) + self.define_unique_helpers = re.findall(r'FN\(\w+, \d+, ##ctx\)', fn_defines_str) def validate_helpers(self): last_helper = '' @@ -425,7 +425,7 @@ class PrinterRST(Printer): try: cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch', '-L', - '/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] + r'/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] date = subprocess.run(cmd, cwd=linuxRoot, capture_output=True, check=True) return date.stdout.decode().rstrip() @@ -496,7 +496,7 @@ HELPERS date=lastUpdate)) def print_footer(self): - footer = ''' + footer = r''' EXAMPLES ======== @@ -598,7 +598,7 @@ SEE ALSO one_arg = '{}{}'.format(comma, a['type']) if a['name']: if a['star']: - one_arg += ' {}**\ '.format(a['star'].replace('*', '\\*')) + one_arg += r' {}**\ '.format(a['star'].replace('*', '\\*')) else: one_arg += '** ' one_arg += '*{}*\\ **'.format(a['name'])
The Python script `bpf_doc.py` uses regular expressions with backslashes in string literals, which results in SyntaxWarnings during its execution. This patch addresses these warnings by converting relevant string literals to raw strings, which interpret backslashes as literal characters. This ensures that the regular expressions are parsed correctly without causing any warnings. Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com> Reported-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> --- scripts/bpf_doc.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)