|
| 1 | +"""Configuration file for the Sphinx documentation builder. |
| 2 | +
|
| 3 | +This file only contains a selection of the most common options. For a full |
| 4 | +list see the documentation: |
| 5 | +https://www.sphinx-doc.org/en/master/usage/configuration.html |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import sys |
| 10 | +from pathlib import Path |
| 11 | +from subprocess import check_output |
| 12 | + |
| 13 | +import requests |
| 14 | + |
| 15 | +import phoebus_guibuilder |
| 16 | + |
| 17 | +# -- General configuration ------------------------------------------------ |
| 18 | +sys.path.insert(0, os.path.abspath("../../src")) |
| 19 | +# General information about the project. |
| 20 | +project = "phoebus-guibuilder" |
| 21 | +copyright = "2025, Diamond Light Source" |
| 22 | + |
| 23 | +# The full version, including alpha/beta/rc tags. |
| 24 | +release = phoebus_guibuilder.__version__ |
| 25 | + |
| 26 | +# The short X.Y version. |
| 27 | +if "+" in release: |
| 28 | + # Not on a tag, use branch name |
| 29 | + root = Path(__file__).absolute().parent.parent |
| 30 | + git_branch = check_output("git branch --show-current".split(), cwd=root) |
| 31 | + version = git_branch.decode().strip() |
| 32 | +else: |
| 33 | + version = release |
| 34 | + |
| 35 | +extensions = [ |
| 36 | + # for diagrams |
| 37 | + "sphinxcontrib.mermaid", |
| 38 | + # Used for BaseModel autodoc |
| 39 | + "sphinxcontrib.autodoc_pydantic", |
| 40 | + # Use this for generating API docs |
| 41 | + "sphinx.ext.autodoc", |
| 42 | + # Not sure if this is still used? |
| 43 | + "sphinx.ext.doctest", |
| 44 | + # and making summary tables at the top of API docs |
| 45 | + "sphinx.ext.autosummary", |
| 46 | + # This can parse google style docstrings |
| 47 | + "sphinx.ext.napoleon", |
| 48 | + # For linking to external sphinx documentation |
| 49 | + "sphinx.ext.intersphinx", |
| 50 | + # Add links to source code in API docs |
| 51 | + "sphinx.ext.viewcode", |
| 52 | + # Adds the inheritance-diagram generation directive |
| 53 | + "sphinx.ext.inheritance_diagram", |
| 54 | + # Add a copy button to each code block |
| 55 | + "sphinx_copybutton", |
| 56 | + # For the card element |
| 57 | + "sphinx_design", |
| 58 | + "sphinx.ext.mathjax", |
| 59 | + "sphinx.ext.githubpages", |
| 60 | +] |
| 61 | + |
| 62 | +napoleon_google_docstring = False |
| 63 | + |
| 64 | +# If true, Sphinx will warn about all references where the target cannot |
| 65 | +# be found. |
| 66 | +# nitpicky = True |
| 67 | + |
| 68 | +# A list of (type, target) tuples (by default empty) that should be ignored when |
| 69 | +# generating warnings in "nitpicky mode". Note that type should include the |
| 70 | +# domain name if present. Example entries would be ('py:func', 'int') or |
| 71 | +# ('envvar', 'LD_LIBRARY_PATH'). |
| 72 | +nitpick_ignore = [ |
| 73 | + # builtins |
| 74 | + ("py:class", "NoneType"), |
| 75 | + ("py:class", "'str'"), |
| 76 | + ("py:class", "'float'"), |
| 77 | + ("py:class", "'int'"), |
| 78 | + ("py:class", "'bool'"), |
| 79 | + ("py:class", "'object'"), |
| 80 | + ("py:class", "'id'"), |
| 81 | + # typing |
| 82 | + ("py:class", "typing_extensions.Literal"), |
| 83 | +] |
| 84 | + |
| 85 | +# Order the members by the order they appear in the source code |
| 86 | +autodoc_member_order = "bysource" |
| 87 | + |
| 88 | +# Don't inherit docstrings from baseclasses |
| 89 | +autodoc_inherit_docstrings = False |
| 90 | + |
| 91 | +# Add some more modules to the top level autosummary |
| 92 | +phoebus_guibuilder.__all__ += [] |
| 93 | + |
| 94 | +# Document only what is in __all__ |
| 95 | +autosummary_ignore_module_all = False |
| 96 | + |
| 97 | +# Add any paths that contain templates here, relative to this directory. |
| 98 | +templates_path = ["_templates"] |
| 99 | + |
| 100 | +# Output graphviz directive produced images in a scalable format |
| 101 | +graphviz_output_format = "svg" |
| 102 | + |
| 103 | +# The name of a reST role (builtin or Sphinx extension) to use as the default |
| 104 | +# role, that is, for text marked up `like this` |
| 105 | +default_role = "any" |
| 106 | + |
| 107 | +# The suffix of source filenames. |
| 108 | +source_suffix = ".rst" |
| 109 | + |
| 110 | +# The master toctree document. |
| 111 | +master_doc = "index" |
| 112 | + |
| 113 | +# List of patterns, relative to source directory, that match files and |
| 114 | +# directories to ignore when looking for source files. |
| 115 | +# These patterns also affect html_static_path and html_extra_path |
| 116 | +exclude_patterns = ["_build"] |
| 117 | + |
| 118 | +# The name of the Pygments (syntax highlighting) style to use. |
| 119 | +pygments_style = "sphinx" |
| 120 | + |
| 121 | + |
| 122 | +# Example configuration for intersphinx: refer to the Python standard library. |
| 123 | +# This means you can link things like `str` and `asyncio` to the relevant |
| 124 | +# docs in the python documentation. |
| 125 | +intersphinx_mapping = { |
| 126 | + "python": ("https://docs.python.org/3", None), |
| 127 | +} |
| 128 | + |
| 129 | +# A dictionary of graphviz graph attributes for inheritance diagrams. |
| 130 | +inheritance_graph_attrs = {"rankdir": "TB"} |
| 131 | + |
| 132 | +# Common links that should be available on every page |
| 133 | +rst_epilog = """ |
| 134 | +.. _NSLS: https://www.bnl.gov/nsls2 |
| 135 | +.. _black: https://github.com/psf/black |
| 136 | +.. _ruff: https://beta.ruff.rs/docs/ |
| 137 | +.. _mypy: http://mypy-lang.org/ |
| 138 | +.. _pre-commit: https://pre-commit.com/ |
| 139 | +""" |
| 140 | + |
| 141 | +# Ignore localhost links for periodic check that links in docs are valid |
| 142 | +linkcheck_ignore = [r"http://localhost:\d+/"] |
| 143 | + |
| 144 | +# Set copy-button to ignore python and bash prompts |
| 145 | +# https://sphinx-copybutton.readthedocs.io/en/latest/use.html#using-regexp-prompt-identifiers |
| 146 | +copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: " |
| 147 | +copybutton_prompt_is_regexp = True |
| 148 | + |
| 149 | +# -- Options for HTML output ------------------------------------------------- |
| 150 | + |
| 151 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 152 | +# a list of builtin themes. |
| 153 | +# |
| 154 | +html_theme = "pydata_sphinx_theme" |
| 155 | +github_repo = "phoebus-guibuilder" |
| 156 | +github_user = "DiamondLightSource" |
| 157 | +switcher_json = "https://diamondlightsource.github.io/phoebus-guibuilder/switcher.json" |
| 158 | +switcher_exists = requests.get(switcher_json).ok |
| 159 | +if not switcher_exists: |
| 160 | + print( |
| 161 | + "*** Can't read version switcher, is GitHub pages enabled? \n" |
| 162 | + " Once Docs CI job has successfully run once, set the " |
| 163 | + "Github pages source branch to be 'gh-pages' at:\n" |
| 164 | + f" https://github.com/{github_user}/{github_repo}/settings/pages", |
| 165 | + file=sys.stderr, |
| 166 | + ) |
| 167 | + |
| 168 | +# Theme options for pydata_sphinx_theme |
| 169 | +# We don't check switcher because there are 3 possible states for a repo: |
| 170 | +# 1. New project, docs are not published so there is no switcher |
| 171 | +# 2. Existing project with latest skeleton, switcher exists and works |
| 172 | +# 3. Existing project with old skeleton that makes broken switcher, |
| 173 | +# switcher exists but is broken |
| 174 | +# Point 3 makes checking switcher difficult, because the updated skeleton |
| 175 | +# will fix the switcher at the end of the docs workflow, but never gets a chance |
| 176 | +# to complete as the docs build warns and fails. |
| 177 | +html_theme_options = { |
| 178 | + "use_edit_page_button": True, |
| 179 | + "github_url": f"https://github.com/{github_user}/{github_repo}", |
| 180 | + "icon_links": [ |
| 181 | + { |
| 182 | + "name": "PyPI", |
| 183 | + "url": f"https://pypi.org/project/{project}", |
| 184 | + "icon": "fas fa-cube", |
| 185 | + }, |
| 186 | + ], |
| 187 | + "switcher": { |
| 188 | + "json_url": switcher_json, |
| 189 | + "version_match": version, |
| 190 | + }, |
| 191 | + "check_switcher": False, |
| 192 | + "navbar_end": ["theme-switcher", "icon-links", "version-switcher"], |
| 193 | + "navigation_with_keys": False, |
| 194 | +} |
| 195 | + |
| 196 | +# A dictionary of values to pass into the template engine’s context for all pages |
| 197 | +html_context = { |
| 198 | + "github_user": github_user, |
| 199 | + "github_repo": project, |
| 200 | + "github_version": version, |
| 201 | + "doc_path": "docs", |
| 202 | +} |
| 203 | + |
| 204 | +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. |
| 205 | +html_show_sphinx = False |
| 206 | + |
| 207 | +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. |
| 208 | +html_show_copyright = False |
| 209 | + |
| 210 | +# Logo |
| 211 | +# html_logo = "images/phoebus-guibuilder-logo.svg" |
| 212 | +# html_favicon = "images/phoebus-guibuilder-favicon.svg" |
| 213 | + |
| 214 | +# If False and a module has the __all__ attribute set, autosummary documents |
| 215 | +# every member listed in __all__ and no others. Default is True |
| 216 | +autosummary_ignore_module_all = False |
| 217 | + |
| 218 | +# Turn on sphinx.ext.autosummary |
| 219 | +autosummary_generate = True |
| 220 | + |
| 221 | +# Add any paths that contain templates here, relative to this directory. |
| 222 | +templates_path = ["_templates"] |
| 223 | + |
| 224 | +# Look for signatures in the first line of the docstring (used for C functions) |
| 225 | +autodoc_docstring_signature = True |
| 226 | + |
| 227 | +# Don't show config summary as it's not relevant |
| 228 | +autodoc_pydantic_model_show_config_summary = False |
| 229 | + |
| 230 | +# Show the fields in source order |
| 231 | +autodoc_pydantic_model_summary_list_order = "bysource" |
0 commit comments