# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import sys
sys.path.insert(0, os.path.abspath("../../../trainer")) # 在sys.path中设置好源码的路径

import importlib.util


def gendoc():
    """Get releases from Github and generate reStructuredText files for release notes."""
    dev_dir = "%s/../../dev" % os.path.dirname(os.path.abspath(__file__))
    spec = importlib.util.spec_from_file_location("gendoc", "%s/gendoc.py" % dev_dir)
    gendoc = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(gendoc)
    gendoc.download_pandoc_if_needed(dev_dir)
    source_dir = os.path.dirname(os.path.abspath(__file__))
    gendoc.gen_release_notes(source_dir)


# gendoc() # TODO 暂时还不会用


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

project = 'trainer-xy'
copyright = '2019, syy'
author = 'syy'

# The full version, including alpha/beta/rc tags
import trainer
release = os.environ.get('RELEASE_VERSION', trainer.__version__)


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

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.8'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.viewcode',
    'sphinx.ext.doctest',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.mathjax',
    # 'sphinx.ext.napoleon', # numpy and google # 很多异常，不用
    'numpydoc',  # handle NumPy documentation formatted docstrings. Needs to install
    # 'matplotlib.sphinxext.plot_directive',  # For visualize plot result
    'nbsphinx',  # Converts Jupyter Notebook to reStructuredText files for Sphinx.
    'IPython.sphinxext.ipython_console_highlighting',# For ipython directive in reStructuredText files.
]



# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# 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 = 'zh_CN'


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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# source suffix
from recommonmark.parser import CommonMarkParser # from sphinx_markdown_parser.markdown_builder import MarkdownBuilder # other
source_parsers = {
    '.md': CommonMarkParser,
}
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'source/index' # 



numpydoc_show_class_members = False
# numpydoc_xref_param_type = True


# highlight_language = 'python3'
add_module_names = True



# -- Options for auto output -------------------------------------------------

autoclass_content = 'both'
autosummary_generate = True


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

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = "classic" # 'sphinx_rtd_theme' #  'nature_with_gtoc' # 

# 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 = []

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = ['themes']

# If false, no index is generated.
html_use_index = False

# If false, no module index is generated.
html_domain_indices = False


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    ('index', 'trainer-xy', u'trainer-xy Documentation',
     [u'Author'], 1)
]


# -- Options for nbsphinx ------------------------------------------------

nbsphinx_allow_errors = True

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

latex_engine = "pdflatex"
latex_elements = {}

# The paper size ('letter' or 'a4').
latex_paper_size = 'a4'

# The font size ('10pt', '11pt' or '12pt').
# latex_font_size = '10pt'

# Grouping the document tree into LaTeX files. List of tuples (source start
# file, target name, title, author, documentclass [howto/manual]).

# 设置文档
latex_documents = [
    (
        master_doc, 
        'trainer.tex', 
        'trainer: batch dataframe',
        '作者：syy', 
        'manual', 
        True
    ),
]

# LaTeX, https://www.sphinx-doc.org/en/master/latex.html
latex_elements = {
    # \documentclass[UTF8, a4paper, notitlepage, cs4size]{ctexart}
    # 宏 导言区
    'preamble': '''
\\hypersetup{unicode=true}
\\usepackage{CJKutf8}
\\AtBeginDocument{\\begin{CJK}{UTF8}{gbsn}}
\\AtEndDocument{\\end{CJK}}
    '''
}

latex_show_urls = 'footnote'


# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False

# Additional stuff for the LaTeX preamble.
# latex_preamble = ''

# Documents to append as an appendix to all manuals.
# latex_appendices = []

# If false, no module index is generated.
# latex_use_modindex = True


# -- unused -------------------------------------------------------


# if pattern is None:
#     intersphinx_mapping = {
#         "dateutil": ("https://dateutil.readthedocs.io/en/latest/", None),
#         "matplotlib": ("https://matplotlib.org/", None),
#         "numpy": ("https://docs.scipy.org/doc/numpy/", None),
#         "pandas-gbq": ("https://pandas-gbq.readthedocs.io/en/latest/", None),
#         "py": ("https://pylib.readthedocs.io/en/latest/", None),
#         "python": ("https://docs.python.org/3/", None),
#         "scipy": ("https://docs.scipy.org/doc/scipy/reference/", None),
#         "statsmodels": ("http://www.statsmodels.org/devel/", None),
#     }

# # extlinks alias
# extlinks = {
#     "issue": ("https://github.com/pandas-dev/pandas/issues/%s", "GH"),
#     "wiki": ("https://github.com/pandas-dev/pandas/wiki/%s", "wiki "),
# }


# ipython_warning_is_error = False
# ipython_exec_lines = [
#     "import numpy as np",
#     "import pandas as pd",
#     # This ensures correct rendering on system with console encoding != utf8
#     # (windows). It forces pandas to encode its output reprs using utf8
#     # wherever the docs are built. The docs' target is the browser, not
#     # the console, so this is fine.
#     'pd.options.display.encoding="utf8"',
# ]






