diff --git a/doc/source/conf.py b/doc/source/conf.py index 9487fcc2..91a51623 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -69,9 +69,18 @@ copyright = u'2015-2017, OpenStack Contributors' # "version" and "release" are used by the "log-a-bug" feature # # The short X.Y version. -version = '1.0' +#version = '1.0' # The full version, including alpha/beta/rc tags. -release = '1.0' +#release = '1.0' +# 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. +# +from openstackdocstheme.version import version_info +# The full version, including alpha/beta/rc tags. +release = version_info.release_string() +# The short X.Y version. +version = version_info.version_string() # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -128,6 +137,7 @@ html_theme = 'openstackdocs' # Otherwise, the list of links for the User and Ops docs # appear in the sidebar dropdown menu. #html_theme_options = {"sidebar_dropdown": "api_ref"} +html_theme_options = {'show_other_versions': True} # Add any paths that contain custom themes here, relative to this directory. # html_theme_path = [] diff --git a/openstackdocstheme/__init__.py b/openstackdocstheme/__init__.py index 176219f3..08f29f85 100644 --- a/openstackdocstheme/__init__.py +++ b/openstackdocstheme/__init__.py @@ -13,12 +13,41 @@ # under the License. import os +import string import subprocess _giturl = 'https://git.openstack.org/cgit/{}/tree/doc/source' _html_context_data = None +def _get_other_versions(app): + if not app.config.html_theme_options.get('show_other_versions', False): + return [] + + git_cmd = ["git", "tag", "--merged"] + try: + raw_version_list = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0] + raw_version_list = raw_version_list.decode("utf-8") + except UnicodeDecodeError: + app.warn('Cannot decode the list based on utf-8 encoding. ' + 'Not setting "other_versions".') + raw_version_list = u'' + except OSError: + app.warn('Cannot get tags from git repository, or no merged tags. ' + 'Not setting "other_versions".') + raw_version_list = u'' + + # grab last five that start with a number and reverse the order + _tags = [t.strip("'") for t in raw_version_list.split('\n')] + other_versions = [ + t for t in _tags if t and t[0] in string.digits + # Don't show alpha, beta or release candidate tags + and 'rc' not in t and 'a' not in t and 'b' not in t + ][:-5:-1] + return other_versions + + def builder_inited(app): theme_dir = os.path.join(os.path.dirname(__file__), 'theme') app.info('Using openstackdocstheme Sphinx theme from %s' % theme_dir) @@ -65,6 +94,7 @@ def _html_page_context(app, pagename, templatename, context, doctree): _html_context_data['bug_tag'] = bug_tag context.update(_html_context_data) + context['other_versions'] = _get_other_versions(app) def setup(app): diff --git a/openstackdocstheme/theme/openstackdocs/layout.html b/openstackdocstheme/theme/openstackdocs/layout.html index cf0b090f..e7177e6b 100644 --- a/openstackdocstheme/theme/openstackdocs/layout.html +++ b/openstackdocstheme/theme/openstackdocs/layout.html @@ -38,6 +38,19 @@ ga('send', 'pageview'); {% include 'titlerow.html' %}