9 from sphinx
import addnodes
10 from sphinx.roles
import XRefRole
11 from sphinx.directives
import ObjectDescription
12 from sphinx.domains
import Domain, ObjType, Index
13 from sphinx.util.docfields
import TypedField, Field
14 from sphinx.util.nodes
import make_refnode
15 from sphinx.util
import logging
16 logger = 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.
26 TypedField(
"parameter", label=
"Parameters", names=(
"param",
"parameter",
"arg",
"argument"),
27 typenames=(
"paramtype",
"type"), typerolename=
None, can_collapse=
True),
28 Field(
'returnvalue', label=
'Returns', has_arg=
False,
29 names=(
'returns',
'return')),
32 def handle_signature(self, sig, signode):
37 name, args = sig.split(
"(", 1)
44 signode += addnodes.desc_name(name, name)
49 paramlist = addnodes.desc_parameterlist()
50 for arg
in (e.strip()
for e
in args[:-1].split(
",")):
53 paramlist += addnodes.desc_parameter(arg, arg)
59 def add_target_and_index(self, name, sig, signode):
61 targetname =
'%s-%s' % (self.objtype, name)
63 signode[
'ids'].append(targetname)
64 self.state.document.note_explicit_target(signode)
68 ddata = self.env.domaindata[
"b2"][self.objtype +
's']
72 logger.warn(
"Duplicate description of basf2 %s %s, " % (self.objtype, name) +
73 "Other instance in " + self.env.doc2path(ddata[name][0]) +
74 ", please add ':noindex:' to one",
75 location=(self.env.docname, self.lineno))
77 ddata[name] = (self.env.docname, targetname)
81 """Create an alphabetic index of all modules"""
83 localname =
"basf2 Module Index"
84 shortname =
"basf2 modules"
86 def generate(self, docnames=None):
88 modules = self.domain.data[
"modules"].items()
89 for modname, (docname, target)
in sorted(modules):
90 letter = modname[0].upper()
91 content.setdefault(letter, [])
92 content[letter].append([modname, 0, docname, target,
"",
"",
""])
93 return list(content.items()),
False
97 """Create an alphabetic index of all variables"""
99 localname =
"basf2 Variable Index"
100 shortname =
"basf2 variables"
102 def generate(self, docnames=None):
104 modules = self.domain.data[
"variables"].items()
105 modules = sorted(modules, key=
lambda x: x[0].lower())
106 for modname, (docname, target)
in modules:
107 letter = modname[0].upper()
108 content.setdefault(letter, [])
109 content[letter].append([modname, 0, docname, target,
"",
"",
""])
110 return list(content.items()),
False
114 """basf2 Software Domain"""
116 label =
"Belle II Software"
118 "module": ObjType(
"module",
"mod"),
119 "variable": ObjType(
"variable",
"var")
123 "module": Basf2Object,
124 "variable": Basf2Object,
140 """Remove the existing domain data for a given document name"""
141 for t
in "modules",
"variables":
143 for name, (doc, target)
in list(self.data[t].items()):
145 del self.data[t][name]
149 def get_objects(self):
150 for i, type
in enumerate([
"modules",
"variables"]):
151 for name, (docname, target)
in self.data[type].items():
152 yield(name, name, type, docname, target, i)
154 def get_type_name(self, type, primary=False):
158 def resolve_xref(self, env, fromdocname, builder,
159 typ, target, node, contnode):
160 t = {
"mod":
"modules",
"var":
"variables"}[typ]
162 docname, labelid = self.data[t][target]
163 return make_refnode(builder, fromdocname, docname,
def clear_doc(self, docname)