import importlib.metadata
import re

project = "Virtue"
author = "Julian Berman"
copyright = "2014, " + author

release = importlib.metadata.version("virtue")
version = release.partition("-")[0]

language = "en"
default_role = "any"

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.autosectionlabel",
    "sphinx.ext.coverage",
    "sphinx.ext.doctest",
    "sphinx.ext.intersphinx",
    "sphinx.ext.napoleon",
    "sphinx.ext.viewcode",
    "sphinxcontrib.spelling",
]

pygments_style = "lovelace"
pygments_dark_style = "one-dark"

html_theme = "furo"

# = Builders =

nitpick_ignore = [
    # Missing from pyrsistent docs
    ("py:class", "pyrsistent.typing.PMap"),
    ("py:class", "pyrsistent.typing.PVector"),
]


def entire_domain(host):
    return r"http.?://" + re.escape(host) + r"($|/.*)"


linkcheck_ignore = [
    entire_domain("img.shields.io"),
    "https://github.com/Julian/Virtue/actions",
    "https://github.com/Julian/Virtue/workflows/CI/badge.svg",
]

# = Extensions =

# -- autodoc --

autodoc_default_options = {
    "members": True,
    "member-order": "bysource",
}

# -- autosectionlabel --

autosectionlabel_prefix_document = True

# -- intersphinx --

intersphinx_mapping = dict(
    pyrsistent=("https://pyrsistent.readthedocs.io/en/latest/", None),
    python=("https://docs.python.org/3", None),
    twisted=("https://docs.twistedmatrix.com/en/stable/api/", None),
)

# -- sphinxcontrib-spelling --

spelling_word_list_filename = "spelling-wordlist.txt"
spelling_show_suggestions = True
