Skip to content

Commit e36afc7

Browse files
jnsnowMarkus Armbruster
authored andcommitted
docs/qapi-domain: always store fully qualified name in signode
Currently, only the definition name is stored in the tree metadata; but the node property is confusingly called "fullname". Rectify this by always storing the FQN in the tree metadata. ... While we're here, re-organize the code in preparation for namespace support to make it a bit easier to add additional components of the FQN. With this change, there is now extremely little code left that's taken directly from the Python domain :) 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 8fad366 commit e36afc7

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

docs/sphinx/qapi_domain.py

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ def get_index_text(self, name: Signature) -> Tuple[str, str]:
178178
# NB: this is used for the global index, not the QAPI index.
179179
return ("single", f"{name} (QMP {self.objtype})")
180180

181+
def _get_context(self) -> str:
182+
modname = self.options.get(
183+
"module", self.env.ref_context.get("qapi:module", "")
184+
)
185+
assert isinstance(modname, str)
186+
return modname
187+
188+
def _get_fqn(self, name: Signature) -> str:
189+
modname = self._get_context()
190+
191+
# If we're documenting a module, don't include the module as
192+
# part of the FQN; we ARE the module!
193+
if self.objtype == "module":
194+
modname = ""
195+
196+
if modname:
197+
name = f"{modname}.{name}"
198+
return name
199+
181200
def add_target_and_index(
182201
self, name: Signature, sig: str, signode: desc_signature
183202
) -> None:
@@ -187,14 +206,8 @@ def add_target_and_index(
187206

188207
assert self.objtype
189208

190-
# If we're documenting a module, don't include the module as
191-
# part of the FQN.
192-
modname = ""
193-
if self.objtype != "module":
194-
modname = self.options.get(
195-
"module", self.env.ref_context.get("qapi:module")
196-
)
197-
fullname = (modname + "." if modname else "") + name
209+
if not (fullname := signode.get("fullname", "")):
210+
fullname = self._get_fqn(name)
198211

199212
node_id = make_id(
200213
self.env, self.state.document, self.objtype, fullname
@@ -213,18 +226,21 @@ def add_target_and_index(
213226
(arity, indextext, node_id, "", None)
214227
)
215228

229+
@staticmethod
230+
def split_fqn(name: str) -> Tuple[str, str]:
231+
if "." in name:
232+
module, name = name.split(".")
233+
else:
234+
module = ""
235+
236+
return (module, name)
237+
216238
def _object_hierarchy_parts(
217239
self, sig_node: desc_signature
218240
) -> Tuple[str, ...]:
219241
if "fullname" not in sig_node:
220242
return ()
221-
modname = sig_node.get("module")
222-
fullname = sig_node["fullname"]
223-
224-
if modname:
225-
return (modname, *fullname.split("."))
226-
227-
return tuple(fullname.split("."))
243+
return self.split_fqn(sig_node["fullname"])
228244

229245
def _toc_entry_name(self, sig_node: desc_signature) -> str:
230246
# This controls the name in the TOC and on the sidebar.
@@ -235,13 +251,19 @@ def _toc_entry_name(self, sig_node: desc_signature) -> str:
235251
return ""
236252

237253
config = self.env.app.config
238-
*parents, name = toc_parts
254+
modname, name = toc_parts
255+
239256
if config.toc_object_entries_show_parents == "domain":
240-
return sig_node.get("fullname", name)
257+
ret = name
258+
if modname and modname != self.env.ref_context.get(
259+
"qapi:module", ""
260+
):
261+
ret = f"{modname}.{name}"
262+
return ret
241263
if config.toc_object_entries_show_parents == "hide":
242264
return name
243265
if config.toc_object_entries_show_parents == "all":
244-
return ".".join(parents + [name])
266+
return sig_node.get("fullname", name)
245267
return ""
246268

247269

@@ -312,11 +334,9 @@ def handle_signature(self, sig: str, signode: desc_signature) -> Signature:
312334
As such, the only argument here is "sig", which is just the QAPI
313335
definition name.
314336
"""
315-
modname = self.options.get(
316-
"module", self.env.ref_context.get("qapi:module")
317-
)
337+
modname = self._get_context()
318338

319-
signode["fullname"] = sig
339+
signode["fullname"] = self._get_fqn(sig)
320340
signode["module"] = modname
321341
sig_prefix = self.get_signature_prefix()
322342
if sig_prefix:

0 commit comments

Comments
 (0)