mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
docs/qapi-domain: add QAPI index
Use the QAPI object registry to generate a special index just for QAPI definitions. The index can show entries both by definition type and all together, alphabetically. The index can be linked from anywhere in the QEMU manual by using the reference `qapi-index`. Signed-off-by: John Snow <jsnow@redhat.com> Message-ID: <20250311034303.75779-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
36ceafad9e
commit
e93d29d27e
1 changed files with 70 additions and 3 deletions
|
@ -9,12 +9,20 @@ from typing import (
|
|||
AbstractSet,
|
||||
Any,
|
||||
Dict,
|
||||
Iterable,
|
||||
List,
|
||||
NamedTuple,
|
||||
Optional,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from sphinx.domains import Domain, ObjType
|
||||
from sphinx.locale import __
|
||||
from sphinx.domains import (
|
||||
Domain,
|
||||
Index,
|
||||
IndexEntry,
|
||||
ObjType,
|
||||
)
|
||||
from sphinx.locale import _, __
|
||||
from sphinx.util import logging
|
||||
|
||||
|
||||
|
@ -31,6 +39,62 @@ class ObjectEntry(NamedTuple):
|
|||
aliased: bool
|
||||
|
||||
|
||||
class QAPIIndex(Index):
|
||||
"""
|
||||
Index subclass to provide the QAPI definition index.
|
||||
"""
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
name = "index"
|
||||
localname = _("QAPI Index")
|
||||
shortname = _("QAPI Index")
|
||||
|
||||
def generate(
|
||||
self,
|
||||
docnames: Optional[Iterable[str]] = None,
|
||||
) -> Tuple[List[Tuple[str, List[IndexEntry]]], bool]:
|
||||
assert isinstance(self.domain, QAPIDomain)
|
||||
content: Dict[str, List[IndexEntry]] = {}
|
||||
collapse = False
|
||||
|
||||
# list of all object (name, ObjectEntry) pairs, sorted by name
|
||||
# (ignoring the module)
|
||||
objects = sorted(
|
||||
self.domain.objects.items(),
|
||||
key=lambda x: x[0].split(".")[-1].lower(),
|
||||
)
|
||||
|
||||
for objname, obj in objects:
|
||||
if docnames and obj.docname not in docnames:
|
||||
continue
|
||||
|
||||
# Strip the module name out:
|
||||
objname = objname.split(".")[-1]
|
||||
|
||||
# Add an alphabetical entry:
|
||||
entries = content.setdefault(objname[0].upper(), [])
|
||||
entries.append(
|
||||
IndexEntry(
|
||||
objname, 0, obj.docname, obj.node_id, obj.objtype, "", ""
|
||||
)
|
||||
)
|
||||
|
||||
# Add a categorical entry:
|
||||
category = obj.objtype.title() + "s"
|
||||
entries = content.setdefault(category, [])
|
||||
entries.append(
|
||||
IndexEntry(objname, 0, obj.docname, obj.node_id, "", "", "")
|
||||
)
|
||||
|
||||
# alphabetically sort categories; type names first, ABC entries last.
|
||||
sorted_content = sorted(
|
||||
content.items(),
|
||||
key=lambda x: (len(x[0]) == 1, x[0]),
|
||||
)
|
||||
return sorted_content, collapse
|
||||
|
||||
|
||||
class QAPIDomain(Domain):
|
||||
"""QAPI language domain."""
|
||||
|
||||
|
@ -54,7 +118,10 @@ class QAPIDomain(Domain):
|
|||
"objects": {}, # fullname -> ObjectEntry
|
||||
}
|
||||
|
||||
indices = []
|
||||
# Index pages to generate; each entry is an Index class.
|
||||
indices = [
|
||||
QAPIIndex,
|
||||
]
|
||||
|
||||
@property
|
||||
def objects(self) -> Dict[str, ObjectEntry]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue