diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9f7ec6e..581a048 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,7 @@ Major changes Minor changes ............. +- Read version from :file:`pyproject.toml` for documentation. [:issue:`103` by @0jc1 and @stevepiercy] - Fix author email format. [:issue:`99` by @gboutry and @stevepiercy] - Drop deprecated license classifier. [:issue:`101` by @gboutry] - Use ``--allow-existing`` argument in the ``dev`` make target to avoid recreating a virtual environment with uv. [:pull:`123` by @stevepiercy] diff --git a/docs/conf.py b/docs/conf.py index 946da0d..ab4fd1b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -42,6 +42,22 @@ ) sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) + +def get_version_from_toml() -> str: + """ + Returns the version from the :file:`pyproject.toml` file. + Supports :pep:`621` formats. Works with Python 3.10+. + """ + path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml") + if sys.version_info >= (3, 11): + import tomllib + else: + import tomli as tomllib + + with open(path, "rb") as f: + data = tomllib.load(f) + return str(data.get("project", {}).get("version")) + # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -75,10 +91,8 @@ # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = '1.8' # The full version, including alpha/beta/rc tags. -release = '1.8.1' +version = release = get_version_from_toml() # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pyproject.toml b/pyproject.toml index a7ae0eb..782a46f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,7 @@ dev = [ "flask>=3.1.2", "pytest>=9.0.2", "sphinx-autobuild>=2024.10.3", + "tomli>=2.0; python_version < '3.11'", "tornado>=6.5.4", ] diff --git a/uv.lock b/uv.lock index f26cfdf..cb172bc 100644 --- a/uv.lock +++ b/uv.lock @@ -629,6 +629,7 @@ dev = [ { name = "pytest" }, { name = "sphinx-autobuild", version = "2024.10.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, { name = "sphinx-autobuild", version = "2025.8.25", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11'" }, + { name = "tomli", marker = "python_full_version < '3.11'" }, { name = "tornado" }, ] @@ -641,6 +642,7 @@ dev = [ { name = "flask", specifier = ">=3.1.2" }, { name = "pytest", specifier = ">=9.0.2" }, { name = "sphinx-autobuild", specifier = ">=2024.10.3" }, + { name = "tomli", marker = "python_full_version < '3.11'", specifier = ">=2.0" }, { name = "tornado", specifier = ">=6.5.4" }, ]