# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.

import os
import sys
import shutil
# Check these extensions were installed.
import sphinx_gallery.gen_gallery
# The package should be installed in a virtual environment.
import onnxruntime
# The documentation requires two extensions available at:
# https://github.com/xadupre/sphinx-docfx-yaml
# https://github.com/xadupre/sphinx-docfx-markdown
import sphinx_modern_theme


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

project = 'ONNX Runtime'
copyright = '2018, Microsoft'
author = 'Microsoft'
version = onnxruntime.__version__
release = version

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

extensions = [
    'sphinx.ext.intersphinx',
    'sphinx.ext.imgmath',
    'sphinx.ext.ifconfig',
    'sphinx.ext.viewcode',
    "sphinx.ext.autodoc",
    'sphinx.ext.githubpages',
    "sphinx_gallery.gen_gallery",
    'sphinx.ext.autodoc',
    "docfx_yaml.extension",
    "docfx_markdown",
    "pyquickhelper.sphinxext.sphinx_runpython_extension",
]

templates_path = ['_templates']

source_parsers = {
   '.md': 'recommonmark.parser.CommonMarkParser',
}

source_suffix = ['.rst', '.md']

master_doc = 'intro'
language = "en"
exclude_patterns = []
pygments_style = 'sphinx'

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

html_theme = "sphinx_modern_theme"
html_theme_path = [sphinx_modern_theme.get_html_theme_path()]
html_logo = "../MSFT-Onnx-Runtime-11282019-Logo.png"
html_static_path = ['_static']

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

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

# -- Options for Sphinx Gallery ----------------------------------------------

sphinx_gallery_conf = {
     'examples_dirs': 'examples',
     'gallery_dirs': 'auto_examples',
}

# -- markdown options -----------------------------------------------------------

md_image_dest = "media"
md_link_replace = {
    '#onnxruntimesessionoptionsenable-profiling)': '#class-onnxruntimesessionoptions)',
}

# -- Setup actions -----------------------------------------------------------

def setup(app):
    # Placeholder to initialize the folder before
    # generating the documentation.
    app.add_stylesheet('_static/gallery.css')
    
    # download examples for the documentation
    this = os.path.abspath(os.path.dirname(__file__))
    dest = os.path.join(this, "model.onnx")
    if not os.path.exists(dest):
        import urllib.request
        url = 'https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_sigmoid/model.onnx'
        urllib.request.urlretrieve(url, dest)
    loc = os.path.split(dest)[-1]
    if not os.path.exists(loc):
        import shutil
        shutil.copy(dest, loc)
    return app


[((61, 19, 61, 60), 'sphinx_modern_theme.get_html_theme_path', 'sphinx_modern_theme.get_html_theme_path', ({}, {}), '()', False, 'import sphinx_modern_theme\n'), ((93, 11, 93, 43), 'os.path.join', 'os.path.join', ({(93, 24, 93, 28): 'this', (93, 30, 93, 42): '"""model.onnx"""'}, {}), "(this, 'model.onnx')", False, 'import os\n'), ((92, 27, 92, 52), 'os.path.dirname', 'os.path.dirname', ({(92, 43, 92, 51): '__file__'}, {}), '(__file__)', False, 'import os\n'), ((94, 11, 94, 31), 'os.path.exists', 'os.path.exists', ({(94, 26, 94, 30): 'dest'}, {}), '(dest)', False, 'import os\n'), ((98, 10, 98, 29), 'os.path.split', 'os.path.split', ({(98, 24, 98, 28): 'dest'}, {}), '(dest)', False, 'import os\n'), ((99, 11, 99, 30), 'os.path.exists', 'os.path.exists', ({(99, 26, 99, 29): 'loc'}, {}), '(loc)', False, 'import os\n'), ((101, 8, 101, 30), 'shutil.copy', 'shutil.copy', ({(101, 20, 101, 24): 'dest', (101, 26, 101, 29): 'loc'}, {}), '(dest, loc)', False, 'import shutil\n')]