import os, sys
from importlib import metadata

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.intersphinx',
]
def check_object_path(key, url, path):
    if path and os.path.isfile(path):
        return {key: (url, path)}
    return {}

intersphinx_mapping = {}
intersphinx_mapping.update(
    check_object_path('pytest',
                      'https://docs.pytest.org/en/stable/',
                      '/usr/share/doc/python-pytest-doc/html/objects.inv'))
intersphinx_mapping.update(
    check_object_path('python',
                      'https://docs.python.org/3/',
                      '/usr/share/doc/python%d.%d/html/objects.inv' % \
                       sys.version_info[:2]))
intersphinx_mapping.update(
    check_object_path('sphinx',
                      'https://www.sphinx-doc.org/en/stable/',
                      '/usr/share/doc/sphinx-doc/html/objects.inv'))
intersphinx_mapping.update(
    check_object_path('myst',
                      'https://myst-parser.readthedocs.io/en/latest',
                      None))  # the docs are not packaged

# General
source_suffix = '.rst'
master_doc = 'index'
project = 'sybil'
copyright = '2017 onwards Chris Withers'
if "DEB_VERSION_UPSTREAM" in os.environ:
    version = release = os.environ["DEB_VERSION_UPSTREAM"]
else:
    version = release = metadata.version(project)
exclude_patterns = [
    '_build',
    'example*',
]
pygments_style = 'sphinx'
autodoc_member_order = 'bysource'

# Options for HTML output
html_theme = 'furo'
htmlhelp_basename = project + 'doc'

nitpicky = True
nitpick_ignore = [
    ('py:class', 'Evaluator'),  # https://github.com/sphinx-doc/sphinx/issues/10785
    ('py:class', 'LexemeMapping'),  # https://github.com/sphinx-doc/sphinx/issues/10785
]
toc_object_entries = False
