import os

# Use sphinx-quickstart to create your own conf.py file!
# After that, you have to edit a few things.  See below.

# Select nbsphinx and, if needed, other Sphinx extensions:
extensions = [
    'nbsphinx',
    'sphinx_copybutton',  # for "copy to clipboard" buttons
    'sphinx.ext.mathjax',  # for math equations
    'sphinxcontrib.bibtex',  # for bibliographic references
    'sphinxcontrib.rsvgconverter',  # for SVG->PDF conversion in LaTeX output
    'sphinx_gallery.load_style',  # load CSS for gallery (needs SG >= 0.6)
    'sphinx_last_updated_by_git',  # get "last updated" from Git
]

# Default language for syntax highlighting in reST and Markdown cells:
highlight_language = 'none'

# Don't add .txt suffix to source files:
html_sourcelink_suffix = ''

# List of arguments to be passed to the kernel that executes the notebooks:
nbsphinx_execute_arguments = [
    "--InlineBackend.figure_formats={'svg', 'pdf'}",
    "--InlineBackend.rc={'figure.dpi': 96}",
]

# Environment variables to be passed to the kernel:
os.environ['MY_DUMMY_VARIABLE'] = 'Hello from conf.py!'

nbsphinx_thumbnails = {
    'gallery/thumbnail-from-conf-py': 'gallery/a-local-file.png',
    'gallery/*-rst': '_static/copy-button.svg',
}

# This is processed by Jinja2 and inserted before each notebook
nbsphinx_prolog = r"""
{% set docname = 'doc/' + env.doc2path(env.docname, base=None) %}

.. raw:: html

    <div class="admonition note">
      This page was generated from
      <a class="reference external" href="https://github.com/spatialaudio/nbsphinx/blob/{{ env.config.release|e }}/{{ docname|e }}">{{ docname|e }}</a>.
      Interactive online version:
      <span style="white-space: nowrap;"><a href="https://mybinder.org/v2/gh/spatialaudio/nbsphinx/{{ env.config.release|e }}?filepath={{ docname|e }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>.</span>
      <script>
        if (document.location.host) {
          $(document.currentScript).replaceWith(
            '<a class="reference external" ' +
            'href="https://nbviewer.jupyter.org/url' +
            (window.location.protocol == 'https:' ? 's/' : '/') +
            window.location.host +
            window.location.pathname.slice(0, -4) +
            'ipynb">View in <em>nbviewer</em></a>.'
          );
        }
      </script>
    </div>

.. raw:: latex

    \nbsphinxstartnotebook{\scriptsize\noindent\strut
    \textcolor{gray}{The following section was generated from
    \sphinxcode{\sphinxupquote{\strut {{ docname | escape_latex }}}} \dotfill}}
"""

# This is processed by Jinja2 and inserted after each notebook
nbsphinx_epilog = r"""
{% set docname = 'doc/' + env.doc2path(env.docname, base=None) %}
.. raw:: latex

    \nbsphinxstopnotebook{\scriptsize\noindent\strut
    \textcolor{gray}{\dotfill\ \sphinxcode{\sphinxupquote{\strut
    {{ docname | escape_latex }}}} ends here.}}
"""

mathjax_config = {
    'TeX': {'equationNumbers': {'autoNumber': 'AMS', 'useLabelIds': True}},
}

# Additional files needed for generating LaTeX/PDF output:
latex_additional_files = ['references.bib']

# Support for notebook formats other than .ipynb
nbsphinx_custom_formats = {
    '.pct.py': ['jupytext.reads', {'fmt': 'py:percent'}],
}

# -- The settings below this line are not specific to nbsphinx ------------

master_doc = 'index'

project = 'nbsphinx'
author = 'Matthias Geier'
copyright = '2020, ' + author
html_show_copyright = False

linkcheck_ignore = [
    r'http://localhost:\d+/',
    'https://github.com/spatialaudio/nbsphinx/compare/',
]

nitpicky = True

# -- Get version information and date from Git ----------------------------

try:
    from subprocess import check_output
    release = check_output(['git', 'describe', '--tags', '--always'])
    release = release.decode().strip()
    today = check_output(['git', 'show', '-s', '--format=%ad', '--date=short'])
    today = today.decode().strip()
