from __future__ import annotations

#
# Progress Bar documentation build configuration file, created by
# sphinx-quickstart on Tue Aug 20 11:47:33 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import datetime
import os
import sys

# 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('..'))
# Only `_ext` -- never `docs` itself. Putting `docs/` on sys.path would let
# something resolve a plain `import examples` to `docs/examples` instead of
# the real top-level `examples.py`, permanently shadowing it for the rest
# of the process once Python caches the wrong module under
# `sys.modules['examples']` (see docs/_ext/demo.py's `load_docs_examples`
# for how the demo directive avoids that instead).
sys.path.insert(0, os.path.abspath('_ext'))

from progressbar import __about__ as metadata

# -- 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.doctest',
    'sphinx.ext.intersphinx',
    'sphinx.ext.todo',
    'sphinx.ext.coverage',
    'sphinx.ext.mathjax',
    'sphinx.ext.ifconfig',
    'sphinx.ext.viewcode',
    'sphinx.ext.napoleon',
    'demo',
]

# `sphinx-autodoc-typehints` is a declared docs dependency but is
# deliberately NOT enabled. It would move each annotation next to its
# parameter description, which suits docstrings that never repeat a type
# in prose -- but it cannot document this package. Enabling it fails the
# `-W` build with 40 `error while formatting signature ... list assignment
# index out of range` warnings, one per module-level callable *instance*
# documented as a data member: every `CSINoArg`/`CSI` escape sequence
# (`CLEAR_LINE`, `CUP`, `HIDE_CURSOR`, ...) and every `ColorGradient`
# class attribute (`Bar.fg`, `JobStatusBar.success_fg_color`, ...). The
# extension tries to resolve hints against the instance rather than its
# `__call__`, and that pattern is pervasive here. Autodoc already renders
# the annotations in the signature, so nothing is lost by leaving this
# off. Do not re-enable without rebuilding from a clean `docs/_build`:
# an incremental rebuild reuses cached doctrees and reports success.

# Merge each class's `__init__` docstring into its class page. Constructor
# arguments are user-facing -- `ProgressBar` alone takes more than fifteen
# -- and without this the default ('class') renders only the class
# docstring, leaving all of that documentation invisible to readers.
autoclass_content = 'both'

suppress_warnings = [
    'image.nonlocal_uri',
    # The ePub builder copies `html_static_path` wholesale and warns about
    # every file whose extension it does not recognise. That is the vendored
    # xterm.js licence and README, and the two wheels plus manifest the
    # in-browser console installs -- all of which belong in the HTML output
    # and are simply inert in an ePub. Read the Docs builds with
    # `fail_on_warning`, so without this the ePub fails on files that are
    # doing exactly what they should.
    'epub.unknown_project_files',
]

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

# The suffix of source filenames.
source_suffix = '.rst'

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = 'Progress Bar'
project_slug: str = ''.join(project.capitalize().split())
copyright = f'{datetime.date.today().year},  <a href="http://wol.ph/">{metadata.__author__}</a>'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version: str = metadata.__version__
# The full version, including alpha/beta/rc tags.
release: str = metadata.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']

# The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None

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

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = True

# The name of the Pygments (syntax highlighting) style to use.
# Furo selects its own light/dark Pygments themes; overriding either one
# breaks the dark-mode contrast it ships with.
pygments_style = None

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False


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

# 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: dict[str, object] = {
    'source_repository': 'https://github.com/wolph/python-progressbar/',
    'source_branch': 'develop',
    'source_directory': 'docs/',
}

# The name for this set of Sphinx documents.  If None, it defaults to
# "<project> v<release> documentation".
# html_title = None

# A shorter title for the navigation bar.  Default is the same as html_title.
# html_short_title = None

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

# The name of an image file (within the static path) to use as favicon of the
# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# html_favicon = None

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

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}

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

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

# If true, the index is split into individual pages for each letter.
# html_split_index = False

# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it.  The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = f'{project_slug}doc'


# -- 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': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents: list[tuple[str, ...]] = [
    (
        'index',
        f'{project_slug}.tex',
        f'{project} Documentation',
        metadata.__author__,
        'manual',
    )
]

# 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

# If true, show page references after internal links.
# latex_show_pagerefs = False

# If true, show URL addresses after external links.
# latex_show_urls = False

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

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


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

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages: list[tuple[str, str, str, list[str], int]] = [
    (
        'index',
        project_slug.lower(),
        f'{project} Documentation',
        [metadata.__author__],
        1,
    )
]

# If true, show URL addresses after external links.
# man_show_urls = False


# -- 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: list[tuple[str, ...]] = [
    (
        'index',
        project_slug,
        f'{project} Documentation',
        metadata.__author__,
        project_slug,
        'One line description of project.',
        'Miscellaneous',
    )
]

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

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

# How to display URL addresses: 'footnote', 'no', or 'inline'.
# texinfo_show_urls = 'footnote'

# If true, do not generate a @detailmenu in the "Top" node's menu.
# texinfo_no_detailmenu = False


# -- Options for Epub output ---------------------------------------------

# Bibliographic Dublin Core info.
epub_title: str = project
epub_author: str = metadata.__author__
epub_publisher: str = metadata.__author__
epub_copyright: str = copyright

# The language of the text. It defaults to the language option
# or en if the language is not set.
# epub_language = ''

# The scheme of the identifier. Typical schemes are ISBN or URL.
# epub_scheme = ''

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
# epub_identifier = ''

# A unique identification for the text.
# epub_uid = ''

# A tuple containing the cover image and cover page html template filenames.
# epub_cover = ()

# A sequence of (type, uri, title) tuples for the guide element of content.opf.
# epub_guide = ()

# HTML files that should be inserted before the pages created by sphinx.
# The format is a list of tuples containing the path and title.
# epub_pre_files = []

# HTML files that should be inserted after the pages created by sphinx.
# The format is a list of tuples containing the path and title.
# epub_post_files = []

# A list of files that should not be packed into the epub file.
# epub_exclude_files = []

# The depth of the table of contents in toc.ncx.
# epub_tocdepth = 3

# Allow duplicate toc entries.
# epub_tocdup = True

# Fix unsupported image types using the PIL.
# epub_fix_images = False

# Scale large images.
# epub_max_image_width = 0

# If 'no', URL addresses will not be shown.
# epub_show_urls = 'inline'

# If false, no index is generated.
# epub_use_index = True


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping: dict[str, tuple[str, None]] = {
    'python': ('https://docs.python.org/3', None)
}

# -- Options for linkcheck ------------------------------------------------

# Without a timeout, one hanging external server blocks its linkcheck
# worker forever and runs the CI docs-linkcheck job into its 10-minute
# kill, where it ends up cancelled instead of failed. A bounded timeout
# turns the hang into an ordinary broken-link failure, which the
# workflow's continue-on-error for experimental envs can absorb.
linkcheck_timeout = 15
linkcheck_retries = 2
# GitHub 429-rate-limits anonymous CI requests to github.com pages (seen
# on this repository's own /commits/develop link), and sphinx's backoff
# sleeps up to linkcheck_rate_limit_timeout per retry -- 300 s by
# default, which single-handedly blows the job's 10-minute budget.
# Links into this repository verify nothing worth that cost.
linkcheck_rate_limit_timeout = 30
linkcheck_ignore = [
    r'https://github\.com/(WoLpH|wolph)/python-progressbar.*',
]