diff --git a/docs/conf.py b/docs/conf.py index 1b91724f0..ccd6fa98d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # +from __future__ import annotations import sys from pathlib import Path @@ -29,7 +30,7 @@ release = "0.35.0" -# -- General configuration --------------------------------------------------- +# -- General configuration ------------------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -40,6 +41,7 @@ "sphinx.ext.autosectionlabel", "sphinx.ext.autosummary", "sphinx.ext.intersphinx", + "sphinx.ext.linkcode", "sphinx_copybutton", "myst_parser", "sphinx_reredirects", @@ -55,12 +57,7 @@ # This pattern also affects html_static_path and html_extra_path. exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] -# Show typehints in the description, along with parameter descriptions -autodoc_typehints = "description" -autodoc_class_signature = "separated" -autodoc_member_order = "groupwise" - -# -- Options for HTML output ------------------------------------------------- +# -- Options for HTML output ----------------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. @@ -118,7 +115,19 @@ "css/custom.css", ] -# -- Options for MyST -------------------------------------------------------- +# -- Options for AutoDoc --------------------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#configuration + +# Show typehints in the description +autodoc_typehints = "description" + +# Display the signature as a method. +autodoc_class_signature = "separated" + +# Sort members by type. +autodoc_member_order = "groupwise" + +# -- Options for MyST ------------------------------------------------------------------ # https://myst-parser.readthedocs.io/en/latest/configuration.html myst_heading_anchors = 3 myst_enable_extensions = { @@ -129,9 +138,34 @@ "porting.html": "guides/porting.html", } -# -- Options for intersphinx ------------------------------------------------- +# -- Options for intersphinx ----------------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration intersphinx_mapping = { "requests": ("https://requests.readthedocs.io/en/latest/", None), "python": ("https://docs.python.org/3/", None), } + +# -- Options for linkcode -------------------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/extensions/linkcode.html#configuration + + +def linkcode_resolve(domain: str, info: dict) -> str | None: + """Get URL to source code. + + Args: + domain: Language domain the object is in. + info: A dictionary with domain-specific keys. + + Returns: + A URL. + """ + if domain != "py": + return None + if not info["module"]: + return None + filename = info["module"].replace(".", "/") + + if filename == "singer_sdk": + filename = "singer_sdk/__init__" + + return f"https://github.com/meltano/sdk/tree/main/{filename}.py"