conf.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. """
  2. Configuration file for the Sphinx documentation builder.
  3. For the full list of built-in configuration values, see the documentation:
  4. https://www.sphinx-doc.org/en/master/usage/configuration.html
  5. """
  6. import os
  7. from functools import wraps
  8. from pathlib import Path
  9. from sphinxcontrib_autodocgen import AutoDocGen
  10. import unfccc_ghg_data
  11. os.environ["UNFCCC_GHG_ROOT_PATH"] = str(Path("..") / "..")
  12. # -- Project information -----------------------------------------------------
  13. # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
  14. project = "Country greenhouse gas data submitted to the UNFCCC"
  15. # put the authors in their own variable, so they can be reused later
  16. authors = ", ".join(["Johannes Gütschow"])
  17. # add a copyright year variable, we can extend this over time in future as
  18. # needed
  19. copyright_year = "2023"
  20. copyright = f"{copyright_year}, {authors}"
  21. # -- General configuration ---------------------------------------------------
  22. # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
  23. extensions = [
  24. # create documentation automatically from source code
  25. # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
  26. "sphinx.ext.autodoc",
  27. # automatic summary
  28. "sphinx.ext.autosummary",
  29. # automatic summary with better control
  30. "sphinxcontrib_autodocgen",
  31. # tell sphinx that we're using numpy style docstrings
  32. # https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
  33. "sphinx.ext.napoleon",
  34. # add support for type hints too (so type hints are included next to
  35. # argument and return types in docs)
  36. # https://github.com/tox-dev/sphinx-autodoc-typehints
  37. # this must come after napoleon
  38. # in the list for things to work properly
  39. # https://github.com/tox-dev/sphinx-autodoc-typehints#compatibility-with-sphinxextnapoleon
  40. "sphinx_autodoc_typehints",
  41. # jupytext rendered notebook support (also loads myst_parser)
  42. "myst_nb",
  43. # links to other docs
  44. "sphinx.ext.intersphinx",
  45. # add source code to docs
  46. "sphinx.ext.viewcode",
  47. # add copy code button to code examples
  48. "sphinx_copybutton",
  49. # math support
  50. "sphinx.ext.mathjax",
  51. # execute code
  52. "sphinx_exec_code",
  53. ]
  54. # general sphinx settings
  55. # https://www.sphinx-doc.org/en/master/usage/configuration.html
  56. # Don't include module names in object names (can also be left on,
  57. # depends a bit how your project is structured and what you prefer)
  58. add_module_names = False
  59. # Other global settings which we've never used but are included by default
  60. templates_path = ["_templates"]
  61. # Avoid sphinx thinking that conf.py is a source file because we use .py
  62. # endings for notebooks
  63. exclude_patterns = ["conf.py"]
  64. # Stop sphinx doing funny things with byte order markers
  65. source_encoding = "utf-8"
  66. # configure default settings for autodoc directives
  67. # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directives
  68. autodoc_default_options = {
  69. # Show the inheritance of classes
  70. "show-inheritance": True,
  71. }
  72. # autosummary with autodocgen
  73. # make sure autosummary doesn't interfere
  74. autosummary_generate = True
  75. autosummary_generate_overwrite = False
  76. autodocgen_config = [
  77. {
  78. "modules": [unfccc_ghg_data],
  79. "generated_source_dir": "docs/source/api",
  80. # choose a different title for specific modules, e.g. the toplevel one
  81. "module_title_decider": lambda modulename: "API Reference"
  82. if modulename == "unfccc_ghg_data"
  83. else modulename,
  84. }
  85. ]
  86. # monkey patch to remove leading newlines
  87. generate_module_rst_orig = AutoDocGen.generate_module_rst
  88. @wraps(generate_module_rst_orig)
  89. def _generate_module_rst_new(*args, **kwargs):
  90. default = generate_module_rst_orig(*args, **kwargs)
  91. out = default.lstrip("\n")
  92. if not out.endswith("\n"):
  93. out = f"{out}\n"
  94. return out
  95. AutoDocGen.generate_module_rst = _generate_module_rst_new
  96. # napoleon extension settings
  97. # https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
  98. # We use numpy style docstrings
  99. napoleon_numpy_docstring = True
  100. # We don't use google docstrings
  101. napoleon_google_docstring = False
  102. # Don't use separate rtype for the return documentation
  103. napoleon_use_rtype = False
  104. # autodoc type hints settings
  105. # https://github.com/tox-dev/sphinx-autodoc-typehints
  106. # include full name of classes when expanding type hints?
  107. typehints_fully_qualified = True
  108. # Add rtype directive if needed
  109. typehints_document_rtype = True
  110. # Put the return type as part of the return documentation
  111. typehints_use_rtype = False
  112. # Left-align maths equations
  113. mathjax3_config = {"chtml": {"displayAlign": "center"}}
  114. # myst configuration
  115. myst_enable_extensions = ["amsmath", "dollarmath"]
  116. # cache because we save our notebooks as `.py` files i.e. without output
  117. # stored so auto doesn't work (it just ends up being run every time)
  118. nb_execution_mode = "cache"
  119. nb_execution_raise_on_error = True
  120. nb_execution_show_tb = True
  121. nb_execution_timeout = 120
  122. nb_custom_formats = {".py": ["jupytext.reads", {"fmt": "py:percent"}]}
  123. # exec-code config
  124. exec_code_working_dir = "." # Path('..') / '..'
  125. exec_code_source_folders = [Path("..") / ".." / "src" / "unfccc_ghg_data"]
  126. exec_code_example_dir = "."
  127. # -- Options for HTML output -------------------------------------------------
  128. # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
  129. # Pick your theme for html output, we typically use the read the docs theme
  130. html_theme = "sphinx_book_theme"
  131. html_static_path = ["_static"]
  132. html_theme_options = {
  133. "repository_url": "https://github.com/JGuetschow/UNFCCC_non-AnnexI_data",
  134. "repository_branch": "main",
  135. "path_to_docs": "docs/source",
  136. "use_repository_button": True,
  137. "use_issues_button": True,
  138. "use_edit_page_button": True,
  139. }
  140. # Ignore ipynb files when building (see https://github.com/executablebooks/MyST-NB/issues/363).
  141. def setup(app):
  142. """
  143. Set up the Sphinx app
  144. """
  145. app.registry.source_suffix.pop(".ipynb", None)
  146. # Intersphinx mapping
  147. intersphinx_mapping = {
  148. "numpy": ("https://docs.scipy.org/doc/numpy", None),
  149. "pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
  150. "python": ("https://docs.python.org/3", None),
  151. "pyam": ("https://pyam-iamc.readthedocs.io/en/latest", None),
  152. "scmdata": ("https://scmdata.readthedocs.io/en/latest", None),
  153. "xarray": ("http://xarray.pydata.org/en/stable", None),
  154. "pint": (
  155. "https://pint.readthedocs.io/en/latest",
  156. None,
  157. ),
  158. }