mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
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 <jsnow@redhat.com> Message-ID: <20250313044312.189276-7-jsnow@redhat.com> Acked-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
7c7247b252
commit
b1df602ebb
1 changed files with 12 additions and 0 deletions
|
@ -451,6 +451,12 @@ class Transmogrifier:
|
|||
finally:
|
||||
self._curr_ent = None
|
||||
|
||||
def set_namespace(self, namespace: str, source: str, lineno: int) -> None:
|
||||
self.add_line_raw(
|
||||
f".. qapi:namespace:: {namespace}", source, lineno + 1
|
||||
)
|
||||
self.ensure_blank_line()
|
||||
|
||||
|
||||
class QAPISchemaGenDepVisitor(QAPISchemaVisitor):
|
||||
"""A QAPI schema visitor which adds Sphinx dependencies each module
|
||||
|
@ -496,6 +502,7 @@ class QAPIDocDirective(NestedDirective):
|
|||
optional_arguments = 1
|
||||
option_spec = {
|
||||
"qapifile": directives.unchanged_required,
|
||||
"namespace": directives.unchanged,
|
||||
"transmogrify": directives.flag,
|
||||
}
|
||||
has_content = False
|
||||
|
@ -510,6 +517,11 @@ class QAPIDocDirective(NestedDirective):
|
|||
vis = Transmogrifier()
|
||||
modules = set()
|
||||
|
||||
if "namespace" in self.options:
|
||||
vis.set_namespace(
|
||||
self.options["namespace"], *self.get_source_info()
|
||||
)
|
||||
|
||||
for doc in schema.docs:
|
||||
module_source = doc.info.fname
|
||||
if module_source not in modules:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue