From: Markus Armbruster <armbru@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: "Armbruster, Markus" <armbru@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH for-4.0 v7 22/27] qapi: add 'If:' condition to enum values documentation
Date: Thu, 13 Dec 2018 14:59:07 +0100 [thread overview]
Message-ID: <87ftv1r0ic.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAMxuvaxu_G62E0Gg677FvCapiswJ+6i3wqzrg78qOVtsizHuVg@mail.gmail.com> ("Marc-André Lureau"'s message of "Tue, 11 Dec 2018 20:07:49 +0400")
Marc-André Lureau <marcandre.lureau@redhat.com> writes:
> Hi
>
> On Tue, Dec 11, 2018 at 8:00 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Marc-André Lureau <marcandre.lureau@redhat.com> writes:
>>
>> > Use a common function to generate the "If:..." line.
>> >
>> > While at it, get rid of the existing \n\n (no idea why it was
>> > there). Use a line-break in member description, this seems to look
>> > slightly better in the plaintext version.
>>
>> Where exactly in the patch is this done?
>
> - if ifcond:
> - body += '\n\n@b{If:} @code{%s}' % ", ".join(ifcond)
> + body += texi_if(ifcond, suffix='')
Thanks. I suspected that much, but wasn't sure.
> See also doc-good.texi output
>
>>
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> > scripts/qapi/doc.py | 24 +++++++++++++++---------
>> > tests/qapi-schema/doc-good.json | 4 +++-
>> > tests/qapi-schema/doc-good.out | 1 +
>> > tests/qapi-schema/doc-good.texi | 2 +-
>> > 4 files changed, 20 insertions(+), 11 deletions(-)
>> >
>> > diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
>> > index 76cb186ff9..2133ded47e 100755
>> > --- a/scripts/qapi/doc.py
>> > +++ b/scripts/qapi/doc.py
>> > @@ -126,19 +126,26 @@ def texi_body(doc):
>> > return texi_format(doc.body.text)
>> >
>> >
>> > -def texi_enum_value(value):
>> > +def texi_if(ifcond, prefix='\n', suffix='\n'):
>> > + """Format the #if condition"""
>> > + return '%s@b{If:} @code{%s}%s' % (
>> > + prefix, ', '.join(ifcond), suffix) if ifcond else ''
>>
>> I like the ternary operator, but I nevertheless think this function is
>> easier to read as
>>
>> if not ifcond:
>> return ''
>> return '%s@b{If:} @code{%s}%s' % (prefix, ', '.join(ifcond), suffix)
>>
>
> No difference to me, sure
>
>> > +
>> > +
>> > +def texi_enum_value(value, desc, suffix=''):
>> > """Format a table of members item for an enumeration value"""
>> > - return '@item @code{%s}\n' % value.name
>> > + return '@item @code{%s}\n%s%s' % (
>> > + value.name, desc, texi_if(value.ifcond, prefix='@*'))
>>
>> Do you ignore suffix intentionally?
>
> yes
That's kind of surprising, until you pry open the abstraction and
realize that we reach this one only from the first call of member_func()
below, which ...
>>
>> >
>> >
>> > -def texi_member(member, suffix=''):
>> > +def texi_member(member, desc='', suffix=''):
>> > """Format a table of members item for an object type member"""
>> > typ = member.type.doc_type()
>> > membertype = ': ' + typ if typ else ''
>> > - return '@item @code{%s%s}%s%s\n' % (
>> > + return '@item @code{%s%s}%s%s\n%s' % (
>> > member.name, membertype,
>> > ' (optional)' if member.optional else '',
>> > - suffix)
>> > + suffix, desc)
>> >
>> >
>> > def texi_members(doc, what, base, variants, member_func):
>> > @@ -155,7 +162,7 @@ def texi_members(doc, what, base, variants, member_func):
>> > desc = 'One of ' + members_text + '\n'
>> > else:
>> > desc = 'Not documented\n'
>> > - items += member_func(section.member) + desc
>> > + items += member_func(section.member, desc)
>>
>> Here, you pass a @desc argument, but no @suffix.
>>
>> @member_func is either texi_enum_value() or texi_member(). Works.
... doesn't pass @suffix. So @suffix is empty when we ignore it.
>> > if base:
>> > items += '@item The members of @code{%s}\n' % base.doc_type()
>> > if variants:
>> > @@ -165,7 +172,7 @@ def texi_members(doc, what, base, variants, member_func):
>> > if v.type.is_implicit():
>> > assert not v.type.base and not v.type.variants
>> > for m in v.type.local_members:
>> > - items += member_func(m, when)
>> > + items += member_func(m, suffix=when)
>>
>> Here, you pass a @suffix argument, but no @desc.
>>
>> texi_enum_value() would choke on that, but it can't occur here, because
>> enums have no variants.
>>
>> Still, I'd prefer texi_enum_value() and texi_member() to have the exact
>> same signature.
>
> OK (not sure what is the more pythonic way)
I suspect there's a clean solution struggling to get out. But I can't
grasp it yet.
>>
>> > else:
>> > items += '@item The members of @code{%s}%s\n' % (
>> > v.type.doc_type(), when)
>> > @@ -185,8 +192,7 @@ def texi_sections(doc, ifcond):
>> > body += texi_example(section.text)
>> > else:
>> > body += texi_format(section.text)
>> > - if ifcond:
>> > - body += '\n\n@b{If:} @code{%s}' % ", ".join(ifcond)
>> > + body += texi_if(ifcond, suffix='')
>> > return body
>> >
>> >
[...]
next prev parent reply other threads:[~2018-12-13 13:59 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-08 11:15 [Qemu-devel] [PATCH for-4.0 v7 00/27] Hi, Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 01/27] qapi: make sure osdep.h is included in type headers Marc-André Lureau
2018-12-10 9:52 ` Markus Armbruster
2018-12-10 11:13 ` Marc-André Lureau
2018-12-10 13:28 ` Markus Armbruster
2018-12-11 15:47 ` Marc-André Lureau
2018-12-12 6:47 ` Markus Armbruster
2018-12-11 16:05 ` Daniel P. Berrangé
2018-12-12 6:48 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeration value explicitly Marc-André Lureau
2018-12-12 8:52 ` Markus Armbruster
2018-12-12 9:05 ` Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 03/27] qapi: rename QAPISchemaEnumType.values to .members Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 04/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 05/27] tests: print enum type members more like object type members Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 06/27] qapi: factor out checking for keys Marc-André Lureau
2018-12-10 9:57 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 07/27] qapi: improve reporting of unknown or missing keys Marc-André Lureau
2018-12-10 10:03 ` Markus Armbruster
2018-12-10 11:11 ` Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 08/27] qapi: add a dictionary form with 'name' key for enum members Marc-André Lureau
2018-12-10 15:44 ` Markus Armbruster
2018-12-10 16:05 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 09/27] qapi: add 'if' to " Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 10/27] qapi-events: add 'if' condition to implicit event enum Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 11/27] qapi: pass long form enum to make_enum_members Marc-André Lureau
2018-12-10 17:04 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 12/27] qapi: rename allow_dict to allow_implicit Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 13/27] qapi: add a dictionary form for TYPE Marc-André Lureau
2018-12-10 17:24 ` Markus Armbruster
2018-12-11 12:11 ` Marc-André Lureau
2018-12-11 15:35 ` Markus Armbruster
2018-12-11 15:18 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 14/27] qapi: add 'if' to implicit struct members Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 15/27] qapi: add an error in case a discriminator is conditional Marc-André Lureau
2018-12-10 17:31 ` Markus Armbruster
2018-12-11 15:23 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 16/27] qapi: add 'if' to union members Marc-André Lureau
2018-12-10 17:33 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 17/27] qapi: simplify make_enum_members() Marc-André Lureau
2018-12-11 12:05 ` Markus Armbruster
2018-12-11 12:08 ` Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 18/27] tests/qapi: add command with condition on union argument Marc-André Lureau
2018-12-11 12:09 ` Markus Armbruster
2018-12-11 12:13 ` Marc-André Lureau
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 19/27] qapi: add 'if' to alternate members Marc-André Lureau
2018-12-11 12:21 ` Markus Armbruster
2018-12-08 11:15 ` [Qemu-devel] [PATCH for-4.0 v7 20/27] tests/qapi: add command with condition on alternate argument Marc-André Lureau
2018-12-11 12:20 ` Markus Armbruster
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 21/27] qapi: add #if conditions to generated code members Marc-André Lureau
2018-12-11 13:17 ` Markus Armbruster
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 22/27] qapi: add 'If:' condition to enum values documentation Marc-André Lureau
2018-12-11 16:00 ` Markus Armbruster
2018-12-11 16:07 ` Marc-André Lureau
2018-12-13 13:59 ` Markus Armbruster [this message]
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 23/27] qapi: add 'If:' condition to struct members documentation Marc-André Lureau
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 24/27] qapi: add condition to variants documentation Marc-André Lureau
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 25/27] qapi: break long lines at 'data' member Marc-André Lureau
2018-12-11 16:07 ` Markus Armbruster
2018-12-11 16:08 ` Marc-André Lureau
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 26/27] qapi: add more conditions to SPICE Marc-André Lureau
2018-12-11 17:11 ` Markus Armbruster
2018-12-08 11:16 ` [Qemu-devel] [PATCH for-4.0 v7 27/27] qapi: add conditions to REPLICATION type/commands on the schema Marc-André Lureau
2018-12-11 17:15 ` Markus Armbruster
2018-12-11 17:17 ` Marc-André Lureau
2018-12-08 11:19 ` [Qemu-devel] [PATCH for-4.0 v7 00/27] Hi, Marc-André Lureau
2018-12-12 17:18 ` Markus Armbruster
2018-12-12 18:13 ` Marc-André Lureau
2018-12-13 5:11 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ftv1r0ic.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.