#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sphinx.util import logging
import sys
import os
from os.path import abspath

sys.path.insert(0, abspath('..'))

# General Configuration

# Extensions that are used for these docs
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'sphinx.ext.intersphinx',
    'sphinx.ext.napoleon',
    'sphinx.ext.todo',
    'nbsphinx',
    'jupyter_sphinx',
    'nbsphinx_link',
    'myst_parser',
]

# Enable extensions for MyST
myst_enable_extensions = [
    'substitution'
]

# Set the nbsphinx JS path to empty to avoid showing twice of the widgets
nbsphinx_requirejs_path = ""
nbsphinx_widgets_path = ""

# directory for templates files
templates_path = ['_templates']
# suffix to source filenames
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'Trident Chemwidgets'
copyright = '2022, Trident Bioscience, Inc.'
author = 'Trident Bioscience, Inc.'

# get version from python package:
here = os.path.dirname(__file__)
repo = os.path.join(here, '..')
_version_py = os.path.join(repo, 'trident_chemwidgets', '_version.py')
version_ns = {}
with open(_version_py) as f:
    exec(f.read(), version_ns)

# The short X.Y version.
version = '%i.%i' % version_ns['version_info'][:2]
# The full version, including alpha/beta/rc tags.
release = version_ns['__version__']

# 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 = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['**.ipynb_checkpoints']

# 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

# Handle substitutions for MyST
myst_substitutions = {
    'version': release
}


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


# 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 = {
    'sidebar_hide_name': True,
    'light_css_variables': {
        'color-brand-primary': '#384E77',
        'color-brand-content': '#384E77',
    },
    'dark_css_variables': {
        'color-brand-primary': '#8BBEB2',
        'color-brand-content': '#8BBEB2',
    },
}
html_logo = '_static/logo.svg'
html_favicon = '_static/favicon.ico'
html_title = f'Trident Chemwidgets - Docs v{version}'

# 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']


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

# Output file base name for HTML help builder.
htmlhelp_basename = 'trident_chemwidgetsdoc'


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

# latex_elements = {
#     # 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, 'trident_chemwidgets.tex', 'trident_chemwidgets Documentation',
#      'Trident Bioscience, Inc.', '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,
     'trident_chemwidgets',
     'trident_chemwidgets 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,
     'trident_chemwidgets',
     'trident_chemwidgets Documentation',
     author,
     'trident_chemwidgets',
     'Chemical widget set to work in jupyter notebook and lab.',
     'Miscellaneous'),
]


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

# import sphinx_rtd_theme
html_theme = 'furo'
# html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

html_theme_path = []


# Uncomment this line if you have know exceptions in your included notebooks
# that nbsphinx complains about:
#
nbsphinx_allow_errors = True  # exception ipstruct.py ipython_genutils

logger = logging.getLogger(__name__)


def setup(app):
    def add_scripts(app):
        for fname in ['helper.js', 'embed-bundle.js']:
            if not os.path.exists(os.path.join(here, '_static', fname)):
                logger.warning('missing javascript file: %s' % fname)
            app.add_js_file(fname)
    app.connect('builder-inited', add_scripts)
