Skip to content

Commit a053c2c

Browse files
committed
feat(conf.py): Implement dynamic version retrieval for RST substitution
1 parent 1c6bd9e commit a053c2c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/src/conf.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55

66
sys.path.insert(0, os.path.abspath('../..'))
7-
from gtdbtk import __author__, __version__, __title__, __maintainer__, __url__
7+
from gtdbtk import __author__, __title__, __maintainer__, __url__
88

99
# Configuration file for the Sphinx documentation builder.
1010
# https://www.sphinx-doc.org/en/master/usage/configuration.html
@@ -15,15 +15,27 @@
1515
copyright = f'{datetime.now().year}, {__maintainer__}'
1616
author = __author__
1717

18-
# The full version, including alpha/beta/rc tags
19-
release = __version__
20-
version = __version__
21-
2218
# The name of the Pygments (syntax highlighting) style to use.
2319
pygments_style = 'sphinx'
2420

2521
github_url = __url__
2622

23+
def get_version():
24+
with open(os.path.abspath('../../gtdbtk/__init__.py')) as f:
25+
for line in f:
26+
if line.startswith('__version__'):
27+
return re.search(r'["\'](.+?)["\']', line).group(1)
28+
return 'unknown'
29+
30+
release = get_version()
31+
version = '.'.join(release.split('.')[:2])
32+
33+
# Make version info available for substitution in RST files
34+
rst_epilog = f"""
35+
.. |release| replace:: {release}
36+
.. |version| replace:: {version}
37+
"""
38+
2739
# -- General configuration ---------------------------------------------------
2840

2941
# Add any Sphinx extension module names here, as strings. They can be

0 commit comments

Comments
 (0)