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