Skip to content

Commit f2ab7b2

Browse files
committed
chore(documentation): read version automatically from __init__.py
1 parent f237a7d commit f2ab7b2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

documentation/conf.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@
1212
# serve to show the default.
1313

1414
import sys, os
15+
import pathlib
16+
import re
1517

1618
# If extensions (or modules to document with autodoc) are in another directory,
1719
# add these directories to sys.path here. If the directory is relative to the
1820
# documentation root, use os.path.abspath to make it absolute, like shown here.
1921
#sys.path.append(os.path.abspath('.'))
2022

23+
def find_version(path: pathlib.Path):
24+
"""
25+
Search the file for a version string.
26+
27+
file_path contain string path components.
28+
29+
Reads the supplied Python module as text without importing it.
30+
"""
31+
version_file = path.read_text()
32+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
33+
version_file, re.M)
34+
if version_match:
35+
return version_match.group(1)
36+
raise RuntimeError("Unable to find version string.")
37+
38+
2139
# -- General configuration -----------------------------------------------------
2240

2341
# Add any Sphinx extension module names here, as strings. They can be extensions
@@ -48,9 +66,9 @@
4866
# built documents.
4967
#
5068
# The short X.Y version.
51-
version = '0.5'
69+
version = find_version(pathlib.Path(__file__).parent.parent / 'serial_asyncio' / '__init__.py')
5270
# The full version, including alpha/beta/rc tags.
53-
release = '0.5'
71+
release = version
5472

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

0 commit comments

Comments
 (0)