Skip to content

Commit 6a00ff2

Browse files
committed
Extract document version from git tag
Instead of hard coding the document version in the config file, use 'git describe' to get the version number from the tags and use that. Just like before, if the version string contains a '-', then it is not an official release and a watermark will be added to the PDF. This catches prereleases "-pre*", untagged revisions "-g<hash>", and uncommitted changes "-dirty". Signed-off-by: Grant Likely <[email protected]> Reviewed-by: Rob Herring <[email protected]>
1 parent 13c1146 commit 6a00ff2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

source/conf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import os
1717
import time
18+
import subprocess
1819

1920
# If extensions (or modules to document with autodoc) are in another directory,
2021
# add these directories to sys.path here. If the directory is relative to the
@@ -64,7 +65,10 @@ def setup(app):
6465
# built documents.
6566
#
6667
# The short X.Y version.
67-
version = u'0.2-pre2'
68+
try:
69+
version = subprocess.check_output(["git", "describe", "--dirty"]).strip()
70+
except:
71+
version = "unknown-rev"
6872
# The full version, including alpha/beta/rc tags.
6973
release = version
7074

@@ -79,7 +83,7 @@ def setup(app):
7983
# non-false value, then it is used:
8084
#today = ''
8185
# Else, today_fmt is used as the format for a strftime call.
82-
today_fmt = '%d %B %Y'
86+
today_fmt = '%d %b %Y'
8387

8488
# List of patterns, relative to source directory, that match files and
8589
# directories to ignore when looking for source files.
@@ -253,7 +257,7 @@ def setup(app):
253257

254258
# Release numbers with a qualifier (ex. '-rc', '-pre') get a watermark.
255259
if '-' in release:
256-
latex_elements['preamble'] = '\\usepackage{draftwatermark}\\SetWatermarkScale{.45}\\SetWatermarkText{DRAFT v%s %s}' % (release, time.strftime(today_fmt))
260+
latex_elements['preamble'] = '\\usepackage{draftwatermark}\\SetWatermarkScale{.45}\\SetWatermarkText{%s}' % (release)
257261

258262
# Grouping the document tree into LaTeX files. List of tuples
259263
# (source start file, target name, title,

0 commit comments

Comments
 (0)