# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import importlib.metadata
from types import FunctionType, MethodType

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "pharia-kernel"
copyright = "2025, Aleph Alpha"
author = "Aleph Alpha"
version = importlib.metadata.version("pharia-skill")

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
    "myst_parser",
    "sphinx_rtd_theme",
    "sphinx_design",
    "sphinx.ext.autodoc",
    "sphinx.ext.viewcode",
    "sphinx.ext.napoleon",
    "sphinx_copybutton",
]

myst_enable_extensions = [
    "amsmath",
    "attrs_inline",
    "attrs_block",
    "colon_fence",
    "deflist",
    "dollarmath",
    "fieldlist",
    "html_admonition",
    "html_image",
    # "linkify",
    "replacements",
    "smartquotes",
    "strikethrough",
    "substitution",
    "tasklist",
]

autodoc_default_options = {
    "autodoc_member_order": "bysource",
}

# do not show full path including pharia_skill
add_module_names = False

templates_path = ["_templates"]
exclude_patterns: list[str] = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
html_use_relative_paths = True

html_static_path = ["../_static"]
html_style = "../_static/css/my_theme.css"


def skip_autodoc_attributes(app, what, name, obj, skip, options):  # type: ignore[no-untyped-def]
    """Skip class attributes in autodocs that are not functions.

    The default behavior with Google style in sphinx is to document each attribute twice.
    Once with the documentation string and once with the type. In order to get rid of the
    documentation generated by the type definition we filter these out.
    Implementation: We filter all member of a class that are not a function. Therefore,
    we will keep all functions in e.g. Csi, but remove all attributes of the dataclasses.

    Returns:
        True: autodoc skips this attribute
        False: autodoc includes this attribute (even show private and magic attributes, e.g. __eq__)
        None: default behavior (private and magic attributes are excluded)
    """
    if (
        what == "class"
        and not isinstance(obj, FunctionType)
        and not isinstance(obj, MethodType)
    ):
        return True
    return None


def setup(app):  # type: ignore[no-untyped-def]
    app.connect("autodoc-skip-member", skip_autodoc_attributes)
