netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Donald Hunter <donald.hunter@gmail.com>
To: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
	 Jonathan Corbet <corbet@lwn.net>,
	 "Akira Yokosawa" <akiyks@gmail.com>,
	 "Breno Leitao" <leitao@debian.org>,
	 "David S. Miller" <davem@davemloft.net>,
	 "Eric Dumazet" <edumazet@google.com>,
	 "Ignacio Encinas Rubio" <ignacio@iencinas.com>,
	 "Jan Stancek" <jstancek@redhat.com>,
	 "Marco Elver" <elver@google.com>,
	 "Paolo Abeni" <pabeni@redhat.com>,
	 "Randy Dunlap" <rdunlap@infradead.org>,
	 "Ruben Wauters" <rubenru09@aol.com>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Simon Horman <horms@kernel.org>,
	joel@joelfernandes.org,  linux-kernel-mentees@lists.linux.dev,
	linux-kernel@vger.kernel.org,  lkmm@lists.linux.dev,
	netdev@vger.kernel.org,  peterz@infradead.org,
	 stern@rowland.harvard.edu
Subject: Re: [PATCH v9 12/13] docs: parser_yaml.py: add support for line numbers from the parser
Date: Thu, 10 Jul 2025 12:25:56 +0100	[thread overview]
Message-ID: <m2zfdc5ltn.fsf@gmail.com> (raw)
In-Reply-To: <3b18b30b1b50b01a014fd4b5a38423e529cde2fb.1752076293.git.mchehab+huawei@kernel.org>

Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:

> Instead of printing line numbers from the temp converted ReST
> file, get them from the original source.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

This doesn't seem to work. This is what I get when I change line 14 of
rt-neigh.yaml

diff --git a/Documentation/netlink/specs/rt-neigh.yaml b/Documentation/netlink/specs/rt-neigh.yaml
index e9cba164e3d1..937d2563f151 100644
--- a/Documentation/netlink/specs/rt-neigh.yaml
+++ b/Documentation/netlink/specs/rt-neigh.yaml
@@ -11,6 +11,7 @@ doc:
 definitions:
   -
     name: ndmsg
+    doc: ".. bogus::"
     type: struct
     members:
       -

/home/donaldh/docs-next/Documentation/netlink/specs/rt-neigh.yaml:165: ERROR: Unknown directive type "bogus".

.. bogus:: [docutils]


