Skip to content

Commit

Permalink
Extract document version from git tag
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
glikely committed Dec 7, 2017
1 parent 13c1146 commit 6a00ff2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import os
import time
import subprocess

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

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

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

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

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

0 comments on commit 6a00ff2

Please sign in to comment.