From 91dfc4d5cc16abe6d3b150b739957865e34954a9 Mon Sep 17 00:00:00 2001 From: Thomas Marwitz Date: Fri, 3 Nov 2023 11:51:12 +0100 Subject: [PATCH] Address issue #44: determine version programmatically. The version for the documentation build was hard-coded in . It is now determined programmtically. --- docs/conf.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 10b297b1..4fe82310 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,6 @@ import inspect import os +import re import sys from sphinx.ext import apidoc @@ -13,6 +14,37 @@ os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe())) # type: ignore ) + +def simplify_version(version): + """ + Simplifies the version string to only include the major.minor.patch components. + + Example: + '1.8.2.post0+g476bc9e.d20231103' -> '1.8.2' + """ + match = re.match(r"^(\d+\.\d+\.\d+)(?:\.post\d+)?", version) + return match.group(1) if match else version + + +try: + import minimalkv + + version = simplify_version(minimalkv.__version__) +except ImportError: + import pkg_resources + + version = simplify_version(pkg_resources.get_distribution("minimalkv").version) + +print(f"Building docs for version: {version}") + +# The version info is fetched programmatically. It acts as replacement for +# |version| and |release|, it is also used in various other places throughout +# the built documents. +# +# major.minor.patch + +release = version + # Generate module references output_dir = os.path.abspath(os.path.join(__location__, "../docs/_rst")) module_dir = os.path.abspath(os.path.join(__location__, "..", package)) @@ -37,14 +69,6 @@ project = "minimalkv" copyright = "2011-2021, The minimalkv contributors" -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -version = "0.14.1" -# The full version, including alpha/beta/rc tags. -release = "0.14.1" exclude_trees = ["_build"]