From 3f58e0c32743e2b7d7c543fcd026e4b421b52023 Mon Sep 17 00:00:00 2001 From: liusheng Date: Wed, 13 Apr 2016 16:31:05 +0800 Subject: [PATCH] Fix doc build if git is absent When building packages if git is absent, then we should not set html_last_updated_fmt. It can still be set via the -D switch when building with sphinx-build. Change-Id: If6abe66590637d963e146c5abc4a986ad010d57e Closes-Bug: #1552251 --- doc/source/conf.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index ada468d76..353c11469 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -14,6 +14,7 @@ import sys import os import subprocess +import warnings BASE_DIR = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.abspath(os.path.join(BASE_DIR, "..", "..")) @@ -154,8 +155,12 @@ html_theme_options = { #html_last_updated_fmt = '%b %d, %Y' git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local", "-n1"] -html_last_updated_fmt = subprocess.Popen(git_cmd, - stdout=subprocess.PIPE).communicate()[0] +try: + html_last_updated_fmt = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0] +except Exception: + warnings.warn('Cannot get last updated time from git repository. ' + 'Not setting "html_last_updated_fmt".') # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities.