conf.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Configuration file for the Sphinx documentation builder.
  4. #
  5. # This file does only contain a selection of the most common options. For a
  6. # full list see the documentation:
  7. # http://www.sphinx-doc.org/en/master/config
  8. # -- Path setup --------------------------------------------------------------
  9. # If extensions (or modules to document with autodoc) are in another directory,
  10. # add these directories to sys.path here. If the directory is relative to the
  11. # documentation root, use os.path.abspath to make it absolute, like shown here.
  12. #
  13. # import os
  14. # import sys
  15. # sys.path.insert(0, os.path.abspath('.'))
  16. import sys
  17. from recommonmark.transform import AutoStructify
  18. from recommonmark.parser import CommonMarkParser
  19. # -- Project information -----------------------------------------------------
  20. src_path = '../hivemind'
  21. project = 'hivemind'
  22. copyright = '2020, Learning@home & contributors'
  23. author = 'Learning@home & contributors'
  24. # The short X.Y version
  25. version = ''
  26. # The full version, including alpha/beta/rc tags
  27. release = 'latest'
  28. branch = 'master'
  29. # -- General configuration ---------------------------------------------------
  30. # If your documentation needs a minimal Sphinx version, state it here.
  31. #
  32. # needs_sphinx = '1.0'
  33. # Add any Sphinx extension module names here, as strings. They can be
  34. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  35. # ones.
  36. extensions = [
  37. 'sphinx.ext.autodoc',
  38. 'sphinx.ext.autosummary',
  39. 'sphinx.ext.doctest',
  40. 'sphinx.ext.mathjax',
  41. 'sphinx.ext.linkcode', # link to github, see linkcode_resolve() below
  42. 'sphinx.ext.napoleon', # alternative to numpydoc
  43. ]
  44. # see http://stackoverflow.com/q/12206334/562769
  45. numpydoc_show_class_members = False
  46. mathjax_path = ('https://cdn.mathjax.org/mathjax/latest/MathJax.js?'
  47. 'config=TeX-AMS-MML_HTMLorMML')
  48. # Add any paths that contain templates here, relative to this directory.
  49. templates_path = ['_templates']
  50. # The suffix(es) of source filenames.
  51. # You can specify multiple suffix as a list of string:
  52. #
  53. source_suffix = {'.rst': 'restructuredtext', '.md': 'markdown'}
  54. # The master toctree document.
  55. master_doc = 'index'
  56. # The language for content autogenerated by Sphinx. Refer to documentation
  57. # for a list of supported languages.
  58. #
  59. # This is also used if you do content translation via gettext catalogs.
  60. # Usually you set "language" from the command line for these cases.
  61. language = None
  62. # List of patterns, relative to source directory, that match files and
  63. # directories to ignore when looking for source files.
  64. # This pattern also affects html_static_path and html_extra_path.
  65. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
  66. # The name of the Pygments (syntax highlighting) style to use.
  67. pygments_style = 'sphinx'
  68. # -- Options for HTML output -------------------------------------------------
  69. # The theme to use for HTML and HTML Help pages. See the documentation for
  70. # a list of builtin themes.
  71. #
  72. html_theme = 'sphinx_rtd_theme'
  73. # Theme options are theme-specific and customize the look and feel of a theme
  74. # further. For a list of options available for each theme, see the
  75. # documentation.
  76. #
  77. html_theme_options = {
  78. "collapse_navigation": False
  79. }
  80. html_favicon = '_static/favicon.png'
  81. # Add any paths that contain custom static files (such as style sheets) here,
  82. # relative to this directory. They are copied after the builtin static files,
  83. # so a file named "default.css" will overwrite the builtin "default.css".
  84. html_static_path = ['_static']
  85. # Custom sidebar templates, must be a dictionary that maps document names
  86. # to template names.
  87. #
  88. # The default sidebars (for documents that don't match any pattern) are
  89. # defined by theme itself. Builtin themes are using these templates by
  90. # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
  91. # 'searchbox.html']``.
  92. #
  93. # html_sidebars = {}
  94. # -- Options for HTMLHelp output ---------------------------------------------
  95. # Output file base name for HTML help builder.
  96. htmlhelp_basename = 'hiveminddoc'
  97. # -- Options for LaTeX output ------------------------------------------------
  98. latex_elements = {
  99. # The paper size ('letterpaper' or 'a4paper').
  100. #
  101. # 'papersize': 'letterpaper',
  102. # The font size ('10pt', '11pt' or '12pt').
  103. #
  104. # 'pointsize': '10pt',
  105. # Additional stuff for the LaTeX preamble.
  106. #
  107. # 'preamble': '',
  108. # Latex figure (float) alignment
  109. #
  110. # 'figure_align': 'htbp',
  111. }
  112. # Grouping the document tree into LaTeX files. List of tuples
  113. # (source start file, target name, title,
  114. # author, documentclass [howto, manual, or own class]).
  115. latex_documents = [
  116. (master_doc, 'hivemind.tex', 'hivemind Documentation',
  117. 'Learning@home \\& contributors', 'manual'),
  118. ]
  119. # -- Options for manual page output ------------------------------------------
  120. # One entry per manual page. List of tuples
  121. # (source start file, name, description, authors, manual section).
  122. man_pages = [
  123. (master_doc, 'hivemind', 'hivemind Documentation',
  124. [author], 1)
  125. ]
  126. # -- Options for Texinfo output ----------------------------------------------
  127. # Grouping the document tree into Texinfo files. List of tuples
  128. # (source start file, target name, title, author,
  129. # dir menu entry, description, category)
  130. texinfo_documents = [
  131. (master_doc, 'hivemind', 'hivemind Documentation',
  132. author, 'hivemind', 'One line description of project.',
  133. 'Miscellaneous'),
  134. ]
  135. # -- Options for Epub output -------------------------------------------------
  136. # Bibliographic Dublin Core info.
  137. epub_title = project
  138. # The unique identifier of the text. This can be a ISBN number
  139. # or the project homepage.
  140. #
  141. # epub_identifier = ''
  142. # A unique identification for the text.
  143. #
  144. # epub_uid = ''
  145. # A list of files that should not be packed into the epub file.
  146. epub_exclude_files = ['search.html']
  147. # -- Extension configuration -------------------------------------------------
  148. # -- Options for intersphinx extension ---------------------------------------
  149. # Example configuration for intersphinx: refer to the Python standard library.
  150. intersphinx_mapping = {'https://docs.python.org/': None}
  151. # -- Options for todo extension ----------------------------------------------
  152. # If true, `todo` and `todoList` produce output, else they produce nothing.
  153. todo_include_todos = True
  154. def setup(app):
  155. app.add_stylesheet("fix_rtd.css")
  156. app.add_config_value('recommonmark_config', {
  157. 'auto_toc_tree_section': 'Contents',
  158. 'enable_math': True,
  159. 'enable_inline_math': True,
  160. 'enable_eval_rst': True,
  161. }, True)
  162. app.add_transform(AutoStructify)
  163. app.add_source_suffix('.md', 'markdown')
  164. app.add_source_parser(CommonMarkParser)
  165. # Resolve function for the linkcode extension.
  166. def linkcode_resolve(domain, info):
  167. def find_source():
  168. # try to find the file and line number, based on code from numpy:
  169. # https://github.com/numpy/numpy/blob/master/doc/source/conf.py#L286
  170. obj = sys.modules[info['module']]
  171. for part in info['fullname'].split('.'):
  172. obj = getattr(obj, part)
  173. import inspect
  174. import os
  175. fn = inspect.getsourcefile(obj)
  176. fn = os.path.relpath(fn, start=os.path.dirname(src_path))
  177. source, lineno = inspect.getsourcelines(obj)
  178. return fn, lineno, lineno + len(source) - 1
  179. if domain != 'py' or not info['module']:
  180. return None
  181. try:
  182. filename = '%s#L%d-L%d' % find_source()
  183. except Exception:
  184. filename = info['module'].replace('.', '/') + '.py'
  185. relative_filename = filename[filename.rindex('hivemind'):]
  186. return "https://github.com/learning-at-home/hivemind/blob/%s/%s" % (branch, relative_filename)