# -- Project information --------------------------------------------------

import importlib.metadata
import os

project = "GWPopulation"
copyright = "2021-2024, Colm Talbot"
author = "Colm Talbot"

# -- General configuration ------------------------------------------------

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.mathjax",
    "numpydoc",
    "nbsphinx",
    "sphinx.ext.autosummary",
    "sphinx.ext.viewcode",
    "autoapi.extension",
    "myst_parser",
    "sphinx_design",
    "sphinx_copybutton",
    "sphinx_tabs.tabs",
]

templates_path = ["_templates"]
html_static_path = ["_static"]
html_favicon = "_static/logo.svg"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "requirements.txt"]

root_doc = "index"
source_suffix = [".rst", ".md"]


# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
fullversion = importlib.metadata.version("gwpopulation")
version = ".".join(fullversion.split(".")[:2])
# The full version, including alpha/beta/rc tags.
release = fullversion.split("+")[0]

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"


# The name of the Pygments (syntax highlighting) style to use.
# pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
# todo_include_todos = False


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

html_theme = "pydata_sphinx_theme"

autosummary_generate = True
numpydoc_show_class_members = False

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}


autoapi_dirs = ["../gwpopulation"]
autoapi_ignore = ["*_version*"]

json_url = "https://wcosmo.readthedocs.io/en/latest/_static/switcher.json"

version_match = os.environ.get("READTHEDOCS_VERSION")
# If READTHEDOCS_VERSION doesn't exist, we're not on RTD
# If it is an integer, we're in a PR build and the version isn't correct.
# If it's "latest" → change to "dev" (that's what we want the switcher to call it)
if not version_match or version_match.isdigit() or version_match == "latest":
    # For local development, infer the version to match from the package.
    if "dev" in release or "rc" in release:
        version_match = "dev"
        # We want to keep the relative reference if we are in dev mode
        # but we want the whole url if we are effectively in a released version
        json_url = "_static/switcher.json"
    else:
        version_match = f"v{release}"
elif version_match == "stable":
    version_match = f"v{release}"

html_theme_options = {
    "logo": {
        "text": f"GWPopulation v{version}",
        "image_light": "_static/logo.svg",
        "image_dark": "_static/logo-dark.svg",
    },
    "navbar_center": ["navbar-nav"],
    # "navbar_start": ["navbar-logo", "version-switcher"],
    "navbar_start": ["navbar-logo"],
    "navbar_end": ["theme-switcher", "navbar-icon-links"],
    "use_edit_page_button": True,
    "show_version_warning_banner": True,
    "footer_start": ["copyright"],
    "footer_center": ["sphinx-version"],
    # "switcher": {
    #     "json_url": json_url,
    #     "version_match": version_match,
    # },
    "icon_links": [
        {
            "name": "GitHub",
            "url": "https://github.com/ColmTalbot/GWPopulation",
            "icon": "fa-brands fa-github",
        },
    ],
}

html_context = {
    "github_user": "ColmTalbot",
    "github_repo": "gwpopulation",
    "github_version": "main",
    "doc_path": "docs",
}

nbsphinx_execute = "never"
nbsphinx_prolog = """
This page was automatically generated from a Jupyter notebook. Find the original here_.

.. image:: https://colab.research.google.com/assets/colab-badge.svg
    :target: https://colab.research.google.com/github/ColmTalbot/GWPopulation/blob/main/examples/{{ env.doc2path(env.docname, base=None) }}

.. _here: https://github.com/ColmTalbot/gwpopulation/tree/main/examples/{{ env.doc2path(env.docname, base=None) }}

----
"""
