From e824242afe668d223f2a00df645e2720562138ee Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 15 Dec 2021 13:40:36 -0800 Subject: [PATCH] Switch docs theme to versioned RTD To match change I2870450ffd02f55509fcc1297d050b09deafbfb9 in Zuul. Change-Id: I87c9aa56f59b7c4b97f79d63b737607fb3519d41 --- doc/requirements.txt | 1 + doc/source/_static/logo.svg | 86 +++++++++++++++ doc/source/_templates/versions.html | 15 +++ doc/source/conf.py | 162 +++++++++++++++++++++------- tox.ini | 1 + 5 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 doc/source/_static/logo.svg create mode 100644 doc/source/_templates/versions.html diff --git a/doc/requirements.txt b/doc/requirements.txt index 75f8a14..36adfde 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -3,3 +3,4 @@ sphinxcontrib-programoutput sphinx-autodoc-typehints reno>=2.8.0 # Apache-2.0 zuul-sphinx +sphinx_rtd_theme diff --git a/doc/source/_static/logo.svg b/doc/source/_static/logo.svg new file mode 100644 index 0000000..0cc6b72 --- /dev/null +++ b/doc/source/_static/logo.svg @@ -0,0 +1,86 @@ + +image/svg+xml + + + + + + + + + + + diff --git a/doc/source/_templates/versions.html b/doc/source/_templates/versions.html new file mode 100644 index 0000000..1318534 --- /dev/null +++ b/doc/source/_templates/versions.html @@ -0,0 +1,15 @@ +{# Based on versions.html from sphinx_rtd_theme, Licensed under ASL2 #} +
+ + {{ _('Versions') }} + v: {{ current_version }} + + +
+
+ {% for slug, url in versions %} +
{{ slug }}
+ {% endfor %} +
+
+
diff --git a/doc/source/conf.py b/doc/source/conf.py index bf1738b..67d5aa7 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,60 +1,150 @@ -# Configuration file for the Sphinx documentation builder. +# -*- coding: utf-8 -*- +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# 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. +# http://www.apache.org/licenses/LICENSE-2.0 # -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys, os, datetime +import subprocess +import re +from zuulclient import version -# -- Project information ----------------------------------------------------- +# The minimum version to link to +min_version = (0, 0, 0) -project = 'Zuul-client' -copyright = '2020, OpenStack' -author = 'OpenStack' - - -# -- General configuration --------------------------------------------------- +sys.path.insert(0, os.path.abspath('../..')) +# -- General configuration ---------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', - 'sphinx_autodoc_typehints', 'sphinxcontrib.programoutput', 'zuul_sphinx', - # 'zuul.sphinx.zuul', 'reno.sphinxext', + 'sphinx_rtd_theme', ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +# autodoc generation is a bit aggressive and a nuisance when doing heavy +# text edit cycles. +# execute "export SPHINX_DEBUG=1" in your terminal to disable -# 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'] +primary_domain = 'zuul' + +# The suffix of source filenames. +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Zuul-Client' +copyright = u'2012-%s, Zuul project contributors' % datetime.date.today().year + +doc_root = os.environ.get('ZUUL_DOC_ROOT', '/docs/%s' % (project.lower())) + +# 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 # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' -# -- Options for HTML output ------------------------------------------------- +# -- 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 = 'alabaster' +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +html_theme = "sphinx_rtd_theme" + +if version.is_release: + version = version.release_string + current_version = version.release_string + versions = [('latest', f'{doc_root}/')] +else: + # Uncomment this if we want to use the in-development version + # number (eg 4.10.5.dev4 887cf31e4 ) + # version = version.get_version_string() + version = 'latest' + current_version = 'latest' + versions = [('latest', f'{doc_root}/')] + +try: + output = subprocess.check_output(['git', 'tag']).decode('utf8') +except subprocess.CalledProcessError: + output = '' + +interesting_tags = [] +for tag in output.splitlines(): + if re.match('^\d+\.\d+\.\d+$', tag): + parts = tuple(map(int, tag.split('.'))) + if parts < min_version: + continue + interesting_tags.append((parts, tag)) +for parts, tag in reversed(sorted(interesting_tags, key=lambda x: x[0])): + versions.append((tag, f'{doc_root}/{tag}/')) + +# 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 = { + 'collapse_navigation': False, + 'navigation_depth': -1, + 'logo_only': True, +} + +html_context = { + # This controls what is displayed at the top of the navbar. + 'version': version, + # This controls what the caret selection displays at the bottom of + # the navbar. + 'current_version': current_version, + # A tuple of (slug, url) + 'versions': versions, +} # 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'] +html_static_path = ['_static'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +html_logo = '_static/logo.svg' + +# Output file base name for HTML help builder. +htmlhelp_basename = '%sdoc' % project + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', + '%s.tex' % project, + u'%s Documentation' % project, + u'Zuul contributors', 'manual'), +] + +# Example configuration for intersphinx: refer to the Python standard library. +#intersphinx_mapping = {'http://docs.python.org/': 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 + +# Additional Zuul role paths +zuul_role_paths = [] diff --git a/tox.ini b/tox.ini index 53741c4..6b129f7 100644 --- a/tox.ini +++ b/tox.ini @@ -56,6 +56,7 @@ commands = coverage xml -o cover/coverage.xml [testenv:docs] +usedevelop = True install_command = pip install {opts} {packages} deps = -r{toxinidir}/doc/requirements.txt