Belle II Software light-2509-fornax
conf.py
1#!/usr/bin/env python3
2#
3# basf2 documentation build configuration file, created by
4# sphinx-quickstart on Mon May 23 17:26:16 2016.
5#
6# This file is execfile()d with the current directory set to its
7# containing dir.
8#
9# Note that not all possible configuration values are present in this
10# autogenerated file.
11#
12# All configuration values have a default; values that are commented out
13# serve to show the default.
14
15import sys
16import os
17import re
18import subprocess
19
20sys.path.insert(0, os.path.abspath("extensions"))
21
22# If extensions (or modules to document with autodoc) are in another directory,
23# add these directories to sys.path here. If the directory is relative to the
24# documentation root, use os.path.abspath to make it absolute, like shown here.
25# sys.path.insert(0, os.path.abspath('....'))
26
27# -- General configuration ------------------------------------------------
28
29# If your documentation needs a minimal Sphinx version, state it here.
30# needs_sphinx = '1.0'
31
32# Add any Sphinx extension module names here, as strings. They can be
33# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
34# ones.
35extensions = [
36 'sphinx.ext.intersphinx',
37 'sphinx.ext.autodoc',
38 # 'sphinx.ext.autosummary',
39 'sphinx.ext.mathjax',
40 'sphinx.ext.napoleon',
41 'sphinx.ext.viewcode',
42 'sphinx.ext.autosectionlabel',
43 'sphinx_codeautolink',
44 'sphinx_togglebutton',
45 'sphinxarg.ext',
46 'basf2ext',
47 'nbsphinx',
48 'sphinxcontrib.programoutput',
49 'IPython.sphinxext.ipython_console_highlighting',
50]
51
52# Codeautolink warnings for compilation. Turned off due to conflicts with line
53# numbering.
54codeautolink_warn_on_missing_inventory = False
55codeautolink_warn_on_failed_resolve = False
56
57basf2_doxygen_xml_dir = f"{os.environ.get('BELLE2_RELEASE_DIR', os.environ.get('BELLE2_LOCAL_DIR'))}/build/doxygen/xml"
58
59nbsphinx_allow_errors = True
60
61# autosummary_generate = True
62
63# prefix each section with the name of the document it is in followed by a
64# colon
65autosectionlabel_prefix_document = True
66suppress_warnings = ['autosectionlabel.*', 'codeautolink.*']
67
68# The text that appears on the toggle buttons (default is "Click to show")
69togglebutton_hint = "Click to reveal"
70
71# What CSS selectors get the toggle behaviour.
72# This is the magic: it looks for admonitions with 'dropdown' class
73togglebutton_selector = ".toggle, .admonition.dropdown"
74
75# Optional: add the little "▶/▼" icons
76togglebutton_hint_toggle = "▶▼"
77
78# Add any paths that contain templates here, relative to this directory.
79templates_path = ['_sphinxtemplates']
80
81# The suffix(es) of source filenames.
82# You can specify multiple suffix as a list of string:
83# source_suffix = ['.rst', '.md']
84source_suffix = '.rst'
85
86# The encoding of source files.
87# source_encoding = 'utf-8-sig'
88
89# The master toctree document.
90master_doc = 'index'
91
92# General information about the project.
93project = 'basf2'
94copyright = 'Belle II Collaboration'
95author = 'Belle II Software Group'
96
97# The version info for the project you're documenting, acts as replacement for
98# |version| and |release|, also used in various other places throughout the
99# built documents.
100#
101# The short X.Y version.
102version = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode().strip()
103# Used for links to the repository
104basf2_repository = "https://gitlab.desy.de/belle2/software/basf2/"
105basf2_commitid = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
106basf2_issues = "https://gitlab.desy.de/belle2/software/basf2/-/issues/"
107
108# The full version, including alpha/beta/rc tags.
109release = os.environ.get('BELLE2_RELEASE', 'development')
110if release == 'head':
111 release = 'development'
112
113# Add warnings in the code if this is not a release
114keep_warnings = release == "development"
115nitpicky = keep_warnings
116
117# Mask false warnings
118nitpick_ignore = []
119for entry in ['cppyy.gbl.TObject', 'cppyy.gbl.TFile', 'ROOT.TFile']:
120 nitpick_ignore.append(('py:class', entry))
121for entry in ['int', 'bool', 'list', 'str', 'object', 'None', 'LogConfig', 'ProcessStatistics.ModuleStatistics']:
122 nitpick_ignore.append(('py:class', entry + ' :'))
123
124basf2_doxygen_baseurl = f"https://software.belle2.org/{release}/doxygen/"
125
126# The language for content autogenerated by Sphinx. Refer to documentation
127# for a list of supported languages.
128#
129# This is also used if you do content translation via gettext catalogs.
130# Usually you set "language" from the command line for these cases.
131language = 'en'
132
133# There are two options for replacing |today|: either, you set today to some
134# non-false value, then it is used:
135# today = ''
136# Else, today_fmt is used as the format for a strftime call.
137# today_fmt = '%B %d, %Y'
138
139# List of patterns, relative to source directory, that match files and
140# directories to ignore when looking for source files.
141# This patterns also effect to html_static_path and html_extra_path
142exclude_patterns = ['.*', '_sphinxbuild', 'Thumbs.db', 'build', 'include', 'lib', 'bin', 'modules', 'data', 'site_scons']
143# If we want to create the light release documentation then we need to exclude anything not in the light release.
144if tags.has('light'): # noqa
145 light_packages = {entry.strip('/') for entry in open('../../.light').read().split() if entry.endswith('/')}
146 for entry in os.listdir("../../"):
147 if entry.find('.') > -1 or os.path.isfile(entry) or entry in exclude_patterns or entry in light_packages:
148 continue
149 exclude_patterns.append(entry)
150 del light_packages
151
152# now we need to exclude everything in the build dir except for the tools_doc
153# sub dir but there's no negative exclusion pattern so do it manually
154exclude_patterns.remove("build")
155exclude_patterns += ['build/html', 'build/latex', 'build/json', 'build/Linux*', 'build/belle2_tools']
156# Ignore jupyter notebooks by default, we only want the ones meant for documentation
157exclude_patterns += ['**/*.ipynb', '*.ipynb']
158
159# The reST default role (used for this markup: `text`) to use for all
160# documents. :any: allows easy linking to functions/classes/modules
161default_role = 'any'
162
163# If true, '()' will be appended to :func: etc. cross-reference text.
164# add_function_parentheses = True
165
166# If true, the current module name will be prepended to all description
167# unit titles (such as .. function::).
168# add_module_names = True
169
170# If true, sectionauthor and moduleauthor directives will be shown in the
171# output. They are ignored by default.
172# show_authors = False
173
174# The name of the Pygments (syntax highlighting) style to use.
175pygments_style = 'sphinx'
176
177# A list of ignored prefixes for module index sorting.
178# modindex_common_prefix = []
179
180# If true, keep warnings as "system message" paragraphs in the built documents.
181# keep_warnings = False
182
183# If true, `todo` and `todoList` produce output, else they produce nothing.
184todo_include_todos = False
185
186# If true, figures with captions automatically get figure numbers included at the start of the caption.
187# Also the :numref: role is allowed for figures. Referencing figures/sections etc in this way
188# will insert a reference to the reference number instead of the reference text/caption.
189numfig = True
190
191# -- Options for HTML output ----------------------------------------------
192
193# The theme to use for HTML and HTML Help pages. See the documentation for
194# a list of builtin themes.
195html_theme = 'sphinx_book_theme'
196
197# Theme options are theme-specific and customize the look and feel of a theme
198# further. For a list of options available for each theme, see the
199# documentation.
200# html_theme_options = {'stickysidebar': True}
201
202# Add any paths that contain custom themes here, relative to this directory.
203html_theme_path = ["_themes", ]
204
205# The name for this set of Sphinx documents.
206# "<project> v<release> documentation" by default.
207# html_title = 'basf2 vhead'
208
209# A shorter title for the navigation bar. Default is the same as html_title.
210# html_short_title = None
211
212# The name of an image file (relative to this directory) to place at the top
213# of the sidebar.
214html_logo = "b2logo.svg"
215
216# The name of an image file (relative to this directory) to use as a favicon of
217# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
218# pixels large.
219# html_favicon = None
220
221# Add any paths that contain custom static files (such as style sheets) here,
222# relative to this directory. They are copied after the builtin static files,
223# so a file named "default.css" will overwrite the builtin "default.css".
224html_static_path = ['_sphinxstatic']
225
226# Add any extra paths that contain custom files (such as robots.txt or
227# .htaccess) here, relative to this directory. These files are copied
228# directly to the root of the documentation.
229# html_extra_path = []
230
231# If not None, a 'Last updated on:' timestamp is inserted at every page
232# bottom, using the given strftime format.
233# The empty string is equivalent to '%b %d, %Y'.
234# html_last_updated_fmt = None
235
236# If true, SmartyPants will be used to convert quotes and dashes to
237# typographically correct entities.
238# html_use_smartypants = True
239
240# Custom sidebar templates, maps document names to template names.
241# html_sidebars = {}
242
243# Additional templates that should be rendered to pages, maps page names to
244# template names.
245# html_additional_pages = {}
246
247# If false, no module index is generated.
248# html_domain_indices = True
249
250# If false, no index is generated.
251# html_use_index = True
252
253# If true, the index is split into individual pages for each letter.
254# html_split_index = False
255
256# If true, links to the reST sources are added to the pages.
257# html_show_sourcelink = True
258
259# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
260# html_show_sphinx = True
261
262# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
263# html_show_copyright = True
264
265# If true, an OpenSearch description file will be output, and all pages will
266# contain a <link> tag referring to it. The value of this option must be the
267# base URL from which the finished HTML is served.
268# html_use_opensearch = ''
269
270# This is the file name suffix for HTML files (e.g. ".xhtml").
271# html_file_suffix = None
272
273# Language to be used for generating the HTML full-text search index.
274# Sphinx supports the following languages:
275# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
276# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh'
277# html_search_language = 'en'
278
279# A dictionary with options for the search language support, empty by default.
280# 'ja' uses this config value.
281# 'zh' user can custom change `jieba` dictionary path.
282# html_search_options = {'type': 'default'}
283
284# The name of a javascript file (relative to the configuration directory) that
285# implements a search results scorer. If empty, the default will be used.
286# html_search_scorer = 'scorer.js'
287
288# Output file base name for HTML help builder.
289htmlhelp_basename = 'basf2doc'
290
291# -- Options for LaTeX output ---------------------------------------------
292
293latex_elements = {
294 # The paper size ('letterpaper' or 'a4paper').
295 'papersize': 'a4paper',
296
297 # The font size ('10pt', '11pt' or '12pt').
298 'pointsize': '10pt',
299
300 # Additional stuff for the LaTeX preamble.
301 'preamble': '\\setcounter{tocdepth}{2}',
302
303 # Latex figure (float) alignment
304 # 'figure_align': 'htbp',
305}
306
307# Grouping the document tree into LaTeX files. List of tuples
308# (source start file, target name, title,
309# author, documentclass [howto, manual, or own class]).
310latex_documents = [
311 (master_doc, 'basf2.tex', 'Belle II Software Documentation',
312 author, 'manual'),
313]
314
315# The name of an image file (relative to this directory) to place at the top of
316# the title page.
317latex_logo = "belle2-logo.pdf"
318
319# For "manual" documents, if this is true, then toplevel headings are parts,
320# not chapters.
321latex_use_parts = True
322latex_show_urls = 'footnote'
323latex_show_pagerefs = True
324
325# If true, show page references after internal links.
326# latex_show_pagerefs = False
327
328# If true, show URL addresses after external links.
329# latex_show_urls = False
330
331# Documents to append as an appendix to all manuals.
332# latex_appendices = []
333
334# If false, no module index is generated.
335# latex_domain_indices = True
336
337
338# -- Options for manual page output ---------------------------------------
339
340# One entry per manual page. List of tuples
341# (source start file, name, description, authors, manual section).
342man_pages = [
343 (master_doc, 'basf2', 'basf2 Documentation',
344 [author], 1)
345]
346
347# If true, show URL addresses after external links.
348# man_show_urls = False
349
350
351# -- Options for Texinfo output -------------------------------------------
352
353# Grouping the document tree into Texinfo files. List of tuples
354# (source start file, target name, title, author,
355# dir menu entry, description, category)
356texinfo_documents = [
357 (master_doc, 'basf2', 'basf2 Documentation',
358 author, 'basf2', 'One line description of project.',
359 'Miscellaneous'),
360]
361
362# Documents to append as an appendix to all manuals.
363# texinfo_appendices = []
364
365# If false, no module index is generated.
366# texinfo_domain_indices = True
367
368# How to display URL addresses: 'footnote', 'no', or 'inline'.
369# texinfo_show_urls = 'footnote'
370
371# If true, do not generate a @detailmenu in the "Top" node's menu.
372# texinfo_no_detailmenu = False
373
374# allow to have links to python documentation
375intersphinx_mapping = {'python': ('https://docs.python.org/3.11/', None),
376 'numpy': ('https://numpy.org/doc/stable/', None),
377 'scipy': ('https://docs.scipy.org/doc/scipy/', None),
378 'pandas': ('https://pandas.pydata.org/docs/', None),
379 'matplotlib': ('https://matplotlib.org/stable/', None),
380 'b2luigi': ('https://b2luigi.belle2.org/', None),
381 'gbasf2': ('https://gbasf2.belle2.org/', None),
382 'uproot': ('https://uproot.readthedocs.io/en/stable/', None)}
383
384
385def process_sig(app, what, name, obj, options, signature, return_annotation):
386 """
387 remove unhelpful 'self' arguments from methods.
388 """
389 if what == 'method' and signature:
390 reg = re.compile('^\\( \\(.*\\)arg1')
391 signature = reg.sub('(', signature)
392 return (signature, return_annotation)
393
394
395def improve_docstring(obj):
396 """
397 Enhances docstrings of PyROOT objects/classes.
398
399 >>> improve_docstring(Belle2.Variable.Manager)
400
401 or
402
403 >>> variables = ROOT.Belle2.Variable.Manager
404 >>> improve_docstring(variables)
405 """
406 try:
407 # is this a ..._meta object?
408 classname = obj.__name__
409 pyclass = obj
410 except AttributeError:
411 classname = obj.__class__.__name__
412 pyclass = obj.__class__
413
414 if '::' not in classname:
415 return # not a ROOT class?
416 pos = classname.find('Belle2::')
417 classname = classname[pos:]
418 if pyclass.__doc__ is None:
419 pyclass.__doc__ = ''
420
421 pyclass.__name__ = 'Belle2.' + classname
422
423 from ROOT import TClass
424 tclass = TClass(classname)
425 # if tclass:
426 # pyclass.__doc__ += '\n' + tclass.GetTitle()
427
428 doxygen_url = f'{basf2_doxygen_baseurl}/class'
429 doxygen_url += '_1_1'.join(classname.split('::'))
430 doxygen_url += '.html'
431 pyclass.__doc__ += f'\n`Doxygen page for {classname} <{doxygen_url}>`_'
432
433 # TODO put this into the member docstrings directly? (sadly, readonly)
434 members = tclass.GetListOfMethods()
435 if members.GetEntries() > 0:
436 pyclass.__doc__ += '\n\nMember functions:'
437 for f in members:
438 # getattr(pyclass, f.GetName()).__doc__ = "test"
439 pyclass.__doc__ += f'\n * {f.GetReturnTypeName()} {f.GetName()}{f.GetSignature()}'
440 title = f.GetTitle()
441 if title:
442 pyclass.__doc__ += f' ({title})'
443
444 members = tclass.GetListOfAllPublicDataMembers()
445 if members.GetEntries() > 0:
446 pyclass.__doc__ += '\n\nPublic data members'
447 for f in members:
448 pyclass.__doc__ += f'\n * {f.GetName()}'
449 title = f.GetTitle()
450 if title:
451 pyclass.__doc__ += f' ({title})'
452
453
454def skipmember(app, what, name, obj, skip, options):
455 """
456 This is executed before docstring processing,
457 so try improving them a bit.
458 """
459 try:
460 improve_docstring(obj)
461 except AttributeError:
462 pass
463 return skip
464
465
466def process_docstring(app, what, name, obj, options, lines):
467 """
468 convert doxygen syntax to sphinx
469 """
470 substitutions = {
471 re.compile(r'^( *)@param (.*?):? '): r':param \2: ',
472 re.compile(r'^( *)@returns? '): r':return: ',
473 }
474 newlines = []
475 for line in lines:
476 new = line
477 for reg, sub in substitutions.items():
478 new = reg.sub(sub, new)
479 if new != line:
480 # Sphinx wants a new paragraph before these, so let's add one
481 newlines += ['']
482 newlines += [new]
483 lines[:] = newlines
484
485
486def setup(app):
487 """
488 Install some event handlers to improve output.
489 """
490 app.connect('autodoc-process-signature', process_sig)
491 app.connect('autodoc-process-docstring', process_docstring)
492 app.connect('autodoc-skip-member', skipmember)
493 app.add_css_file('css/custom.css')