Skip to content

Commit b1df602

Browse files
jnsnowMarkus Armbruster
authored andcommitted
docs/qapidoc: add :namespace: option to qapi-doc directive
Add a :namespace: option to the qapi-doc directive, which inserts a qapi:namespace directive into the start of the generated document. This, in turn, associates all auto-generated definitions by this directive with the specified namespace. The source info for these generated lines are credited to the start of the qapi-doc directive, which isn't precisely correct, but I wasn't sure how to get it more accurate without some re-parsing shenanigans. Signed-off-by: John Snow <[email protected]> Message-ID: <[email protected]> Acked-by: Markus Armbruster <[email protected]> Signed-off-by: Markus Armbruster <[email protected]>
1 parent 7c7247b commit b1df602

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/sphinx/qapidoc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ def visit_entity(self, ent: QAPISchemaDefinition) -> None:
451451
finally:
452452
self._curr_ent = None
453453

454+
def set_namespace(self, namespace: str, source: str, lineno: int) -> None:
455+
self.add_line_raw(
456+
f".. qapi:namespace:: {namespace}", source, lineno + 1
457+
)
458+
self.ensure_blank_line()
459+
454460

455461
class QAPISchemaGenDepVisitor(QAPISchemaVisitor):
456462
"""A QAPI schema visitor which adds Sphinx dependencies each module
@@ -496,6 +502,7 @@ class QAPIDocDirective(NestedDirective):
496502
optional_arguments = 1
497503
option_spec = {
498504
"qapifile": directives.unchanged_required,
505+
"namespace": directives.unchanged,
499506
"transmogrify": directives.flag,
500507
}
501508
has_content = False
@@ -510,6 +517,11 @@ def transmogrify(self, schema: QAPISchema) -> nodes.Element:
510517
vis = Transmogrifier()
511518
modules = set()
512519

520+
if "namespace" in self.options:
521+
vis.set_namespace(
522+
self.options["namespace"], *self.get_source_info()
523+
)
524+
513525
for doc in schema.docs:
514526
module_source = doc.info.fname
515527
if module_source not in modules:

0 commit comments

Comments
 (0)