conf.py 6.0 KB

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