> ---
>  Documentation/sphinx/parser_yaml.py      | 12 ++++++++++--
>  tools/net/ynl/pyynl/lib/doc_generator.py | 16 ++++++++++++----
>  2 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/sphinx/parser_yaml.py b/Documentation/sphinx/parser_yaml.py
> index fa2e6da17617..8288e2ff7c7c 100755
> --- a/Documentation/sphinx/parser_yaml.py
> +++ b/Documentation/sphinx/parser_yaml.py
> @@ -54,6 +54,8 @@ class YamlParser(Parser):
>  
>      netlink_parser = YnlDocGenerator()
>  
> +    re_lineno = re.compile(r"\.\. LINENO ([0-9]+)$")
> +
>      def rst_parse(self, inputstring, document, msg):
>          """
>          Receives a ReST content that was previously converted by the
> @@ -66,8 +68,14 @@ class YamlParser(Parser):
>  
>          try:
>              # Parse message with RSTParser
> -            for i, line in enumerate(msg.split('\n')):
> -                result.append(line, document.current_source, i)
> +            lineoffset = 0;
> +            for line in msg.split('\n'):
> +                match = self.re_lineno.match(line)
> +                if match:
> +                    lineoffset = int(match.group(1))
> +                    continue
> +
> +                result.append(line, document.current_source, lineoffset)

I expect this would need to be source=document.current_source, offset=lineoffset

>  
>              rst_parser = RSTParser()
>              rst_parser.parse('\n'.join(result), document)

But anyway this discards any line information by just concatenating the
lines together again.

> diff --git a/tools/net/ynl/pyynl/lib/doc_generator.py b/tools/net/ynl/pyynl/lib/doc_generator.py
> index 658759a527a6..403abf1a2eda 100644
> --- a/tools/net/ynl/pyynl/lib/doc_generator.py
> +++ b/tools/net/ynl/pyynl/lib/doc_generator.py
> @@ -158,9 +158,11 @@ class YnlDocGenerator:
>      def parse_do(self, do_dict: Dict[str, Any], level: int = 0) -> str:
>          """Parse 'do' section and return a formatted string"""
>          lines = []
> +        if LINE_STR in do_dict:
> +            lines.append(self.fmt.rst_lineno(do_dict[LINE_STR]))
> +
>          for key in do_dict.keys():
>              if key == LINE_STR:
> -                lines.append(self.fmt.rst_lineno(do_dict[key]))
>                  continue
>              lines.append(self.fmt.rst_paragraph(self.fmt.bold(key), level + 1))
>              if key in ['request', 'reply']:
> @@ -187,13 +189,15 @@ class YnlDocGenerator:
>          lines = []
>  
>          for operation in operations:
> +            if LINE_STR in operation:
> +                lines.append(self.fmt.rst_lineno(operation[LINE_STR]))
> +
>              lines.append(self.fmt.rst_section(namespace, 'operation',
>                                                operation["name"]))
>              lines.append(self.fmt.rst_paragraph(operation["doc"]) + "\n")
>  
>              for key in operation.keys():
>                  if key == LINE_STR:
> -                    lines.append(self.fmt.rst_lineno(operation[key]))
>                      continue
>  
>                  if key in preprocessed:
> @@ -253,10 +257,12 @@ class YnlDocGenerator:
>          lines = []
>  
>          for definition in defs:
> +            if LINE_STR in definition:
> +                lines.append(self.fmt.rst_lineno(definition[LINE_STR]))
> +
>              lines.append(self.fmt.rst_section(namespace, 'definition', definition["name"]))
>              for k in definition.keys():
>                  if k == LINE_STR:
> -                    lines.append(self.fmt.rst_lineno(definition[k]))
>                      continue
>                  if k in preprocessed + ignored:
>                      continue
> @@ -284,6 +290,9 @@ class YnlDocGenerator:
>              lines.append(self.fmt.rst_section(namespace, 'attribute-set',
>                                                entry["name"]))
>              for attr in entry["attributes"]:
> +                if LINE_STR in attr:
> +                    lines.append(self.fmt.rst_lineno(attr[LINE_STR]))
> +
>                  type_ = attr.get("type")
>                  attr_line = attr["name"]
>                  if type_:
> @@ -294,7 +303,6 @@ class YnlDocGenerator:
>  
>                  for k in attr.keys():
>                      if k == LINE_STR:
> -                        lines.append(self.fmt.rst_lineno(attr[k]))
>                          continue
>                      if k in preprocessed + ignored:
>                          continue

  reply	other threads:[~2025-07-10 11:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 15:58 [PATCH v9 00/13] Don't generate netlink .rst files inside $(srctree) Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 01/13] docs: netlink: netlink-raw.rst: use :ref: instead of :doc: Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 02/13] tools: ynl_gen_rst.py: Split library from command line tool Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 03/13] docs: netlink: index.rst: add a netlink index file Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 04/13] tools: ynl_gen_rst.py: cleanup coding style Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 05/13] docs: sphinx: add a parser for yaml files for Netlink specs Mauro Carvalho Chehab
2025-07-10  8:27   ` Donald Hunter
2025-07-09 15:58 ` [PATCH v9 06/13] docs: use parser_yaml extension to handle " Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 07/13] docs: uapi: netlink: update netlink specs link Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 08/13] tools: ynl_gen_rst.py: drop support for generating index files Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 09/13] docs: netlink: remove obsolete .gitignore from unused directory Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 10/13] MAINTAINERS: add netlink_yml_parser.py to linux-doc Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 11/13] tools: netlink_yml_parser.py: add line numbers to parsed data Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 12/13] docs: parser_yaml.py: add support for line numbers from the parser Mauro Carvalho Chehab
2025-07-10 11:25   ` Donald Hunter [this message]
2025-07-10 14:25     ` Donald Hunter
2025-07-10 17:57       ` Mauro Carvalho Chehab
2025-07-11  9:51         ` Donald Hunter
2025-07-11 17:40           ` Mauro Carvalho Chehab
2025-07-09 15:58 ` [PATCH v9 13/13] docs: parser_yaml.py: fix backward compatibility with old docutils Mauro Carvalho Chehab
2025-07-11  8:36 ` [PATCH v9 14/13] sphinx: parser_yaml.py: fix line numbers information Mauro Carvalho Chehab

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=m2zfdc5ltn.fsf@gmail.com \
    --to=donald.hunter@gmail.com \
    --cc=akiyks@gmail.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=elver@google.com \
    --cc=horms@kernel.org \
    --cc=ignacio@iencinas.com \
    --cc=joel@joelfernandes.org \
    --cc=jstancek@redhat.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkmm@lists.linux.dev \
    --cc=mchehab+huawei@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rubenru09@aol.com \
    --cc=skhan@linuxfoundation.org \
    --cc=stern@rowland.harvard.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).