except Exception:
    release = '<unknown>'
    today = '<unknown date>'

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

html_favicon = 'favicon.svg'
html_title = project + ' version ' + release

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

# See https://www.sphinx-doc.org/en/master/latex.html
latex_elements = {
    'papersize': 'a4paper',
    'printindex': '',
    'sphinxsetup': r"""
        %verbatimwithframe=false,
        %verbatimwrapslines=false,
        %verbatimhintsturnover=false,
        VerbatimColor={HTML}{F5F5F5},
        VerbatimBorderColor={HTML}{E0E0E0},
        noteBorderColor={HTML}{E0E0E0},
        noteborder=1.5pt,
        warningBorderColor={HTML}{E0E0E0},
        warningborder=1.5pt,
        warningBgColor={HTML}{FBFBFB},
    """,
    'preamble': r"""
\usepackage[sc,osf]{mathpazo}
\linespread{1.05}  % see http://www.tug.dk/FontCatalogue/urwpalladio/
\renewcommand{\sfdefault}{pplj}  % Palatino instead of sans serif
\IfFileExists{zlmtt.sty}{
    \usepackage[light,scaled=1.05]{zlmtt}  % light typewriter font from lmodern
}{
    \renewcommand{\ttdefault}{lmtt}  % typewriter font from lmodern
}
\usepackage{booktabs}  % for Pandas dataframes
""",
}

latex_documents = [
    (master_doc, 'nbsphinx.tex', project, author, 'howto'),
]

latex_show_urls = 'footnote'
latex_show_pagerefs = True

# -- Options for EPUB output ----------------------------------------------

# These are just defined to avoid Sphinx warnings related to EPUB:
version = release
suppress_warnings = ['epub.unknown_project_files']

# -- Set default HTML theme (if none was given above) ---------------------

if 'html_theme' not in globals():
    try:
        import insipid_sphinx_theme
    except ImportError:
        pass
    else:
        html_theme = 'insipid'
        html_copy_source = False
        html_add_permalinks = '\N{SECTION SIGN}'




###########################################################################
#          auto-created readthedocs.org specific configuration            #
###########################################################################


#
# The following code was added during an automated build on readthedocs.org
# It is auto created and injected for every build. The result is based on the
# conf.py.tmpl file found in the readthedocs.org codebase:
# https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
#


import importlib
import sys
import os.path
from six import string_types

from sphinx import version_info

# Get suffix for proper linking to GitHub
# This is deprecated in Sphinx 1.3+,
# as each page can have its own suffix
if globals().get('source_suffix', False):
    if isinstance(source_suffix, string_types):
        SUFFIX = source_suffix
    elif isinstance(source_suffix, (list, tuple)):
        # Sphinx >= 1.3 supports list/tuple to define multiple suffixes
        SUFFIX = source_suffix[0]
    elif isinstance(source_suffix, dict):
        # Sphinx >= 1.8 supports a mapping dictionary for multiple suffixes
        SUFFIX = list(source_suffix.keys())[0]  # make a ``list()`` for py2/py3 compatibility
    else:
        # default to .rst
        SUFFIX = '.rst'
else:
    SUFFIX = '.rst'

# Add RTD Static Path. Add to the end because it overwrites previous files.
if not 'html_static_path' in globals():
    html_static_path = []
if os.path.exists('_static'):
    html_static_path.append('_static')

# Add RTD Theme only if they aren't overriding it already
using_rtd_theme = (
    (
        'html_theme' in globals() and
        html_theme in ['default'] and
        # Allow people to bail with a hack of having an html_style
        'html_style' not in globals()
    ) or 'html_theme' not in globals()
)
if using_rtd_theme:
    theme = importlib.import_module('sphinx_rtd_theme')
    html_theme = 'sphinx_rtd_theme'
    html_style = None
    html_theme_options = {}
    if 'html_theme_path' in globals():
        html_theme_path.append(theme.get_html_theme_path())
    else:
        html_theme_path = [theme.get_html_theme_path()]

if globals().get('websupport2_base_url', False):
    websupport2_base_url = 'https://readthedocs.org/websupport'
    websupport2_static_url = 'https://assets.readthedocs.org/static/'


