# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# https://www.sphinx-doc.org/en/master/config
"""
Sphinx configuration for FAT Forensics.
"""

import datetime
import os
import sys

import fatf

# -- 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.
#
sys.path.insert(0, os.path.abspath('.'))

from linkcode_github import make_linkcode_resolve

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

current_year = datetime.datetime.now().year

github_org = 'fat-forensics'
github_repo = 'fat-forensics'
github_docs_repo = 'fat-forensics-doc'

project = 'FAT Forensics'
copyright = (  # pylint: disable=redefined-builtin
    '2018--{}, Kacper Sokol et al.'.format(current_year))
author = 'Kacper Sokol et al.'

title = 'FAT Forensics Documentation'
short_description = 'One line description of project.'

# The short X.Y version
version = fatf.__version__
# The full version, including alpha/beta/rc tags
release = fatf.__version__

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

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

# 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.autosummary',
    'numpydoc',
    'sphinx.ext.linkcode',  # Show source as a URL to GitHub
    # 'sphinx.ext.viewcode',  # Show source as a web page generated from rST
    'sphinx.ext.intersphinx',  # Link documentation of other projects
    'sphinx.ext.doctest',  # Used for documentation Python setup code blocks
    'sphinx.ext.coverage',
    'sphinx.ext.githubpages',
    # 'sphinx.ext.mathjax',  # Appended later based on OS variables
    # 'sphinx.ext.imgconverter',
    'sphinx_gallery.gen_gallery'
]

# Generate docstrings for methods with autosummary and numpydoc
# See https://github.com/numpy/numpydoc/issues/69
numpydoc_class_members_toctree = False
# class_members_toctree = False
#
# numpydoc_show_class_members = True  # Handled by `autodoc_default_options`

# Document class members and inherited class members by default
# autodoc_default_flags = ['members', 'inherited-members']  # sphinx<1.8
autodoc_default_options = {'members': True, 'inherited-members': True}
autodoc_typehints = 'none'

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

# For maths, use mathjax by default and svg if NO_MATHJAX env variable is set
# (useful for viewing the doc offline)
if os.environ.get('NO_MATHJAX'):
    extensions.append('sphinx.ext.imgmath')
    imgmath_image_format = 'svg'
else:
    extensions.append('sphinx.ext.mathjax')
    mathjax_path = ('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/'
                    'MathJax.js?config=TeX-AMS_SVG')

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content auto-generated 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 pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'themes', 'templates', 'resources',
                    'Thumbs.db', '.DS_Store', '__pycache__',
                    'linkcode_github.py', 'JOSS_paper']

# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = False

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

# Generate auto-summary even if no references.
# (https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html)
autosummary_generate = True

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

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

sphinx_gallery_conf = {
    'filename_pattern': '/xmpl_',
    'examples_dir': os.path.join('..', 'examples'),
    'gallery_dirs': 'sphinx_gallery_auto',
    'backreferences_dir': 'generated',  # `doc_module`
    'doc_module': 'fatf',  # Generate mini galleries for the API documentation.
    'reference_url': {'fatf': None},  # Put links to docs in the examples code.
    'binder': {
        'org': github_org,
        'repo': github_docs_repo,
        'branch': 'master',
        'binderhub_url': 'https://mybinder.org',
        'dependencies': ['requirements.txt']
    }
}

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

html_baseurl = 'https://fat-forensics.org'

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'fat-forensics'  # 'nature', 'alabaster'

# 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 = {}

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

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

# Copy extra files to the target build directory.
html_extra_path = ['Readme.md', '.nojekyll']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself.  Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = 'logos/fatf.png'

html_favicon = 'logos/fatf.ico'

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

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

# -- 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, 'FATForensics.tex', title, author, '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, 'fatforensics', title, [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, 'FATForensics', title, author, 'FATForensics',
     short_description, 'Miscellaneous'),
]

# -- Extension configuration -------------------------------------------------

# -- Options for coverage extension ------------------------------------------
coverage_ignore_functions = [
    'fatf_structured_to_unstructured',
    'fatf_structured_to_unstructured_row'
]

# Remove <BLANKLINE> and # doctest: options for all code blocks (including
# the ones imported from doc strings.)
trim_doctest_flags = True

# -- Options for linkcode extension ------------------------------------------
# The following is used by sphinx.ext.linkcode to provide links to GitHub
fatf_github_url = ('https://github.com/%s/%s/blob/{revision}/{package}/{path}'
                   '#L{lineno}') % (github_org, github_repo)
linkcode_resolve = make_linkcode_resolve('fatf', fatf_github_url)

# -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
    # 'https://docs.python.org/': None
    'python': ('https://docs.python.org/{.major}'.format(sys.version_info),
               None),
    'numpy': ('https://docs.scipy.org/doc/numpy/', None),
    'scipy': ('https://docs.scipy.org/doc/scipy/reference', None),
    'sklearn': ('https://scikit-learn.org/stable', None),
    'skimage': ('https://scikit-image.org/docs/stable', None),
    'PIL': ('https://pillow.readthedocs.io/en/stable', None),
    'matplotlib': ('https://matplotlib.org/', None)
}
