diff --git a/api-ref/source/conf.py b/api-ref/source/conf.py index 66a4865e..e4a4ee64 100644 --- a/api-ref/source/conf.py +++ b/api-ref/source/conf.py @@ -71,8 +71,12 @@ release = '1.0' # These variables are passed to the logabug code via html_context. giturl = u'https://git.openstack.org/cgit/openstack/openstackdocstheme/tree/doc/source' git_cmd = ["/usr/bin/git", "rev-parse", "HEAD"] -gitsha = subprocess.Popen( - git_cmd, stdout=subprocess.PIPE).communicate()[0].strip('\n') +# git might not be available during build (eg when building from an sdist) +try: + gitsha = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0].strip('\n') +except Exception: + gitsha = 'unknown' bug_tag = "doc-builds" html_context = {"gitsha": gitsha, "bug_tag": bug_tag, "giturl": giturl} diff --git a/openstackdocstheme/__init__.py b/openstackdocstheme/__init__.py index 08f29f85..16282f77 100644 --- a/openstackdocstheme/__init__.py +++ b/openstackdocstheme/__init__.py @@ -78,9 +78,14 @@ def _html_page_context(app, pagename, templatename, context, doctree): global _html_context_data if _html_context_data is None: _html_context_data = {} - _html_context_data['gitsha'] = subprocess.check_output( - ['git', 'rev-parse', 'HEAD'], - ).decode('utf-8').strip() + try: + _html_context_data['gitsha'] = subprocess.check_output( + ['git', 'rev-parse', 'HEAD'], + ).decode('utf-8').strip() + except Exception: + app.warn('Cannot get gitsha from git repository.') + _html_context_data['gitsha'] = 'unknown' + repo_name = app.config.repository_name if repo_name: _html_context_data['giturl'] = _giturl.format(repo_name)