# -*- coding: utf-8 -*-
#
# Cilium documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 12 18:34:43 2017.
#
# 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.

# 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
import re
import subprocess
import semver

sys.path.insert(0, os.path.abspath('_exts'))
import cilium_spellfilters


# -- 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.
html_logo = "images/logo.svg"
extensions = ['sphinx.ext.ifconfig',
              'sphinx.ext.githubpages',
              'sphinx.ext.extlinks',
              'sphinxcontrib.openapi',
              'sphinx_tabs.tabs',
              'sphinxcontrib.spelling',
              'versionwarning.extension']

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

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

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'Cilium'
copyright = u'2017-2021, Cilium Authors'
author = u'Cilium Authors'

# 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.
release = open("../VERSION", "r").read().strip()
# Used by version warning
versionwarning_body_selector = "div.document"

# The version of Go used to compile Cilium
go_release = open("../GO_VERSION", "r").read().strip()

# The image tag for Cilium docker images
image_tag = 'v' + release

# Fetch the docs version from an environment variable.
# Map latest -> master.
# Map stable -> current version number.
branch = os.environ.get('READTHEDOCS_VERSION')
if not branch or branch == 'latest':
    branch = 'HEAD'
    archive_name = 'master'
    chart_release = './cilium'
    image_tag = 'latest'
elif branch == 'stable':
    branch = release
    archive_name = release
    chart_release = 'cilium/cilium --version ' + release
    tags.add('stable')
else:
    archive_name = branch
    chart_release = 'cilium/cilium --version ' + release
    tags.add('stable')
relinfo = semver.parse_version_info(release)
current_release = '%d.%d' % (relinfo.major, relinfo.minor)
if relinfo.patch == 90:
    next_release = '%d.%d' % (relinfo.major, relinfo.minor + 1)
else:
    next_release = current_release
githubusercontent = 'https://raw.githubusercontent.com/cilium/cilium/'
scm_web = githubusercontent + branch
jenkins_branch = 'https://jenkins.cilium.io/view/Cilium-v' + current_release
github_repo = 'https://github.com/cilium/cilium/'
archive_filename = archive_name + '.tar.gz'
archive_link = github_repo + 'archive/' + archive_filename
archive_name = 'cilium-' + archive_name.strip('v')
project_link = github_repo + 'projects?query=is:open+' + next_release
backport_format = github_repo + 'pulls?q=is:open+is:pr+label:%s/' + current_release

# Store variables in the epilogue so they are globally available.
rst_epilog = """
.. |SCM_WEB| replace:: \{s}
.. |SCM_BRANCH| replace:: \{b}
.. |SCM_ARCHIVE_NAME| replace:: \{a}
.. |SCM_ARCHIVE_FILENAME| replace:: \{f}
.. |SCM_ARCHIVE_LINK| replace:: \{l}
.. |CURRENT_RELEASE| replace:: \{c}
.. |NEXT_RELEASE| replace:: \{n}