Skip to content

Commit d8d36a4

Browse files
committed
conf.py: set the version for sphinx, based on the current git tag
1 parent 19af89c commit d8d36a4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

conf.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import json
2121
import logging
2222
import os
23+
import re
2324
import subprocess
2425
import sys
2526
import urllib.parse
@@ -106,7 +107,25 @@
106107
#
107108
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
108109
# breakdown, so use the same version identifier for both to avoid confusion.
109-
version = release = '0.0.0'
110+
111+
final_version = ""
112+
git_describe = subprocess.run(
113+
["git", "describe", "--dirty", "--tags"],
114+
stdout=subprocess.PIPE,
115+
stderr=subprocess.STDOUT,
116+
encoding="utf-8"
117+
)
118+
if git_describe.returncode == 0:
119+
git_version = re.search(
120+
r"^\d(?:\.\d){0,2}(?:\-(?:alpha|beta)\.\d+){0,1}",
121+
str(git_describe.stdout)
122+
)
123+
if git_version:
124+
final_version = git_version[0]
125+
else:
126+
print("Failed to retrieve git version:", git_describe.stdout)
127+
128+
version = release = final_version
110129

111130
# The language for content autogenerated by Sphinx. Refer to documentation
112131
# for a list of supported languages.

0 commit comments

Comments
 (0)