All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Victor Toso de Carvalho" <victortoso@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Konstantin Kostiuk" <kkostiuk@redhat.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Lukas Straub" <lukasstraub2@web.de>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Ani Sinha" <anisinha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-block@nongnu.org, "Jiri Pirko" <jiri@resnulli.us>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>, "Eric Blake" <eblake@redhat.com>
Subject: Re: [PATCH 04/13] qapi/parser: preserve indentation in QAPIDoc sections
Date: Wed, 19 Jun 2024 14:03:20 +0200	[thread overview]
Message-ID: <878qz12l87.fsf@pond.sub.org> (raw)
In-Reply-To: <20240619003012.1753577-5-jsnow@redhat.com> (John Snow's message of "Tue, 18 Jun 2024 20:30:03 -0400")

John Snow <jsnow@redhat.com> writes:

> Change get_doc_indented() to preserve indentation on all subsequent text
> lines, and create a compatibility dedent() function for qapidoc.py to
> remove that indentation. This is being done for the benefit of a new

Suggest "remove indentation the same way get_doc_indented() did."

> qapidoc generator which requires that indentation in argument and
> features sections are preserved.
>
> Prior to this patch, a section like this:
>
> ```
> @name: lorem ipsum
>    dolor sit amet
>      consectetur adipiscing elit
> ```
>
> would have its body text be parsed as:

Suggest "parsed into".

> (first and final newline only for presentation)
>
> ```
> lorem ipsum
> dolor sit amet
>   consectetur adipiscing elit
> ```
>
> We want to preserve the indentation for even the first body line so that
> the entire block can be parsed directly as rST. This patch would now
> parse that segment as:

If you change "parsed as" to "parsed into" above, then do it here, too.

>
> ```
> lorem ipsum
>    dolor sit amet
>      consectetur adipiscing elit
> ```
>
> This is helpful for formatting arguments and features as field lists in
> rST, where the new generator will format this information as:
>
> ```
> :arg type name: lorem ipsum
>    dolor sit amet
>      consectetur apidiscing elit
> ```
>
> ...and can be formed by the simple concatenation of the field list
> construct and the body text. The indents help preserve the continuation
> of a block-level element, and further allow the use of additional rST
> block-level constructs such as code blocks, lists, and other such
> markup. Avoiding reflowing the text conditionally also helps preserve
> source line context for better rST error reporting from sphinx through
> generated source, too.

What do you mean by "reflowing"?

> This understandably breaks the existing qapidoc.py; so a new function is
> added there to dedent the text for compatibility. Once the new generator
> is merged, this function will not be needed any longer and can be
> dropped.
>
> I verified this patch changes absolutely nothing by comparing the
> md5sums of the QMP ref html pages both before and after the change, so
> it's certified inert. QAPI test output has been updated to reflect the
> new strategy of preserving indents for rST.

I think the remainder is unnecessary detail.  Drop?

> before:
>
> 69cde3d6f18b0f324badbb447d4381ce  manual_before/interop/qemu-ga-ref.html
> 446e9381833def2adc779f1b90f2215f  manual_before/interop/qemu-qmp-ref.html
> df0ad6c26cb4c28b85d663fe44609c12  manual_before/interop/qemu-storage-daemon-qmp-ref.html
>
> after:
>
> 69cde3d6f18b0f324badbb447d4381ce  manual/interop/qemu-ga-ref.html
> 446e9381833def2adc779f1b90f2215f  manual/interop/qemu-qmp-ref.html
> df0ad6c26cb4c28b85d663fe44609c12  manual/interop/qemu-storage-daemon-qmp-ref.html
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  docs/sphinx/qapidoc.py         | 29 ++++++++++++++++++++++++-----
>  scripts/qapi/parser.py         |  5 +++--
>  tests/qapi-schema/doc-good.out | 32 ++++++++++++++++----------------
>  3 files changed, 43 insertions(+), 23 deletions(-)
>
> diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
> index e675966defa..f2f2005dd5f 100644
> --- a/docs/sphinx/qapidoc.py
> +++ b/docs/sphinx/qapidoc.py
> @@ -26,6 +26,7 @@
>  
>  import os
>  import re
> +import textwrap
>  
>  from docutils import nodes
>  from docutils.parsers.rst import Directive, directives
> @@ -53,6 +54,21 @@
>  __version__ = "1.0"
>  
>  
> +def dedent(text: str) -> str:
> +    # Temporary: In service of the new QAPI Sphinx domain, the QAPI doc
> +    # parser now preserves indents in args/members/features text.
> +    # QAPIDoc does not handle this well, so undo that change here.

A comment should explain how things are.  This one explains how things
have changed.  Suggest:

       # Adjust indentation to make description text parse as paragraph.

If we planned to keep this, we might want to explain in more detail, as
I did in review of v1.  But we don't.

> +
> +    lines = text.splitlines(True)
> +    if re.match(r"\s+", lines[0]):
> +        # First line is indented; description started on the line after
> +        # the name. dedent the whole block.
> +        return textwrap.dedent(text)
> +
> +    # Descr started on same line. Dedent line 2+.
> +    return lines[0] + textwrap.dedent("".join(lines[1:]))
> +
> +
>  # Disable black auto-formatter until re-enabled:
>  # fmt: off
>  
> @@ -176,7 +192,7 @@ def _nodes_for_members(self, doc, what, base=None, branches=None):
>              term = self._nodes_for_one_member(section.member)
>              # TODO drop fallbacks when undocumented members are outlawed
>              if section.text:
> -                defn = section.text
> +                defn = dedent(section.text)
>              else:
>                  defn = [nodes.Text('Not documented')]
>  
> @@ -214,7 +230,7 @@ def _nodes_for_enum_values(self, doc):
>                  termtext.extend(self._nodes_for_ifcond(section.member.ifcond))
>              # TODO drop fallbacks when undocumented members are outlawed
>              if section.text:
> -                defn = section.text
> +                defn = dedent(section.text)
>              else:
>                  defn = [nodes.Text('Not documented')]
>  
> @@ -249,7 +265,7 @@ def _nodes_for_features(self, doc):
>          dlnode = nodes.definition_list()
>          for section in doc.features.values():
>              dlnode += self._make_dlitem(
> -                [nodes.literal('', section.member.name)], section.text)
> +                [nodes.literal('', section.member.name)], dedent(section.text))
>              seen_item = True
>  
>          if not seen_item:
> @@ -272,9 +288,12 @@ def _nodes_for_sections(self, doc):
>                  continue
>              snode = self._make_section(section.tag)
>              if section.tag and section.tag.startswith('Example'):
> -                snode += self._nodes_for_example(section.text)
> +                snode += self._nodes_for_example(dedent(section.text))
>              else:
> -                self._parse_text_into_node(section.text, snode)
> +                self._parse_text_into_node(
> +                    dedent(section.text) if section.tag else section.text,
> +                    snode,
> +                )
>              nodelist.append(snode)
>          return nodelist
>  
> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 7b13a583ac1..43167ef0ab3 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -437,6 +437,7 @@ def _match_at_name_colon(string: str) -> Optional[Match[str]]:
>          return re.match(r'@([^:]*): *', string)
>  
>      def get_doc_indented(self, doc: 'QAPIDoc') -> Optional[str]:
> +        """get_doc_indented preserves indentation for later rST parsing."""

