# 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

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

from trinity import __version__ as version

project = "Trinity-RFT"
copyright = "2025, Trinity-RFT Team"
author = "Trinity-RFT Team"
release = version
language = "en"
root_doc = "index"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
    "sphinxcontrib.apidoc",
    "sphinx.ext.autodoc",
    "sphinx.ext.autosummary",
    "sphinx.ext.viewcode",
    "sphinx.ext.napoleon",
    "sphinx.ext.autosectionlabel",
    "sphinxcontrib.mermaid",
    "sphinx_multiversion",
    "myst_parser",
    "sphinx.ext.mathjax",
]
source_suffix = {
    ".rst": "restructuredtext",
    ".md": "markdown",
}
myst_enable_extensions = ["colon_fence", "amsmath", "dollarmath"]

# Prefix document path to section labels, otherwise autogenerated labels would
# look like 'heading' rather than 'path/to/file:heading'
autosectionlabel_prefix_document = True
autosummary_generate = True
autosummary_ignore_module_all = False
napoleon_google_docstring = True

autodoc_member_order = "bysource"

templates_path = ["../_templates"]
exclude_patterns = ["build"]

autodoc_default_options = {
    "members": True,
    "special-members": "__init__",
}

# auto api configs
apidoc_module_dir = "../../../trinity"
apidoc_output_dir = "build_api"
apidoc_excluded_paths = ["tests", "build"]
apidoc_separate_modules = True


# Multiversion configs
def get_recent_tags(n: int) -> list:
    """Retrieve the most recent n git tags."""
    try:
        tags = subprocess.check_output(
            ["git", "tag", "--sort=-creatordate"], universal_newlines=True
        ).splitlines()
        return tags[:n]
    except subprocess.CalledProcessError:
        return []


smv_tag_whitelist = r"^(" + "|".join(get_recent_tags(2)) + r")$"
smv_branch_whitelist = r"^(main)$"  # included branches
smv_remote_whitelist = None

smv_prefer_remote_refs = False

# -- Options for HTML output -------------------------------------------------

html_theme = "sphinx_book_theme"

html_logo = "../_static/logo.svg"

html_favicon = "../_static/favicon.ico"

html_theme_options = {
    "navigation_depth": 3,
    "article_header_end": "article_header_customized.html",
    "use_download_button": True,
    "use_fullscreen_button": True,
    "repository_url": "https://github.com/agentscope-ai/Trinity-RFT",
    "use_repository_button": True,
}

html_sidebars = {
    "**": [
        "navbar-logo.html",
        "icon-links.html",
        "versions.html",
        "search-button-field.html",
        "sbt-sidebar-nav.html",
    ]
}

html_context = {
    "display_github": True,
    "github_user": "modelscope",
    "github_repo": "Trinity-RFT",
    "github_version": "main",
    "conf_py_path": "/docs/sphinx_doc/source/",
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["../_static"]
