[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 06/23] docs/qapidoc: add transmogrifier stub
From: |
John Snow |
Subject: |
[PATCH v2 06/23] docs/qapidoc: add transmogrifier stub |
Date: |
Tue, 14 Jan 2025 13:58:23 -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 d622398f1da..dc72f3fd3f3 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.1
- [PATCH v2 00/23] docs: add basic sphinx-domain rST generator to qapidoc, John Snow, 2025/01/14
- [PATCH v2 01/23] docs/qapidoc: support header-less freeform sections, John Snow, 2025/01/14
- [PATCH v2 08/23] docs/qapidoc: add visit_module() method, John Snow, 2025/01/14
- [PATCH v2 02/23] qapi/parser: adjust info location for doc body section, John Snow, 2025/01/14
- [PATCH v2 13/23] docs/qapidoc: add visit_errors() method, John Snow, 2025/01/14
- [PATCH v2 15/23] docs/qapidoc: add add_field() and generate_field() helper methods, John Snow, 2025/01/14
- [PATCH v2 14/23] docs/qapidoc: add format_type() method, John Snow, 2025/01/14
- [PATCH v2 06/23] docs/qapidoc: add transmogrifier stub,
John Snow <=
- [PATCH v2 04/23] qapi: expand tags to all doc sections, John Snow, 2025/01/14
- [PATCH v2 09/23] qapi/source: allow multi-line QAPISourceInfo advancing, John Snow, 2025/01/14
- [PATCH v2 11/23] docs/qapidoc: add preamble() method, John Snow, 2025/01/14
- [PATCH v2 19/23] docs/qapidoc: add visit_member() method, John Snow, 2025/01/14
- [PATCH v2 05/23] qapi/schema: add __repr__ to QAPIDoc.Section, John Snow, 2025/01/14
- [PATCH v2 12/23] docs/qapidoc: add visit_paragraph() method, John Snow, 2025/01/14
- [PATCH v2 17/23] docs/qapidoc: prepare to record entity being transmogrified, John Snow, 2025/01/14
- [PATCH v2 22/23] docs/qapidoc: implement transmogrify() method, John Snow, 2025/01/14
- [PATCH v2 03/23] docs/qapidoc: remove example section support, John Snow, 2025/01/14
- [PATCH v2 07/23] docs/qapidoc: add transmogrifier class stub, John Snow, 2025/01/14