conf.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Neo documentation build configuration file, created by
  5. # sphinx-quickstart on Tue Jul 25 10:23:12 2017.
  6. #
  7. # This file is execfile()d with the current directory set to its
  8. # containing dir.
  9. #
  10. # Note that not all possible configuration values are present in this
  11. # autogenerated file.
  12. #
  13. # All configuration values have a default; values that are commented out
  14. # serve to show the default.
  15. # If extensions (or modules to document with autodoc) are in another directory,
  16. # add these directories to sys.path here. If the directory is relative to the
  17. # documentation root, use os.path.abspath to make it absolute, like shown here.
  18. #
  19. import sys
  20. from pathlib import Path
  21. from draugr import PROJECT_AUTHOR, PROJECT_NAME, PROJECT_VERSION, PROJECT_YEAR
  22. PACKAGE_ROOT = Path(__file__).parent.parent.parent
  23. sys.path.insert(0, str(PACKAGE_ROOT.absolute()))
  24. # -- General configuration ------------------------------------------------
  25. # If your documentation needs a minimal Sphinx version, state it here.
  26. #
  27. # needs_sphinx = '1.0'
  28. # Add any Sphinx extension module names here, as strings. They can be
  29. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  30. # ones.
  31. extensions = [
  32. "m2r2",
  33. # 'recommonmark',
  34. "sphinxcontrib.programoutput",
  35. "sphinx.ext.autodoc",
  36. "sphinx.ext.autosummary",
  37. "sphinx.ext.napoleon",
  38. "sphinx.ext.doctest",
  39. "sphinx.ext.intersphinx",
  40. "sphinx.ext.todo",
  41. "sphinx.ext.coverage",
  42. "sphinx.ext.mathjax",
  43. "sphinx.ext.viewcode",
  44. "sphinx.ext.githubpages",
  45. "sphinx.ext.graphviz",
  46. ]
  47. napoleon_use_ivar = True
  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', '.md']
  54. # source_suffix = '.rst'
  55. source_suffix = {".rst": "restructuredtext", ".txt": "markdown", ".md": "markdown"}
  56. # source_parsers = {
  57. # '.md': CommonMarkParser,
  58. # }
  59. # The master toctree document.
  60. master_doc = "index"
  61. # General information about the project.
  62. project = PROJECT_NAME
  63. author = PROJECT_AUTHOR
  64. copyright_text = f"{PROJECT_YEAR}, {PROJECT_AUTHOR}"
  65. # The version info for the project you're documenting, acts as replacement for
  66. # |version| and |release|, also used in various other places throughout the
  67. # built documents.
  68. version = PROJECT_VERSION
  69. release = version # 'master'
  70. # The language for content autogenerated by Sphinx. Refer to documentation
  71. # for a list of supported languages.
  72. #
  73. # This is also used if you do content translation via gettext catalogs.
  74. # Usually you set 'language' from the command line for these cases.
  75. language = None
  76. # List of patterns, relative to source directory, that match files and
  77. # directories to ignore when looking for source files.
  78. # This patterns also effect to html_static_path and html_extra_path
  79. exclude_patterns = []
  80. # The name of the Pygments (syntax highlighting) style to use.
  81. pygments_style = "sphinx"
  82. # If true, `todo` and `todoList` produce output, else they produce nothing.
  83. todo_include_todos = True
  84. # -- Options for HTML output ----------------------------------------------
  85. # The theme to use for HTML and HTML Help pages. See the documentation for
  86. # a list of builtin themes.
  87. #
  88. html_theme = "alabaster"
  89. # Theme options are theme-specific and customize the look and feel of a theme
  90. # further. For a list of options available for each theme, see the
  91. # documentation.
  92. #
  93. # html_theme_options = {}
  94. # Add any paths that contain custom static files (such as style sheets) here,
  95. # relative to this directory. They are copied after the builtin static files,
  96. # so a file named 'default.css' will overwrite the builtin 'default.css'.
  97. html_static_path = ["_static"]
  98. html_baseurl = f"{PROJECT_NAME}.github.io"
  99. # -- Options for HTMLHelp output ------------------------------------------
  100. # Output file base name for HTML help builder.
  101. htmlhelp_basename = f"{PROJECT_NAME}doc"
  102. # -- Options for LaTeX output ---------------------------------------------
  103. latex_elements = {
  104. # The paper size ('letterpaper' or 'a4paper').
  105. #
  106. # 'papersize': 'letterpaper',
  107. # The font size ('10pt', '11pt' or '12pt').
  108. #
  109. # 'pointsize': '10pt',
  110. # Additional stuff for the LaTeX preamble.
  111. #
  112. # 'preamble': '',
  113. # Latex figure (float) alignment
  114. #
  115. # 'figure_align': 'htbp',
  116. }
  117. # Grouping the document tree into LaTeX files. List of tuples
  118. # (source start file, target name, title,
  119. # author, documentclass [howto, manual, or own class]).
  120. latex_documents = [
  121. (
  122. master_doc,
  123. f"{PROJECT_NAME}.tex",
  124. f"{PROJECT_NAME} Documentation",
  125. PROJECT_AUTHOR,
  126. "manual",
  127. )
  128. ]
  129. # -- Options for manual page output ---------------------------------------
  130. # One entry per manual page. List of tuples
  131. # (source start file, name, description, authors, manual section).
  132. man_pages = [
  133. (master_doc, PROJECT_NAME, f"{PROJECT_NAME} Documentation", [PROJECT_AUTHOR], 1)
  134. ]
  135. # -- Options for Texinfo output -------------------------------------------
  136. # Grouping the document tree into Texinfo files. List of tuples
  137. # (source start file, target name, title, author,
  138. # dir menu entry, description, category)
  139. texinfo_documents = [
  140. (
  141. master_doc,
  142. PROJECT_NAME,
  143. f"{PROJECT_NAME} Documentation",
  144. PROJECT_AUTHOR,
  145. PROJECT_NAME,
  146. "One line description of project.",
  147. "Miscellaneous",
  148. )
  149. ]
  150. # -- Options for Epub output ----------------------------------------------
  151. # Bibliographic Dublin Core info.
  152. epub_title = PROJECT_NAME
  153. epub_author = PROJECT_AUTHOR
  154. epub_publisher = PROJECT_AUTHOR
  155. epub_copyright = copyright_text
  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. # Example configuration for intersphinx: refer to the Python standard library.
  166. intersphinx_mapping = {
  167. "python": ("https://docs.python.org/", None),
  168. "numpy": ("http://docs.scipy.org/doc/numpy/", None),
  169. "torch": ("https://pytorch.org/docs/", None),
  170. }
  171. # -- A patch that prevents Sphinx from cross-referencing ivar tags -------
  172. # See http://stackoverflow.com/a/41184353/3343043
  173. from docutils import nodes
  174. from sphinx import addnodes
  175. from sphinx.util.docfields import TypedField
  176. def patched_make_field(self, types, domain, items, **kw) -> nodes.field:
  177. """ """
  178. # `kw` catches `env=None` needed for newer sphinx while maintaining
  179. # backwards compatibility when passed along further down!
  180. ## type: (List, unicode, Tuple) -> nodes.field
  181. def handle_item(fieldarg, content):
  182. """ """
  183. par = nodes.paragraph()
  184. par += addnodes.literal_strong("", fieldarg) # Patch: this line added
  185. # par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
  186. # addnodes.literal_strong))
  187. if fieldarg in types:
  188. par += nodes.Text(" (")
  189. # NOTE: using .pop() here to prevent a single type node to be
  190. # inserted twice into the doctree, which leads to
  191. # inconsistencies later when references are resolved
  192. fieldtype = types.pop(fieldarg)
  193. if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
  194. typename = "".join(n.astext() for n in fieldtype)
  195. typename = typename.replace("int", "python:int")
  196. typename = typename.replace("long", "python:long")
  197. typename = typename.replace("float", "python:float")
  198. typename = typename.replace("type", "python:type")
  199. par.extend(
  200. self.make_xrefs(
  201. self.typerolename,
  202. domain,
  203. typename,
  204. addnodes.literal_emphasis,
  205. **kw,
  206. )
  207. )
  208. else:
  209. par += fieldtype
  210. par += nodes.Text(")")
  211. par += nodes.Text(" -- ")
  212. par += content
  213. return par
  214. field_name = nodes.field_name("", self.label)
  215. if len(items) == 1 and self.can_collapse:
  216. field_arg, content = items[0]
  217. body_node = handle_item(field_arg, content)
  218. else:
  219. body_node = self.list_type()
  220. for field_arg, content in items:
  221. body_node += nodes.list_item("", handle_item(field_arg, content))
  222. field_body = nodes.field_body("", body_node)
  223. return nodes.field("", field_name, field_body)
  224. TypedField.make_field = patched_make_field