[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/23] docs/qapidoc: add transmogrifier stub
From: |
John Snow |
Subject: |
[PATCH 06/23] docs/qapidoc: add transmogrifier stub |
Date: |
Thu, 12 Dec 2024 21:18:09 -0500 |
This commit adds a stubbed option to the qapi-doc directive that opts-in
to the new rST generator; the implementation of which will follow in
subsequent commits.
Once all QAPI documents have been converted, this option and the old
qapidoc implementation can be dropped.
Note that moving code outside of the try...except block has no impact
because the code moved outside of that block does not ever raise a
QAPIError.
Signed-off-by: John Snow <jsnow@redhat.com>
---
docs/sphinx/qapidoc.py | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
index 6abdcc884f5..230e67bca23 100644
--- a/docs/sphinx/qapidoc.py
+++ b/docs/sphinx/qapidoc.py
@@ -452,9 +452,9 @@ def _parse_text_into_node(self, doctext, node):
rstlist.append("", self._cur_doc.info.fname, self._cur_doc.info.line)
self._sphinx_directive.do_parse(rstlist, node)
- def get_document_nodes(self):
- """Return the list of docutils nodes which make up the document"""
- return self._top_node.children
+ def get_document_node(self):
+ """Return the root docutils node which makes up the document"""
+ return self._top_node
# Turn the black formatter on for the rest of the file.
@@ -503,7 +503,10 @@ class QAPIDocDirective(NestedDirective):
required_argument = 1
optional_arguments = 1
- option_spec = {"qapifile": directives.unchanged_required}
+ option_spec = {
+ "qapifile": directives.unchanged_required,
+ "transmogrify": directives.flag,
+ }
has_content = False
def new_serialno(self):
@@ -511,10 +514,24 @@ def new_serialno(self):
env = self.state.document.settings.env
return "qapidoc-%d" % env.new_serialno("qapidoc")
+ def transmogrify(self, schema) -> nodes.Element:
+ raise NotImplementedError
+
+ def legacy(self, schema) -> nodes.Element:
+ vis = QAPISchemaGenRSTVisitor(self)
+ vis.visit_begin(schema)
+ for doc in schema.docs:
+ if doc.symbol:
+ vis.symbol(doc, schema.lookup_entity(doc.symbol))
+ else:
+ vis.freeform(doc)
+ return vis.get_document_node()
+
def run(self):
env = self.state.document.settings.env
qapifile = env.config.qapidoc_srctree + "/" + self.arguments[0]
qapidir = os.path.dirname(qapifile)
+ transmogrify = "transmogrify" in self.options
try:
schema = QAPISchema(qapifile)
@@ -522,20 +539,18 @@ def run(self):
# First tell Sphinx about all the schema files that the
# output documentation depends on (including 'qapifile' itself)
schema.visit(QAPISchemaGenDepVisitor(env, qapidir))
-
- vis = QAPISchemaGenRSTVisitor(self)
- vis.visit_begin(schema)
- for doc in schema.docs:
- if doc.symbol:
- vis.symbol(doc, schema.lookup_entity(doc.symbol))
- else:
- vis.freeform(doc)
- return vis.get_document_nodes()
except QAPIError as err:
# Launder QAPI parse errors into Sphinx extension errors
# so they are displayed nicely to the user
raise ExtensionError(str(err)) from err
+ if transmogrify:
+ contentnode = self.transmogrify(schema)
+ else:
+ contentnode = self.legacy(schema)
+
+ return contentnode.children
+
class QMPExample(CodeBlock, NestedDirective):
"""
--
2.47.0
- Re: [PATCH 01/23] docs/qapidoc: support header-less freeform sections, (continued)
- [PATCH 03/23] docs/qapidoc: remove example section support, John Snow, 2024/12/12
- [PATCH 02/23] qapi/parser: adjust info location for doc body section, John Snow, 2024/12/12
- [PATCH 04/23] qapi: expand tags to all doc sections, John Snow, 2024/12/12
- [PATCH 05/23] qapi/schema: add __repr__ to QAPIDoc.Section, John Snow, 2024/12/12
- [PATCH 06/23] docs/qapidoc: add transmogrifier stub,
John Snow <=
- [PATCH 07/23] docs/qapidoc: add transmogrifier class stub, John Snow, 2024/12/12
- [PATCH 08/23] docs/qapidoc: add visit_module() method, John Snow, 2024/12/12
- [PATCH 09/23] qapi/source: allow multi-line QAPISourceInfo advancing, John Snow, 2024/12/12
- [PATCH 10/23] docs/qapidoc: add visit_freeform() method, John Snow, 2024/12/12
- [PATCH 11/23] docs/qapidoc: add preamble() method, John Snow, 2024/12/12
- [PATCH 12/23] docs/qapidoc: add visit_paragraph() method, John Snow, 2024/12/12
- [PATCH 14/23] docs/qapidoc: add format_type() method, John Snow, 2024/12/12