Only get git timestamp for generated files

openstackdocstheme now gets the last modified timestamp for files by
default. This makes most of our sphinx extension for this redundant. We
do have a few generated files that we perform special handling that
openstackdocstheme does not know about, so this updates our extension to
optimize for only checking the files that will not be covered by the
theme.

This also adds a bindep file to fix a doc build issue with a font
missing. Gate jobs used to use a common bindep-failback.txt file if
there wasn't a local one present. That mechanism was recently removed,
and it appears now the docs build will not pass unless a needed fonts
package is installed that is not there by default.

Change-Id: I454f4d92e397d6410cb869498f348b86ae26ca0a
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
changes/64/667664/3
Sean McGinnis 3 years ago
parent f39811d136
commit f91f1d9270
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
  1. 5
      bindep.txt
  2. 54
      doc/source/_exts/page_context.py
  3. 2
      openstack_governance/members.py

@ -0,0 +1,5 @@
# This is a cross-platform list tracking distribution packages needed for
# install and tests;
# see https://docs.openstack.org/infra/bindep/ for additional information.
fonts-dejavu-core [platform:dpkg]

@ -18,7 +18,8 @@ from sphinx.util import logging
LOG = logging.getLogger('page_context')
_default_last_updated = datetime.datetime.now()
_projects_last_updated = datetime.datetime.now()
_projects_last_updated_set = False
def _get_last_updated_file(src_file):
@ -47,45 +48,24 @@ def _get_last_updated_file(src_file):
return None
def _get_last_updated(app, pagename):
last_updated = None
full_src_file = app.builder.env.doc2path(pagename)
candidates = []
# Strip the prefix from the filename so the git command recognizes
# the file as part of the current repository.
src_file = full_src_file[len(app.builder.env.srcdir):].lstrip('/')
candidates.append(src_file)
if not os.path.exists(src_file):
# Some of the files are in doc/source and some are not. Some
# of the ones that are not are symlinked. If we can't find the
# file after stripping the full prefix, try looking for it in
# doc/source explicitly.
candidates.append(os.path.join('doc/source', src_file))
if pagename.startswith('reference/projects/'):
# If the file is in the reference/projects directory, it may
# be an auto-generated project page. In that case, use the
# YAML file as the source of the last_updated timestamp.
candidates.append('reference/projects.yaml')
for filename in candidates:
last_updated = _get_last_updated_file(filename)
if last_updated:
LOG.info('[governance] Last updated for %s is %s',
pagename, last_updated)
return last_updated
LOG.info('[governance] could not determine last_updated for %r',
pagename)
return _default_last_updated
def html_page_context(app, pagename, templatename, context, doctree):
# Use the last modified date from git instead of applying a single
# value to the entire site.
context['last_updated'] = _get_last_updated(app, pagename)
global _projects_last_updated
global _projects_last_updated_set
# Note: openstackdocstheme now handles this, so we only need to do our own
# evaluation for generated reference pages.
if pagename.startswith('reference/projects/'):
if not _projects_last_updated_set:
last_updated = _get_last_updated_file('reference/projects.yaml')
if last_updated:
LOG.info('[governance] Last updated for reference/'
'projects.yaml is %s', last_updated)
_projects_last_updated = last_updated
_projects_last_updated_set = True
context['last_updated'] = _projects_last_updated
def setup(app):

@ -17,4 +17,4 @@ def parse_members_file(filename):
"""Load the members file and return each row as a dictionary.
"""
with open(filename, 'r') as f:
return yaml.load(f)
return yaml.safe_load(f)

Loading…
Cancel
Save