22 sys.path.insert(0, os.path.abspath(
"extensions"))
38 'sphinx.ext.intersphinx',
42 'sphinx.ext.napoleon',
43 'sphinx.ext.viewcode',
44 'sphinx.ext.autosectionlabel',
45 'sphinx_codeautolink',
49 'sphinxcontrib.programoutput',
50 'IPython.sphinxext.ipython_console_highlighting',
55 codeautolink_warn_on_missing_inventory =
False
56 codeautolink_warn_on_failed_resolve =
False
58 nbsphinx_allow_errors =
True
63 nbsphinx_custom_formats = {
64 '.doc.jupy.py':
lambda s: jupytext.reads(s,
'.py'),
71 autosectionlabel_prefix_document =
True
72 suppress_warnings = [
'autosectionlabel.*',
'codeautolink.*']
75 templates_path = [
'_sphinxtemplates']
80 source_suffix =
'.rst'
90 copyright =
'Belle II Collaboration'
91 author =
'Belle II Software Group'
98 version = subprocess.check_output([
"git",
"rev-parse",
"--short",
"HEAD"]).decode().strip()
100 basf2_repository =
"https://gitlab.desy.de/belle2/software/basf2/"
101 basf2_commitid = subprocess.check_output([
"git",
"rev-parse",
"HEAD"]).decode().strip()
102 basf2_issues =
"https://gitlab.desy.de/belle2/software/basf2/-/issues/"
105 release = os.environ.get(
'BELLE2_RELEASE',
'development')
106 if release ==
'head':
107 release =
'development'
110 keep_warnings = release ==
"development"
111 nitpicky = keep_warnings
115 for entry
in [
'cppyy.gbl.TObject',
'cppyy.gbl.TFile',
'ROOT.TFile']:
116 nitpick_ignore.append((
'py:class', entry))
117 for entry
in [
'int',
'bool',
'list',
'str',
'object',
'None',
'LogConfig',
'ModuleStatistics']:
118 nitpick_ignore.append((
'py:class', entry +
' :'))
136 exclude_patterns = [
'.*',
'_sphinxbuild',
'Thumbs.db',
'build',
'include',
'lib',
'bin',
'modules',
'data',
'site_scons']
138 if tags.has(
'light'):
139 light_packages = set([entry.strip(
'/')
for entry
in open(
'../../.light').read().split()
if entry.endswith(
'/')])
140 for entry
in os.listdir(
"../../"):
141 if entry.find(
'.') > -1
or os.path.isfile(entry)
or entry
in exclude_patterns
or entry
in light_packages:
143 exclude_patterns.append(entry)
148 exclude_patterns.remove(
"build")
149 exclude_patterns += [
'build/html',
'build/latex',
'build/json',
'build/Linux*',
'build/belle2_tools']
151 exclude_patterns += [
'**/*.ipynb',
'*.ipynb']
169 pygments_style =
'sphinx'
178 todo_include_todos =
False
189 html_theme =
'sphinx_book_theme'
197 html_theme_path = [
"_themes", ]
208 html_logo =
"b2logo.svg"
218 html_static_path = [
'_sphinxstatic']
283 htmlhelp_basename =
'basf2doc'
289 'papersize':
'a4paper',
295 'preamble':
'\\setcounter{tocdepth}{2}',
305 (master_doc,
'basf2.tex',
'Belle II Software Documentation',
311 latex_logo =
"belle2-logo.pdf"
315 latex_use_parts =
True
316 latex_show_urls =
'footnote'
317 latex_show_pagerefs =
True
337 (master_doc,
'basf2',
'basf2 Documentation',
350 texinfo_documents = [
351 (master_doc,
'basf2',
'basf2 Documentation',
352 author,
'basf2',
'One line description of project.',
369 intersphinx_mapping = {
'python': (
'https://docs.python.org/3.8/',
None),
370 'numpy': (
'https://numpy.org/doc/stable/',
None),
371 'scipy': (
'https://docs.scipy.org/doc/scipy/',
None),
372 'pandas': (
'https://pandas.pydata.org/docs/',
None),
373 'matplotlib': (
'https://matplotlib.org/stable/',
None),
374 'uproot': (
'https://uproot.readthedocs.io/en/stable/',
None)}
377 def process_sig(app, what, name, obj, options, signature, return_annotation):
379 remove unhelpful 'self' arguments from methods.
381 if what ==
'method' and signature:
382 reg = re.compile(
'^\\( \\(.*\\)arg1')
383 signature = reg.sub(
'(', signature)
384 return (signature, return_annotation)
387 def improve_docstring(obj):
389 Enhances docstrings of PyROOT objects/classes.
391 >>> improve_docstring(Belle2.Variable.Manager)
395 >>> variables = ROOT.Belle2.Variable.Manager
396 >>> improve_docstring(variables)
400 classname = obj.__name__
402 except AttributeError:
403 classname = obj.__class__.__name__
404 pyclass = obj.__class__
406 if '::' not in classname:
408 pos = classname.find(
'Belle2::')
409 classname = classname[pos:]
410 if pyclass.__doc__
is None:
413 pyclass.__name__ =
'Belle2.' + classname
415 from ROOT
import TClass
416 tclass = TClass(classname)
420 doxygen_url =
'https://software.belle2.org/development/class'
421 doxygen_url +=
'_1_1'.join(classname.split(
'::'))
422 doxygen_url +=
'.html'
423 pyclass.__doc__ +=
'\n`Doxygen page for %s <%s>`_' % (classname, doxygen_url)
426 members = tclass.GetListOfMethods()
427 if members.GetEntries() > 0:
428 pyclass.__doc__ +=
'\n\nMember functions:'
431 pyclass.__doc__ +=
'\n * %s %s%s' % (f.GetReturnTypeName(), f.GetName(), f.GetSignature())
434 pyclass.__doc__ +=
' (%s)' % (title)
436 members = tclass.GetListOfAllPublicDataMembers()
437 if members.GetEntries() > 0:
438 pyclass.__doc__ +=
'\n\nPublic data members'
440 pyclass.__doc__ +=
'\n * %s' % (f.GetName())
443 pyclass.__doc__ +=
' (%s)' % (title)
446 def skipmember(app, what, name, obj, skip, options):
448 This is executed before docstring processing,
449 so try improving them a bit.
452 improve_docstring(obj)
453 except AttributeError:
458 def process_docstring(app, what, name, obj, options, lines):
460 convert doxygen syntax to sphinx
463 re.compile(
r'^( *)@param (.*?):? '):
r':param \2: ',
464 re.compile(
r'^( *)@returns? '):
r':return: ',
469 for reg, sub
in substitutions.items():
470 new = reg.sub(sub, new)
480 Install some event handlers to improve output.
482 app.connect(
'autodoc-process-signature', process_sig)
483 app.connect(
'autodoc-process-docstring', process_docstring)
484 app.connect(
'autodoc-skip-member', skipmember)
485 app.add_css_file(
'css/custom.css')
491 from sphinx.ext
import autodoc
493 old_directive_header = autodoc.PropertyDocumenter.add_directive_header
497 def _fixed_directive_header(*args, **argk):
498 """Catch the ValueError and ignore it as done in https://github.com/sphinx-doc/sphinx/pull/9190"""
500 old_directive_header(*args, **argk)
506 autodoc.PropertyDocumenter.add_directive_header = _fixed_directive_header