John Snow <js...@redhat.com> writes: > 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 <js...@redhat.com> > Reviewed-by: Eduardo Habkost <ehabk...@redhat.com> > Reviewed-by: Cleber Rosa <cr...@redhat.com> > --- > scripts/qapi/commands.py | 9 +++++++-- > scripts/qapi/common.py | 23 ----------------------- > scripts/qapi/events.py | 9 ++------- > scripts/qapi/gen.py | 31 +++++++++++++++++++++++++++++-- > 4 files changed, 38 insertions(+), 34 deletions(-) > > diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py > index 5dc2f5a9fa8..f67393f8713 100644 > --- a/scripts/qapi/commands.py > +++ b/scripts/qapi/commands.py > @@ -13,8 +13,13 @@ > See the COPYING file in the top-level directory. > """ > > -from .common import build_params, c_name, mcgen > -from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext > +from .common import c_name, mcgen > +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 0ef38ea5fe0..9ab0685cc51 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 6b3afa14d72..f840a62ed92 100644 > --- a/scripts/qapi/events.py > +++ b/scripts/qapi/events.py > @@ -12,13 +12,8 @@ > See the COPYING file in the top-level directory. > """ > > -from .common import ( > - build_params, > - c_enum_const, > - c_name, > - mcgen, > -) > -from .gen import QAPISchemaModularCVisitor, ifcontext > +from .common import c_enum_const, c_name, mcgen > +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 1fed712b43b..f2e2746fea5 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 <aligu...@us.ibm.com> > # Markus Armbruster <arm...@redhat.com> > # Marc-André Lureau <marcandre.lur...@redhat.com> > #
The code you move into this file is actually Red Hat's: $ git-log -L174,193:scripts/qapi/common.py master| egrep 'Author|Date' Author: Markus Armbruster <arm...@redhat.com> Date: Wed Aug 15 21:37:36 2018 +0800 Author: Marc-André Lureau <marcandre.lur...@redhat.com> Date: Thu Jun 1 16:41:41 2017 +0400 Author: Eric Blake <ebl...@redhat.com> Date: Wed Jul 13 21:50:20 2016 -0600 Author: Eric Blake <ebl...@redhat.com> Date: Wed Jul 13 21:50:19 2016 -0600 Author: Eric Blake <ebl...@redhat.com> Date: Thu Mar 17 16:48:28 2016 -0600 Author: Markus Armbruster <arm...@redhat.com> Date: Wed Sep 16 13:06:20 2015 +0200 So the correct update is simply # # QAPI code generation # -# Copyright (c) 2018-2019 Red Hat Inc. +# Copyright (c) 2015-2019 Red Hat Inc. # # Authors: # Markus Armbruster <arm...@redhat.com> # Marc-André Lureau <marcandre.lur...@redhat.com> # > @@ -15,16 +17,18 @@ > 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 +94,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):