conf.py 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. from pathlib import Path
  5. from warg import cprint, is_windows, is_linux, is_mac
  6. PACKAGE_ROOT = Path(__file__).parent.parent.parent # / "draugr"
  7. cprint(PACKAGE_ROOT)
  8. sys.path.insert(0, str(PACKAGE_ROOT.absolute()))
  9. # sys.path.insert(0, str(PACKAGE_ROOT.absolute() / PROJECT_NAME))
  10. # -- General configuration ------------------------------------------------
  11. # If your documentation needs a minimal Sphinx version, state it here.
  12. #
  13. # needs_sphinx = '1.0'
  14. # Add any Sphinx extension module names here, as strings. They can be
  15. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
  16. # ones.
  17. from draugr import (
  18. PROJECT_ORGANISATION,
  19. PROJECT_AUTHOR,
  20. PROJECT_NAME,
  21. PROJECT_VERSION,
  22. PROJECT_YEAR,
  23. __project__,
  24. __url__,
  25. )
  26. if is_windows():
  27. autodoc_mock_imports = [
  28. "draugr.os_utilities.linux_utilities",
  29. "draugr.matlab_utilities",
  30. "draugr.os_utilities.mac_utilities",
  31. ]
  32. elif is_linux():
  33. autodoc_mock_imports = [
  34. "draugr.os_utilities.windows_utilities",
  35. "draugr.matlab_utilities",
  36. "draugr.os_utilities.mac_utilities",
  37. ]
  38. elif is_mac():
  39. autodoc_mock_imports = [
  40. "draugr.os_utilities.windows_utilities",
  41. "draugr.matlab_utilities",
  42. "draugr.os_utilities.linux_utilities",
  43. ]
  44. else:
  45. raise ValueError("Unknown OS")
  46. # autodoc_default_options = {"exclude-members": "exclude"}
  47. extensions = [
  48. "sphinxcontrib.programoutput",
  49. "sphinx.ext.autodoc",
  50. "sphinx.ext.autosummary",
  51. "sphinx.ext.napoleon",
  52. "sphinx.ext.doctest",
  53. "sphinx.ext.intersphinx",
  54. "sphinx.ext.todo",
  55. "sphinx.ext.coverage",
  56. "sphinx.ext.mathjax",
  57. "sphinx.ext.viewcode",
  58. "sphinx.ext.githubpages",
  59. "sphinx.ext.graphviz",
  60. ]
  61. napoleon_use_ivar = True
  62. autosummary_generate = True
  63. # autosummary_imported_members = False
  64. autosummary_ignore_module_all = False
  65. autosummary_generate_overwrite = True
  66. # Add any paths that contain templates here, relative to this directory.
  67. templates_path = ["../templates"]
  68. # templates_path = []
  69. # The suffix(es) of source filenames.
  70. # You can specify multiple suffix as a list of string:
  71. #
  72. # source_suffix = ['.rst', '.md']
  73. # source_suffix = '.rst'
  74. source_suffix = {".rst": "restructuredtext", ".txt": "markdown", ".md": "markdown"}
  75. # source_parsers = {
  76. # '.md': CommonMarkParser,
  77. # }
  78. # The master toctree document.
  79. master_doc = "index"
  80. # General information about the project.
  81. project = __project__ # PROJECT_NAME
  82. author = PROJECT_AUTHOR
  83. copyright_text = f"{PROJECT_YEAR}, {PROJECT_AUTHOR}"
  84. rst_prolog = f"""
  85. .. |project| replace:: {project}
  86. .. |PROJECT_NAME| replace:: {PROJECT_NAME}
  87. .. |github_url| replace:: {__url__}
  88. """
  89. # The version info for the project you're documenting, acts as replacement for
  90. # |version| and |release|, also used in various other places throughout the
  91. # built documents.
  92. version = PROJECT_VERSION
  93. release = version # 'master'
  94. # The language for content autogenerated by Sphinx. Refer to documentation
  95. # for a list of supported languages.
  96. #
  97. # This is also used if you do content translation via gettext catalogs.
  98. # Usually you set 'language' from the command line for these cases.
  99. language = "en"
  100. # List of patterns, relative to source directory, that match files and
  101. # directories to ignore when looking for source files.
  102. # This patterns also effect to html_static_path and html_extra_path
  103. exclude_patterns = ["**/*exclude*", "**/*Exclude*"]
  104. # The name of the Pygments (syntax highlighting) style to use.
  105. pygments_style = "sphinx"
  106. # If true, `todo` and `todoList` produce output, else they produce nothing.
  107. todo_include_todos = True
  108. # -- Options for HTML output ----------------------------------------------
  109. # The theme to use for HTML and HTML Help pages. See the documentation for
  110. # a list of builtin themes.
  111. #
  112. html_theme = "alabaster"
  113. # html_theme = 'sphinx_rtd_theme'
  114. # Theme options are theme-specific and customize the look and feel of a theme
  115. # further. For a list of options available for each theme, see the
  116. # documentation.
  117. #
  118. # html_theme_options = {}
  119. # Add any paths that contain custom static files (such as style sheets) here,
  120. # relative to this directory. They are copied after the builtin static files,
  121. # so a file named 'default.css' will overwrite the builtin 'default.css'.
  122. # html_static_path = ["_static"]
  123. html_static_path = ["../../.github/images"]
  124. html_logo = "../../.github/images/valknut.svg"
  125. html_theme_options = {
  126. # "logo_only": True,
  127. # "display_version": False,
  128. }
  129. html_baseurl = f"{PROJECT_ORGANISATION}.github.io/{PROJECT_NAME}"
  130. # -- Options for HTMLHelp output ------------------------------------------
  131. # Output file base name for HTML help builder.
  132. htmlhelp_basename = f"{PROJECT_NAME}doc"
  133. # -- Options for LaTeX output ---------------------------------------------
  134. latex_elements = {
  135. # The paper size ('letterpaper' or 'a4paper').
  136. #
  137. # 'papersize': 'letterpaper',
  138. # The font size ('10pt', '11pt' or '12pt').
  139. #
  140. # 'pointsize': '10pt',
  141. # Additional stuff for the LaTeX preamble.
  142. #
  143. # 'preamble': '',
  144. # Latex figure (float) alignment
  145. #
  146. # 'figure_align': 'htbp',
  147. }
  148. # Grouping the document tree into LaTeX files. List of tuples
  149. # (source start file, target name, title,
  150. # author, documentclass [howto, manual, or own class]).
  151. latex_documents = [
  152. (
  153. master_doc,
  154. f"{PROJECT_NAME}.tex",
  155. f"{PROJECT_NAME} Documentation",
  156. PROJECT_AUTHOR,
  157. "manual",
  158. )
  159. ]
  160. # -- Options for manual page output ---------------------------------------
  161. # One entry per manual page. List of tuples
  162. # (source start file, name, description, authors, manual section).
  163. man_pages = [
  164. (master_doc, PROJECT_NAME, f"{PROJECT_NAME} Documentation", [PROJECT_AUTHOR], 1)
  165. ]
  166. # -- Options for Texinfo output -------------------------------------------
  167. # Grouping the document tree into Texinfo files. List of tuples
  168. # (source start file, target name, title, author,
  169. # dir menu entry, description, category)
  170. texinfo_documents = [
  171. (
  172. master_doc,
  173. PROJECT_NAME,
  174. f"{PROJECT_NAME} Documentation",
  175. PROJECT_AUTHOR,
  176. PROJECT_NAME,
  177. "One line description of project.",
  178. "Miscellaneous",
  179. )
  180. ]
  181. # -- Options for Epub output ----------------------------------------------
  182. # Bibliographic Dublin Core info.
  183. epub_title = PROJECT_NAME
  184. epub_author = PROJECT_AUTHOR
  185. epub_publisher = PROJECT_AUTHOR
  186. epub_copyright = copyright_text
  187. # The unique identifier of the text. This can be a ISBN number
  188. # or the project homepage.
  189. #
  190. # epub_identifier = ''
  191. # A unique identification for the text.
  192. #
  193. # epub_uid = ''
  194. # A list of files that should not be packed into the epub file.
  195. epub_exclude_files = ["search.html"]
  196. # Example configuration for intersphinx: refer to the Python standard library.
  197. intersphinx_mapping = {
  198. "python": ("https://docs.python.org/", None),
  199. "numpy": ("http://docs.scipy.org/doc/numpy/", None),
  200. # "torch": ("https://pytorch.org/docs/", None),
  201. }
  202. # -- A patch that prevents Sphinx from cross-referencing ivar tags -------
  203. # See http://stackoverflow.com/a/41184353/3343043
  204. from docutils import nodes
  205. from sphinx import addnodes
  206. from sphinx.util.docfields import TypedField
  207. def patched_make_field(self, types, domain, items, **kw) -> nodes.field:
  208. """description"""
  209. # `kw` catches `env=None` needed for newer sphinx while maintaining
  210. # backwards compatibility when passed along further down!
  211. ## type: (List, unicode, Tuple) -> nodes.field
  212. def handle_item(fieldarg, content):
  213. """description"""
  214. par = nodes.paragraph()
  215. par += addnodes.literal_strong("", fieldarg) # Patch: this line added
  216. # par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
  217. # addnodes.literal_strong))
  218. if fieldarg in types:
  219. par += nodes.Text(" (")
  220. # NOTE: using .pop() here to prevent a single type node to be
  221. # inserted twice into the doctree, which leads to
  222. # inconsistencies later when references are resolved
  223. fieldtype = types.pop(fieldarg)
  224. if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
  225. typename = "".join(n.astext() for n in fieldtype)
  226. typename = typename.replace("int", "python:int")
  227. typename = typename.replace("long", "python:long")
  228. typename = typename.replace("float", "python:float")
  229. typename = typename.replace("type", "python:type")
  230. par.extend(
  231. self.make_xrefs(
  232. self.typerolename,
  233. domain,
  234. typename,
  235. addnodes.literal_emphasis,
  236. **kw,
  237. )
  238. )
  239. else:
  240. par += fieldtype
  241. par += nodes.Text(")")
  242. par += nodes.Text(" -- ")
  243. par += content
  244. return par
  245. field_name = nodes.field_name("", self.label)
  246. if len(items) == 1 and self.can_collapse:
  247. field_arg, content = items[0]
  248. body_node = handle_item(field_arg, content)
  249. else:
  250. body_node = self.list_type()
  251. for field_arg, content in items:
  252. body_node += nodes.list_item("", handle_item(field_arg, content))
  253. field_body = nodes.field_body("", body_node)
  254. return nodes.field("", field_name, field_body)
  255. TypedField.make_field = patched_make_field