#Add project information to the template context.
context = {
    'using_theme': using_rtd_theme,
    'html_theme': html_theme,
    'current_version': "0.8.1",
    'version_slug': "0.8.1",
    'MEDIA_URL': "https://media.readthedocs.org/",
    'STATIC_URL': "https://assets.readthedocs.org/static/",
    'PRODUCTION_DOMAIN': "readthedocs.org",
    'versions': [
    ("latest", "/en/latest/"),
    ("0.8.1", "/en/0.8.1/"),
    ("0.8.0", "/en/0.8.0/"),
    ("0.7.1", "/en/0.7.1/"),
    ("0.7.0", "/en/0.7.0/"),
    ("0.6.1", "/en/0.6.1/"),
    ("0.6.0", "/en/0.6.0/"),
    ("0.5.1", "/en/0.5.1/"),
    ("0.5.0", "/en/0.5.0/"),
    ("0.4.3", "/en/0.4.3/"),
    ("0.4.2", "/en/0.4.2/"),
    ("0.4.1", "/en/0.4.1/"),
    ("0.3.5", "/en/0.3.5/"),
    ("0.3.4", "/en/0.3.4/"),
    ("0.3.3", "/en/0.3.3/"),
    ("0.3.2", "/en/0.3.2/"),
    ("0.3.1", "/en/0.3.1/"),
    ("0.3.0", "/en/0.3.0/"),
    ("0.2.18", "/en/0.2.18/"),
    ("0.2.17", "/en/0.2.17/"),
    ("0.2.16", "/en/0.2.16/"),
    ("0.2.15", "/en/0.2.15/"),
    ("0.2.14", "/en/0.2.14/"),
    ("0.2.13", "/en/0.2.13/"),
    ("0.2.12", "/en/0.2.12/"),
    ("0.2.11", "/en/0.2.11/"),
    ("0.2.10", "/en/0.2.10/"),
    ("0.2.9", "/en/0.2.9/"),
    ("0.2.8", "/en/0.2.8/"),
    ("0.2.7", "/en/0.2.7/"),
    ("0.2.6", "/en/0.2.6/"),
    ("0.2.5", "/en/0.2.5/"),
    ("0.2.4", "/en/0.2.4/"),
    ("0.2.3", "/en/0.2.3/"),
    ("0.2.2", "/en/0.2.2/"),
    ("0.2.1", "/en/0.2.1/"),
    ("0.2.0", "/en/0.2.0/"),
    ("uedoc-theme", "/en/uedoc-theme/"),
    ("typlog-theme", "/en/typlog-theme/"),
    ("traditional-theme", "/en/traditional-theme/"),
    ("sphinxdoc-theme", "/en/sphinxdoc-theme/"),
    ("sphinx-book-theme", "/en/sphinx-book-theme/"),
    ("sizzle-theme", "/en/sizzle-theme/"),
    ("scrolls-theme", "/en/scrolls-theme/"),
    ("save-rst", "/en/save-rst/"),
    ("rtd-theme", "/en/rtd-theme/"),
    ("pyviz-theme", "/en/pyviz-theme/"),
    ("pytorch-theme", "/en/pytorch-theme/"),
    ("pyramid-theme", "/en/pyramid-theme/"),
    ("pydata-theme", "/en/pydata-theme/"),
    ("py3doc-enhanced-theme", "/en/py3doc-enhanced-theme/"),
    ("pangeo-theme", "/en/pangeo-theme/"),
    ("pandas-theme", "/en/pandas-theme/"),
    ("nature-theme", "/en/nature-theme/"),
    ("material-theme", "/en/material-theme/"),
    ("maisie-theme", "/en/maisie-theme/"),
    ("jupyter-theme", "/en/jupyter-theme/"),
    ("insipid-theme", "/en/insipid-theme/"),
    ("holoviz-theme", "/en/holoviz-theme/"),
    ("haiku-theme", "/en/haiku-theme/"),
    ("guzzle-theme", "/en/guzzle-theme/"),
    ("furo-theme", "/en/furo-theme/"),
    ("documatt-theme", "/en/documatt-theme/"),
    ("dask-theme", "/en/dask-theme/"),
    ("cloud-theme", "/en/cloud-theme/"),
    ("classic-theme", "/en/classic-theme/"),
    ("bootstrap-theme", "/en/bootstrap-theme/"),
    ("bizstyle-theme", "/en/bizstyle-theme/"),
    ("better-theme", "/en/better-theme/"),
    ("basicstrap-theme", "/en/basicstrap-theme/"),
    ("astropy-theme", "/en/astropy-theme/"),
    ("alabaster-theme", "/en/alabaster-theme/"),
    ("agogo-theme", "/en/agogo-theme/"),
    ("0.1.0", "/en/0.1.0/"),
    ],
    'downloads': [ 
    ("pdf", "//nbsphinx.readthedocs.io/_/downloads/en/0.8.1/pdf/"),
    ("html", "//nbsphinx.readthedocs.io/_/downloads/en/0.8.1/htmlzip/"),
    ("epub", "//nbsphinx.readthedocs.io/_/downloads/en/0.8.1/epub/"),
    ],
    'subprojects': [ 
    ],
    'slug': 'nbsphinx',
    'name': u'nbsphinx',
    'rtd_language': u'en',
    'programming_language': u'py',
    'canonical_url': 'https://nbsphinx.readthedocs.io/en/0.8.1/',
    'analytics_code': 'None',
    'single_version': False,
    'conf_py_path': '/doc/',
    'api_host': 'https://readthedocs.org',
    'github_user': 'spatialaudio',
    'proxied_api_host': '/_',
    'github_repo': 'nbsphinx',
    'github_version': '0.8.1',
    'display_github': True,
    'bitbucket_user': 'None',
    'bitbucket_repo': 'None',
    'bitbucket_version': '0.8.1',
    'display_bitbucket': False,
    'gitlab_user': 'None',
    'gitlab_repo': 'None',
    'gitlab_version': '0.8.1',
    'display_gitlab': False,
    'READTHEDOCS': True,
    'using_theme': (html_theme == "default"),
    'new_theme': (html_theme == "sphinx_rtd_theme"),
    'source_suffix': SUFFIX,
    'ad_free': False,
    'docsearch_disabled': False,
    'user_analytics_code': '',
    'global_analytics_code': None,
    'commit': '2432715f',
}