A proper function comment explains what the function does.  This one
merely points out one minor aspect.  Easy fix: delete it.  Alternative
fix: write a proper function comment.

>          self.accept(False)
>          line = self.get_doc_line()
>          while line == '':

[...]

Just commit message and doc nitpicks, so
Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2024-06-19 12:04 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  0:29 [PATCH 00/13] qapi: convert "Note" and "Example" sections to rST John Snow
2024-06-19  0:30 ` [PATCH 01/13] [DO-NOT-MERGE]: Add some ad-hoc linting helpers John Snow
2024-06-19  0:30 ` [PATCH 02/13] qapi: linter fixups John Snow
2024-06-19  0:30 ` [PATCH 03/13] docs/qapidoc: delint a tiny portion of the module John Snow
2024-06-19  6:28   ` Markus Armbruster
2024-06-19 17:06     ` John Snow
2024-06-19  0:30 ` [PATCH 04/13] qapi/parser: preserve indentation in QAPIDoc sections John Snow
2024-06-19 12:03   ` Markus Armbruster [this message]
2024-06-20 14:47     ` John Snow
2024-06-20 15:07       ` Markus Armbruster
2024-06-20 15:14         ` John Snow
2024-06-21  6:38           ` Markus Armbruster
2024-06-21 17:28             ` John Snow
2024-06-22  8:48               ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 05/13] qapi/parser: fix comment parsing immediately following a doc block John Snow
2024-06-19 12:04   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 06/13] docs/qapidoc: fix nested parsing under untagged sections John Snow
2024-06-19 12:05   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 07/13] qapi: fix non-compliant JSON examples John Snow
2024-06-19 12:07   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 08/13] qapi: ensure all errors sections are uniformly typset John Snow
2024-06-19 12:10   ` Markus Armbruster
2024-06-20 15:25     ` John Snow
2024-06-19  0:30 ` [PATCH 09/13] qapi: convert "Note" sections to plain rST John Snow
2024-06-19 12:49   ` Markus Armbruster
2024-06-20 13:35     ` Markus Armbruster
2024-06-20 15:46       ` John Snow
2024-06-20 18:44         ` John Snow
2024-06-21 12:23           ` Markus Armbruster
2024-06-21 17:41             ` John Snow
2024-06-22  8:52               ` Markus Armbruster
2024-06-20 15:39     ` John Snow
2024-06-21 10:20       ` Markus Armbruster
2024-06-19 13:07   ` Markus Armbruster
2024-06-20 15:40     ` John Snow
2024-06-21  6:39       ` Markus Armbruster
2024-06-20 13:54   ` Markus Armbruster
2024-06-20 15:52     ` John Snow
2024-06-21 12:08   ` Markus Armbruster
2024-06-21 17:33     ` John Snow
2024-06-19  0:30 ` [PATCH 10/13] qapi: update prose in note blocks John Snow
2024-06-19 12:18   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 11/13] qapi: add markup to " John Snow
2024-06-19 12:19   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 12/13] qapi/parser: don't parse rST markup as section headers John Snow
2024-06-19 12:55   ` Markus Armbruster
2024-06-19  0:30 ` [PATCH 13/13] qapi: convert "Example" sections to rST John Snow
2024-06-19 13:20   ` Markus Armbruster
2024-06-19 17:32     ` John Snow
2024-06-26  5:17   ` Markus Armbruster
2024-06-26 14:39     ` John Snow
2024-06-26  5:35 ` [PATCH 00/13] qapi: convert "Note" and " Markus Armbruster
2024-07-01 20:28 ` Michael S. Tsirkin

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=878qz12l87.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=anisinha@redhat.com \
    --cc=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=farosas@suse.de \
    --cc=hreitz@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=jsnow@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lukasstraub2@web.de \
    --cc=mads@ynddal.dk \
    --cc=marcandre.lureau@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    --cc=victortoso@redhat.com \
    --cc=wangyanan55@huawei.com \
    /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.