Skip to content

Commit 74d40b0

Browse files
jnsnowMarkus Armbruster
authored andcommitted
docs/qapi_domain: add namespace support to FQN
This patch adds a namespace component to the "Fully Qualified Name", in the form of "domain:module.name". As there are no namespace directives or options yet, this component will simply be empty as of this patch. 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 e36afc7 commit 74d40b0

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

docs/sphinx/qapi_domain.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,18 @@ 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:
181+
def _get_context(self) -> Tuple[str, str]:
182+
namespace = self.options.get(
183+
"namespace", self.env.ref_context.get("qapi:namespace", "")
184+
)
182185
modname = self.options.get(
183186
"module", self.env.ref_context.get("qapi:module", "")
184187
)
185-
assert isinstance(modname, str)
186-
return modname
188+
189+
return namespace, modname
187190

188191
def _get_fqn(self, name: Signature) -> str:
189-
modname = self._get_context()
192+
namespace, modname = self._get_context()
190193

191194
# If we're documenting a module, don't include the module as
192195
# part of the FQN; we ARE the module!
@@ -195,6 +198,8 @@ def _get_fqn(self, name: Signature) -> str:
195198

196199
if modname:
197200
name = f"{modname}.{name}"
201+
if namespace:
202+
name = f"{namespace}:{name}"
198203
return name
199204

200205
def add_target_and_index(
@@ -227,13 +232,18 @@ def add_target_and_index(
227232
)
228233

229234
@staticmethod
230-
def split_fqn(name: str) -> Tuple[str, str]:
235+
def split_fqn(name: str) -> Tuple[str, str, str]:
236+
if ":" in name:
237+
ns, name = name.split(":")
238+
else:
239+
ns = ""
240+
231241
if "." in name:
232242
module, name = name.split(".")
233243
else:
234244
module = ""
235245

236-
return (module, name)
246+
return (ns, module, name)
237247

238248
def _object_hierarchy_parts(
239249
self, sig_node: desc_signature
@@ -251,14 +261,18 @@ def _toc_entry_name(self, sig_node: desc_signature) -> str:
251261
return ""
252262

253263
config = self.env.app.config
254-
modname, name = toc_parts
264+
namespace, modname, name = toc_parts
255265

256266
if config.toc_object_entries_show_parents == "domain":
257267
ret = name
258268
if modname and modname != self.env.ref_context.get(
259269
"qapi:module", ""
260270
):
261271
ret = f"{modname}.{name}"
272+
if namespace and namespace != self.env.ref_context.get(
273+
"qapi:namespace", ""
274+
):
275+
ret = f"{namespace}:{ret}"
262276
return ret
263277
if config.toc_object_entries_show_parents == "hide":
264278
return name
@@ -334,10 +348,15 @@ def handle_signature(self, sig: str, signode: desc_signature) -> Signature:
334348
As such, the only argument here is "sig", which is just the QAPI
335349
definition name.
336350
"""
337-
modname = self._get_context()
351+
# No module or domain info allowed in the signature!
352+
assert ":" not in sig
353+
assert "." not in sig
338354

355+
namespace, modname = self._get_context()
339356
signode["fullname"] = self._get_fqn(sig)
357+
signode["namespace"] = namespace
340358
signode["module"] = modname
359+
341360
sig_prefix = self.get_signature_prefix()
342361
if sig_prefix:
343362
signode += addnodes.desc_annotation(

0 commit comments

Comments
 (0)