conf.py 8.2 KB

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