From f94dc206ded7c9e8cbf960de301a08d11ccd4894 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdelin Date: Wed, 12 May 2021 11:10:42 +0200 Subject: [PATCH] doc: fix an error if the doc is not generated from github The commit 57c45c04 expect Sphinx to find the environment variable RELEASE_TAG. It seems it's only the case when the documentation is generated from github using the workflow defined in the release.yml file. This commit allows to generate the doc from outside github, by setting version to the current commit id if we are on a git repository, and "n/a" otherwise. --- doc/sphinx/conf.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/sphinx/conf.py b/doc/sphinx/conf.py index 5688a5d52..3f90e3450 100644 --- a/doc/sphinx/conf.py +++ b/doc/sphinx/conf.py @@ -13,6 +13,7 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # import os +import subprocess # import sys # sys.path.insert(0, os.path.abspath('.')) @@ -24,7 +25,16 @@ author = 'SiFive Inc.' # The short X.Y version -version = os.environ['RELEASE_TAG'] +# if github provides us a ref or tag +if 'RELEASE_TAG' in os.environ: + version = os.environ['RELEASE_TAG'] +# if we are in a git repository +elif subprocess.call(["git", "branch"], stderr=subprocess.STDOUT, stdout=open(os.devnull, 'w')) == 0: + # set version to the current commit id + version = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip().decode('ascii') +else: + version = "n/a" + # The full version, including alpha/beta/rc tags release = version