conf.py 7.6 KB

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