# For sphinx >=1.8 we can use html_baseurl to set the canonical URL.
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl
if version_info >= (1, 8):
    if not globals().get('html_baseurl'):
        html_baseurl = context['canonical_url']
    context['canonical_url'] = None





if 'html_context' in globals():
    
    html_context.update(context)
    
else:
    html_context = context

# Add custom RTD extension
if 'extensions' in globals():
    # Insert at the beginning because it can interfere
    # with other extensions.
    # See https://github.com/rtfd/readthedocs.org/pull/4054
    extensions.insert(0, "readthedocs_ext.readthedocs")
else:
    extensions = ["readthedocs_ext.readthedocs"]

# Add External version warning banner to the external version documentation
if 'tag' == 'external':
    extensions.insert(1, "readthedocs_ext.external_version_warning")

project_language = 'en'

# User's Sphinx configurations
language_user = globals().get('language', None)
latex_engine_user = globals().get('latex_engine', None)
latex_elements_user = globals().get('latex_elements', None)

# Remove this once xindy gets installed in Docker image and XINDYOPS
# env variable is supported
# https://github.com/rtfd/readthedocs-docker-images/pull/98
latex_use_xindy = False

chinese = any([
    language_user in ('zh_CN', 'zh_TW'),
    project_language in ('zh_CN', 'zh_TW'),
])

japanese = any([
    language_user == 'ja',
    project_language == 'ja',
])

if chinese:
    latex_engine = latex_engine_user or 'xelatex'

    latex_elements_rtd = {
        'preamble': '\\usepackage[UTF8]{ctex}\n',
    }
    latex_elements = latex_elements_user or latex_elements_rtd
elif japanese:
    latex_engine = latex_engine_user or 'platex'

# Make sure our build directory is always excluded
exclude_patterns = globals().get('exclude_patterns', [])
exclude_patterns.extend(['_build'])
