9from sphinx
import addnodes
10from sphinx.roles
import XRefRole
11from sphinx.directives
import ObjectDescription
12from sphinx.domains
import Domain, ObjType, Index
13from sphinx.util.docfields
import TypedField, Field
14from sphinx.util.nodes
import make_refnode
15from sphinx.util
import logging
16logger = logging.getLogger(__name__)
21 A basf2 x-ref directive registered with Sphinx.add_object_type().
22 Basically copied together
from sphinxcontrib-domaintools
and sphinxcontrib-adadomain.
25## \cond Doxygen_suppress
28 TypedField("parameter", label=
"Parameters", names=(
"param",
"parameter",
"arg",
"argument"),
29 typenames=(
"paramtype",
"type"), typerolename=
None, can_collapse=
True),
30 Field(
'returnvalue', label=
'Returns', has_arg=
False,
31 names=(
'returns',
'return')),
34 def handle_signature(self, sig, signode):
39 name, args = sig.split(
"(", 1)
46 signode += addnodes.desc_name(name, name)
51 paramlist = addnodes.desc_parameterlist()
52 for arg
in (e.strip()
for e
in args[:-1].split(
",")):
55 paramlist += addnodes.desc_parameter(arg, arg)
63 def add_target_and_index(self, name, sig, signode):
65 targetname = f
'{self.objtype}-{name}'
67 signode[
'ids'].append(targetname)
68 self.state.document.note_explicit_target(signode)
72 ddata = self.env.domaindata[
"b2"][self.objtype +
's']
76 logger.warn(f
"Duplicate description of basf2 {self.objtype} {name}, " +
77 "Other instance in " + self.env.doc2path(ddata[name][0]) +
78 ", please add ':noindex:' to one",
79 location=(self.env.docname, self.lineno))
81 ddata[name] = (self.env.docname, targetname)
85 """Create an alphabetic index of all modules"""
88 localname =
"basf2 Module Index"
89 shortname =
"basf2 modules"
91 def generate(self, docnames=None):
93 modules = self.domain.data[
"modules"].items()
94 for modname, (docname, target)
in sorted(modules):
95 letter = modname[0].upper()
96 content.setdefault(letter, [])
97 content[letter].append([modname, 0, docname, target,
"",
"",
""])
98 return list(content.items()),
False
103 """Create an alphabetic index of all variables"""
106 localname =
"basf2 Variable Index"
107 shortname =
"basf2 variables"
109 def generate(self, docnames=None):
111 modules = self.domain.data[
"variables"].items()
112 modules = sorted(modules, key=
lambda x: x[0].lower())
113 for modname, (docname, target)
in modules:
114 letter = modname[0].upper()
115 content.setdefault(letter, [])
116 content[letter].append([modname, 0, docname, target,
"",
"",
""])
117 return list(content.items()),
False
122 """basf2 Software Domain"""
125 label =
"Belle II Software"
127 "module": ObjType(
"module",
"mod"),
128 "variable": ObjType(
"variable",
"var")
132 "module": Basf2Object,
133 "variable": Basf2Object,
150 """Remove the existing domain data for a given document name"""
151 for t
in "modules",
"variables":
153 for name, (doc, target)
in list(self.data[t].items()):
155 del self.data[t][name]
160 def get_objects(self):
161 for i, type
in enumerate([
"modules",
"variables"]):
162 for name, (docname, target)
in self.data[type].items():
163 yield(name, name, type, docname, target, i)
165 def get_type_name(self, type, primary=False):
169 def resolve_xref(self, env, fromdocname, builder,
170 typ, target, node, contnode):
171 t = {
"mod":
"modules",
"var":
"variables"}[typ]
173 docname, labelid = self.data[t][target]
174 return make_refnode(builder, fromdocname, docname,
def clear_doc(self, docname)