#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

import os

import gi

gi.require_version("Pango", "1.0")
gi.require_version("PangoCairo", "1.0")

from gaphor.application import distribution  # noqa: E402

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

project = "Gaphor"
copyright = "2001, The Gaphor Development Team"
author = "Arjan Molenaar"
version = distribution().version

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

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.doctest",
    "sphinx.ext.intersphinx",
    "sphinx.ext.coverage",
    "sphinx.ext.viewcode",
    "sphinx.ext.autosectionlabel",
    "myst_nb",
    "sphinx_copybutton",
    "gaphor.extensions.sphinx",
    "IPython.sphinxext.ipython_console_highlighting",
]

autodoc_mock_imports = [
    "gi.repository.Gdk",
    "gi.repository.Gtk",
    "gi.repository.Adw",
    "gi.repository.GtkSource",
    "gi.repository.Graphene",
]
gi.require_version = lambda *_: ...

os.environ["PYDEVD_DISABLE_FILE_VALIDATION"] = "1"

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

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = {".rst": "restructuredtext", ".md": "restructuredtext"}

# The master toctree document.
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
locale_dirs = ["locale/"]
gettext_compact = "docs"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

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

nb_execution_show_tb = True
nb_execution_raise_on_error = True
nb_render_markdown_format = "myst"

myst_heading_anchors = 3
suppress_warnings = ["myst.header"]

gaphor_models = {
    "connect": "connect.gaphor",
    "design-principles": "design-principles.gaphor",
    "stereotypes": "stereotypes.gaphor",
    "example": "../examples/sequence-diagram.gaphor",
    "coffee-machine": "../examples/coffee-machine.gaphor",
    "sysml-template": "../gaphor/templates/sysml.gaphor",
    "style-sheets": "style-sheet-examples.gaphor",
    "core": "../models/Core.gaphor",
    "uml": "../models/UML.gaphor",
    "sysml": "../models/SysML.gaphor",
    "raaml": "../models/RAAML.gaphor",
    "c4model": "../models/C4Model.gaphor",
}

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

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = "furo"
html_favicon = "../data/logos/gaphor-24x24.png"

# 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 = {
    "light_logo": "gaphor-logo-full-black.svg",
    "dark_logo": "gaphor-logo-full-white.svg",
    "sidebar_hide_name": True,
}

# 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",
]

html_css_files = [
    "css/custom.css",
]
html_js_files = [
    "js/utterances.js",
]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = "Gaphordoc"


# -- Options for LaTeX output ------------------------------------------------

latex_elements: dict[str, str] = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',
    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',
    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',
    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [(master_doc, "Gaphor.tex", "Gaphor Documentation", author, "manual")]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "gaphor", "Gaphor Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (
        master_doc,
        "Gaphor",
        "Gaphor Documentation",
        author,
        "Gaphor",
        "The simple modeling tool",
        "Miscellaneous",
    )
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
    "gnome": ("https://api.pygobject.gnome.org", None),
    "pygobject": ("https://pygobject.gnome.org", None),
    "gaphas": ("https://gaphas.readthedocs.io/en/stable", None),
    "python": ("https://docs.python.org/3", None),
}

# Canonical URL required for custom domain with RTD Addons enabled
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "")
