From 202ca394fba8b3aa01ac0f492f45b3800cf1dcb7 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 15 Dec 2021 13:49:58 -0800 Subject: [PATCH] Switch docs theme to versioned RTD To match change I2870450ffd02f55509fcc1297d050b09deafbfb9 in Zuul. Change-Id: Ic23dcbc743ca1c79bcead8eebd2899c00e0750c6 --- doc/requirements.txt | 2 + doc/source/_static/logo.svg | 100 +++++++++++++++++++++++----- doc/source/_templates/versions.html | 15 +++++ doc/source/conf.py | 93 ++++++++++++++++++++------ tox.ini | 5 +- zuul_sphinx/version.py | 32 +++++++++ 6 files changed, 209 insertions(+), 38 deletions(-) create mode 100644 doc/requirements.txt create mode 100644 doc/source/_templates/versions.html create mode 100644 zuul_sphinx/version.py diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 0000000..4ebc140 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,2 @@ +sphinx_rtd_theme +reno>=2.8.0 # Apache-2.0 diff --git a/doc/source/_static/logo.svg b/doc/source/_static/logo.svg index ded6d34..0cc6b72 100644 --- a/doc/source/_static/logo.svg +++ b/doc/source/_static/logo.svg @@ -1,22 +1,86 @@ - - - -
+ + {{ _('Versions') }} + v: {{ current_version }} + + +
+
+ {% for slug, url in versions %} +
{{ slug }}
+ {% endfor %} +
+
+
diff --git a/doc/source/conf.py b/doc/source/conf.py index 8d4f735..279d6d1 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -12,8 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os -import sys +import sys, os, datetime +import subprocess +import re +from zuul_sphinx import version + +# The minimum version to link to +min_version = (0, 4, 0) sys.path.insert(0, os.path.abspath('../..')) # -- General configuration ---------------------------------------------------- @@ -22,8 +27,9 @@ sys.path.insert(0, os.path.abspath('../..')) # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', - #'sphinx.ext.intersphinx', 'zuul_sphinx', + 'reno.sphinxext', + 'sphinx_rtd_theme', ] # autodoc generation is a bit aggressive and a nuisance when doing heavy @@ -39,8 +45,10 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u'zuul-sphinx' -copyright = u'2017, Zuul contributors' +project = u'Zuul-Sphinx' +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 @@ -56,9 +64,65 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. Major themes that come with # Sphinx are currently 'default' and 'sphinxdoc'. -# html_theme_path = ["."] -# html_theme = '_theme' -# html_static_path = ['static'] +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'] + +# 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 @@ -70,25 +134,16 @@ latex_documents = [ ('index', '%s.tex' % project, u'%s Documentation' % project, - u'OpenStack Foundation', 'manual'), + 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 (relative to this directory) to place at the top -# of the sidebar. -html_logo = '_static/logo.svg' - # 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'] - -# Sample additional role paths +# Additional Zuul role paths zuul_role_paths = ['tests/roles'] diff --git a/tox.ini b/tox.ini index b5d830c..78b05a7 100644 --- a/tox.ini +++ b/tox.ini @@ -20,10 +20,13 @@ deps = bindep commands = bindep test [testenv:docs] +usedevelop = True +deps = + -r{toxinidir}/doc/requirements.txt + -r{toxinidir}/requirements.txt commands = sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html - [testenv:pep8] whitelist_externals = bash commands = diff --git a/zuul_sphinx/version.py b/zuul_sphinx/version.py new file mode 100644 index 0000000..b57c528 --- /dev/null +++ b/zuul_sphinx/version.py @@ -0,0 +1,32 @@ +# Copyright 2020 Red Hat, inc +# +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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 json + +import pbr.version +import pkg_resources + +version_info = pbr.version.VersionInfo('zuul-sphinx') +release_string = version_info.release_string() + +is_release = None +git_version = None +try: + _metadata = json.loads( + pkg_resources.get_distribution('zuul-sphinx').get_metadata('pbr.json')) + if _metadata: + is_release = _metadata['is_release'] + git_version = _metadata['git_version'] +except Exception: + pass