Skip to content

Commit

Permalink
Address issue data-engineering-collective#44: determine version progr…
Browse files Browse the repository at this point in the history
…ammatically.

The version for the documentation build was hard-coded in .
It is now determined programmtically.
  • Loading branch information
ThomasMarwitzQC committed Nov 3, 2023
1 parent 476bc9e commit 91dfc4d
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import os
import re
import sys

from sphinx.ext import apidoc
Expand All @@ -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))
Expand All @@ -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"]

Expand Down

0 comments on commit 91dfc4d

Please sign in to comment.