Re: [PATCH v2 15/38] qapi/common.py: move build_params into gen.py

2020-09-23 Thread Cleber Rosa
On Tue, Sep 22, 2020 at 05:00:38PM -0400, John Snow wrote:
> Including it in common.py creates a circular import dependency; schema
> relies on common, but common.build_params requires a type annotation
> from schema. To type this properly, it needs to be moved outside the
> cycle.
> 
> Signed-off-by: John Snow 

Reviewed-by: Cleber Rosa 


signature.asc
Description: PGP signature


Re: [PATCH v2 15/38] qapi/common.py: move build_params into gen.py

2020-09-23 Thread Eduardo Habkost
On Tue, Sep 22, 2020 at 05:00:38PM -0400, John Snow wrote:
> Including it in common.py creates a circular import dependency; schema
> relies on common, but common.build_params requires a type annotation
> from schema. To type this properly, it needs to be moved outside the
> cycle.
> 
> Signed-off-by: John Snow 

Reviewed-by: Eduardo Habkost 

-- 
Eduardo




[PATCH v2 15/38] qapi/common.py: move build_params into gen.py

2020-09-22 Thread John Snow
Including it in common.py creates a circular import dependency; schema
relies on common, but common.build_params requires a type annotation
from schema. To type this properly, it needs to be moved outside the
cycle.

Signed-off-by: John Snow 
---
 scripts/qapi/commands.py |  8 ++--
 scripts/qapi/common.py   | 23 ---
 scripts/qapi/events.py   |  7 +--
 scripts/qapi/gen.py  | 34 --
 4 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index d9cda3b209..9b3f24b8ed 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -14,11 +14,15 @@
 """
 
 from .common import (
-build_params,
 c_name,
 mcgen,
 )
-from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext
+from .gen import (
+QAPIGenCCode,
+QAPISchemaModularCVisitor,
+build_params,
+ifcontext,
+)
 
 
 def gen_command_decl(name, arg_type, boxed, ret_type):
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 730283722a..50c3d36e27 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -209,26 +209,3 @@ def gen_endif(ifcond: Sequence[str]) -> str:
 #endif /* %(cond)s */
 ''', cond=ifc)
 return ret
-
-
-def build_params(arg_type,
- boxed: bool,
- extra: Optional[str] = None) -> str:
-ret = ''
-sep = ''
-if boxed:
-assert arg_type
-ret += '%s arg' % arg_type.c_param_type()
-sep = ', '
-elif arg_type:
-assert not arg_type.variants
-for memb in arg_type.members:
-ret += sep
-sep = ', '
-if memb.optional:
-ret += 'bool has_%s, ' % c_name(memb.name)
-ret += '%s %s' % (memb.type.c_param_type(),
-  c_name(memb.name))
-if extra:
-ret += sep + extra
-return ret if ret else 'void'
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index 6b3afa14d7..69a0ac5471 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -13,12 +13,15 @@
 """
 
 from .common import (
-build_params,
 c_enum_const,
 c_name,
 mcgen,
 )
-from .gen import QAPISchemaModularCVisitor, ifcontext
+from .gen import (
+QAPISchemaModularCVisitor,
+build_params,
+ifcontext,
+)
 from .schema import QAPISchemaEnumMember
 from .types import gen_enum, gen_enum_lookup
 
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 11472ba043..9898d513ae 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -2,9 +2,11 @@
 #
 # QAPI code generation
 #
-# Copyright (c) 2018-2019 Red Hat Inc.
+# Copyright IBM, Corp. 2011
+# Copyright (c) 2013-2019 Red Hat Inc.
 #
 # Authors:
+#  Anthony Liguori 
 #  Markus Armbruster 
 #  Marc-André Lureau 
 #
@@ -15,16 +17,21 @@
 import errno
 import os
 import re
+from typing import Optional
 
 from .common import (
 c_fname,
+c_name,
 gen_endif,
 gen_if,
 guardend,
 guardstart,
 mcgen,
 )
-from .schema import QAPISchemaVisitor
+from .schema import (
+QAPISchemaObjectType,
+QAPISchemaVisitor,
+)
 
 
 class QAPIGen:
@@ -90,6 +97,29 @@ def _wrap_ifcond(ifcond, before, after):
 return out
 
 
+def build_params(arg_type: Optional[QAPISchemaObjectType],
+ boxed: bool,
+ extra: Optional[str] = None) -> str:
+ret = ''
+sep = ''
+if boxed:
+assert arg_type
+ret += '%s arg' % arg_type.c_param_type()
+sep = ', '
+elif arg_type:
+assert not arg_type.variants
+for memb in arg_type.members:
+ret += sep
+sep = ', '
+if memb.optional:
+ret += 'bool has_%s, ' % c_name(memb.name)
+ret += '%s %s' % (memb.type.c_param_type(),
+  c_name(memb.name))
+if extra:
+ret += sep + extra
+return ret if ret else 'void'
+
+
 class QAPIGenCCode(QAPIGen):
 
 def __init__(self, fname):
-- 
2.26.2