Re: [ovs-dev] [PATCH 1/3] ovsdb-doc: Fix syntax warning with Python 3.12 and flake8 issues.

2024-04-11 Thread Simon Horman
On Thu, Apr 11, 2024 at 12:43:28AM +0200, Ilya Maximets wrote:
> ovsdb-doc script generates the following syntax warning while running
> with Python 3.12:
> 
>   /ovsdb/ovsdb-doc:240: SyntaxWarning: invalid escape sequence '\{'
>   s += """
> 
> This doesn't cause a build failure because so far it's only a warning,
> but it will become a syntax error in the future.
> 
> Fix that by converting to a raw string and removing unnecessary
> escape sequences.
> 
> Adding ovsdb-doc to flake8-check to avoid re-introducing issues in
> the future.  This means also fixing all the other issues with the
> script like unused imports and variables, long lines, missing empty
> lines, wildcarded imports.  Also cleaning up one place that handles
> compatibility with Python 2 types, since we do not support Python 2
> for a long time now.
> 
> Signed-off-by: Ilya Maximets 

Acked-by: Simon Horman 

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH 1/3] ovsdb-doc: Fix syntax warning with Python 3.12 and flake8 issues.

2024-04-10 Thread Ilya Maximets
ovsdb-doc script generates the following syntax warning while running
with Python 3.12:

  /ovsdb/ovsdb-doc:240: SyntaxWarning: invalid escape sequence '\{'
  s += """

This doesn't cause a build failure because so far it's only a warning,
but it will become a syntax error in the future.

Fix that by converting to a raw string and removing unnecessary
escape sequences.

Adding ovsdb-doc to flake8-check to avoid re-introducing issues in
the future.  This means also fixing all the other issues with the
script like unused imports and variables, long lines, missing empty
lines, wildcarded imports.  Also cleaning up one place that handles
compatibility with Python 2 types, since we do not support Python 2
for a long time now.

Signed-off-by: Ilya Maximets 
---
 ovsdb/automake.mk |  1 +
 ovsdb/ovsdb-doc   | 50 +++
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/ovsdb/automake.mk b/ovsdb/automake.mk
index eba713bb6..e8149224b 100644
--- a/ovsdb/automake.mk
+++ b/ovsdb/automake.mk
@@ -114,6 +114,7 @@ $(OVSIDL_BUILT): ovsdb/ovsdb-idlc.in python/ovs/dirs.py
 
 # ovsdb-doc
 EXTRA_DIST += ovsdb/ovsdb-doc
+FLAKE8_PYFILES += ovsdb/ovsdb-doc
 OVSDB_DOC = $(run_python) $(srcdir)/ovsdb/ovsdb-doc
 ovsdb/ovsdb-doc: python/ovs/dirs.py
 
diff --git a/ovsdb/ovsdb-doc b/ovsdb/ovsdb-doc
index 099770d25..2edf487a2 100755
--- a/ovsdb/ovsdb-doc
+++ b/ovsdb/ovsdb-doc
@@ -14,9 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from datetime import date
 import getopt
-import os
 import sys
 import xml.dom.minidom
 
@@ -24,10 +22,13 @@ import ovs.json
 from ovs.db import error
 import ovs.db.schema
 
-from ovs_build_helpers.nroff import *
+from ovs_build_helpers.nroff import block_xml_to_nroff
+from ovs_build_helpers.nroff import escape_nroff_literal
+from ovs_build_helpers.nroff import text_to_nroff
 
 argv0 = sys.argv[0]
 
+
 def typeAndConstraintsToNroff(column):
 type = column.type.toEnglish(escape_nroff_literal)
 constraints = column.type.constraintsToEnglish(escape_nroff_literal,
@@ -38,6 +39,7 @@ def typeAndConstraintsToNroff(column):
 type += " (must be unique within table)"
 return type
 
+
 def columnGroupToNroff(table, groupXml, documented_columns):
 introNodes = []
 columnNodes = []
@@ -49,7 +51,10 @@ def columnGroupToNroff(table, groupXml, documented_columns):
 if (columnNodes
 and not (node.nodeType == node.TEXT_NODE
  and node.data.isspace())):
-raise error.Error("text follows  or  inside 
: %s" % node)
+raise error.Error(
+"text follows  or  inside : %s"
+% node
+)
 introNodes += [node]
 
 summary = []
@@ -65,15 +70,9 @@ def columnGroupToNroff(table, groupXml, documented_columns):
 if node.hasAttribute('type'):
 type_string = node.attributes['type'].nodeValue
 type_json = ovs.json.from_string(str(type_string))
-# py2 -> py3 means str -> bytes and unicode -> str
-try:
-if type(type_json) in (str, unicode):
-raise error.Error("%s %s:%s has invalid 'type': 
%s" 
-  % (table.name, name, key, 
type_json))
-except:
-if type(type_json) in (bytes, str):
-raise error.Error("%s %s:%s has invalid 'type': 
%s" 
-  % (table.name, name, key, 
type_json))
+if type(type_json) in (bytes, str):
+raise error.Error("%s %s:%s has invalid 'type': %s"
+  % (table.name, name, key, type_json))
 type_ = ovs.db.types.BaseType.from_json(type_json)
 else:
 type_ = column.type.value
@@ -91,10 +90,11 @@ def columnGroupToNroff(table, groupXml, documented_columns):
 else:
 if type_.type != column.type.value.type:
 type_english = type_.toEnglish()
+typeNroff += ", containing "
 if type_english[0] in 'aeiou':
-typeNroff += ", containing an %s" % 
type_english
+typeNroff += "an %s" % type_english
 else:
-typeNroff += ", containing a %s" % type_english
+typeNroff += "a %s" % type_english
 constraints = (
 type_.constraintsToEnglish(escape_nroff_literal,
text_to_nroff))
@@ -121,6 +121,7 @@ def columnGroupToNroff(table,