conf.py 7.6 KB

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