diff mbox series

[ovs-dev,5/6] build-aux/extract-ofp-msgs: Fix flake8 and syntax errors.

Message ID 20231030201054.136934-6-i.maximets@ovn.org
State Accepted
Commit 20e6309ba66fc9e39525a1fefae6c3702212d7a7
Delegated to: Ilya Maximets
Headers show
Series build-aux: Fix flake8 and syntax issues with python 3.12. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Ilya Maximets Oct. 30, 2023, 8:10 p.m. UTC
A few general style issues like extra spacing and line length,
semicolons at the end of the line and unused variable 'raw_types'.
And a few invalid escape sequences, which are not actual escape
sequences, but cause actual syntax warnings starting python 3.12
and will eventually become syntax errors [1]:

 extract-ofp-msgs:118: SyntaxWarning: invalid escape sequence '\s'
  m = re.match('\s+(?:OFPRAW_%s)(\d*)_([A-Z0-9_]+),?$' % type_,

These are fixed by converting to raw strings.

[1] https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 build-aux/extract-ofp-msgs | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Comments

Eelco Chaudron Oct. 31, 2023, 8:23 a.m. UTC | #1
On 30 Oct 2023, at 21:10, Ilya Maximets wrote:

> A few general style issues like extra spacing and line length,
> semicolons at the end of the line and unused variable 'raw_types'.
> And a few invalid escape sequences, which are not actual escape
> sequences, but cause actual syntax warnings starting python 3.12
> and will eventually become syntax errors [1]:
>
>  extract-ofp-msgs:118: SyntaxWarning: invalid escape sequence '\s'
>   m = re.match('\s+(?:OFPRAW_%s)(\d*)_([A-Z0-9_]+),?$' % type_,
>
> These are fixed by converting to raw strings.
>
> [1] https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences
>
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Thanks for fixing this, and the changes look good to me.

Acked-by: Eelco Chaudron <echaudro@redhat.com>
diff mbox series

Patch

diff --git a/build-aux/extract-ofp-msgs b/build-aux/extract-ofp-msgs
index 6b3295cf6..c26ea1d35 100755
--- a/build-aux/extract-ofp-msgs
+++ b/build-aux/extract-ofp-msgs
@@ -24,6 +24,9 @@  OFPT11_STATS_REQUEST = 18
 OFPT11_STATS_REPLY = 19
 OFPST_VENDOR = 0xffff
 
+n_errors = 0
+
+
 def decode_version_range(range):
     if range in VERSION:
         return (VERSION[range], VERSION[range])
@@ -35,6 +38,7 @@  def decode_version_range(range):
         a, b = re.match(r'^([^-]+)-([^-]+)$', range).groups()
         return (VERSION[a], VERSION[b])
 
+
 def get_line():
     global line
     global line_number
@@ -43,16 +47,18 @@  def get_line():
     if line == "":
         fatal("unexpected end of input")
 
-n_errors = 0
+
 def error(msg):
     global n_errors
     sys.stderr.write("%s:%d: %s\n" % (file_name, line_number, msg))
     n_errors += 1
 
+
 def fatal(msg):
     error(msg)
     sys.exit(1)
 
+
 def usage():
     argv0 = os.path.basename(sys.argv[0])
     print('''\
@@ -65,6 +71,7 @@  only controls #line directives in the output.\
 ''' % {"argv0": argv0})
     sys.exit(0)
 
+
 def make_sizeof(s):
     m = re.match(r'(.*) up to (.*)', s)
     if m:
@@ -73,9 +80,8 @@  def make_sizeof(s):
     else:
         return "sizeof(%s)" % s
 
-def extract_ofp_msgs(output_file_name):
-    raw_types = []
 
+def extract_ofp_msgs(output_file_name):
     all_hdrs = {}
     all_raws = {}
     all_raws_order = []
@@ -108,15 +114,16 @@  def extract_ofp_msgs(output_file_name):
             comment += ' %s' % line.lstrip('* \t').rstrip(' \t\r\n')
         comment = comment[:-2].rstrip()
 
-        m = re.match(r'([A-Z]+) ([-.+\d]+|<all>) \((\d+)\): ([^.]+)\.$', comment)
+        m = re.match(
+            r'([A-Z]+) ([-.+\d]+|<all>) \((\d+)\): ([^.]+)\.$', comment
+        )
         if not m:
             fatal("unexpected syntax between messages")
         type_, versions, number, contents = m.groups()
         number = int(number)
 
         get_line()
-        m = re.match('\s+(?:OFPRAW_%s)(\d*)_([A-Z0-9_]+),?$' % type_,
-                     line)
+        m = re.match(r'\s+(?:OFPRAW_%s)(\d*)_([A-Z0-9_]+),?$' % type_, line)
         if not m:
             fatal("syntax error expecting OFPRAW_ enum")
         vinfix, name = m.groups()
@@ -300,7 +307,7 @@  def extract_ofp_msgs(output_file_name):
         for hdrs in r['hdrs']:
             output.append("    { {0, NULL}, {%d, %d, %d, 0x%x, %d}, %s, 0 },"
                           % (hdrs + (raw,)))
-                
+
         output.append("};")
 
     output.append("")
@@ -349,8 +356,8 @@  def extract_ofp_msgs(output_file_name):
                               % r["human_name"])
     output.append("};")
 
-    output.append("");
-    output.append("static const char *type_names[] = {");
+    output.append("")
+    output.append("static const char *type_names[] = {")
     for t in all_types:
         output.append("    \"%s\"," % t)
     output.append("};")
@@ -378,4 +385,3 @@  if __name__ == '__main__':
 
         for line in extract_ofp_msgs(sys.argv[2]):
             print(line)
-