Skip to content

Commit 56cee1d

Browse files
docs: improt version form toml
1 parent c20dd11 commit 56cee1d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

docs/conf.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import os
22
import sys
3+
from pathlib import Path
4+
5+
try:
6+
import tomllib # Python 3.11+
7+
except ImportError:
8+
import tomli as tomllib # pip install tomli for older Pythons
39

410
# -- Path setup --------------------------------------------------------------
511
# Ensure the project package is importable for autodoc (assumes src layout)
@@ -8,8 +14,19 @@
814
# -- Project information -----------------------------------------------------
915
project = "python-project-template-AS"
1016
author = "Andrea Scaglioni"
11-
# Keep in sync with pyproject.toml
12-
release = "0.1.0"
17+
18+
# Read project version from pyproject.toml
19+
pyproject_path = Path(__file__).resolve().parents[1] / "pyproject.toml"
20+
release = "0.0.0"
21+
if pyproject_path.exists():
22+
with pyproject_path.open("rb") as f:
23+
data = tomllib.load(f)
24+
# PEP 621
25+
release = (
26+
data.get("project", {}).get("version")
27+
or data.get("tool", {}).get("poetry", {}).get("version")
28+
or release
29+
)
1330

1431
# -- General configuration ---------------------------------------------------
1532
extensions = [

0 commit comments

Comments
 (0)