Skip to content

Commit e7d93ab

Browse files
Copilotjason810496
andauthored
Support versioned documentation with dynamic version reading (#20)
* Initial plan * Add versioned documentation support Co-authored-by: jason810496 <[email protected]> * Add Python 3.9+ compatibility and error handling for version reading Co-authored-by: jason810496 <[email protected]> * Improve exception handling and version parsing robustness Co-authored-by: jason810496 <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jason810496 <[email protected]>
1 parent b82812e commit e7d93ab

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

.readthedocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ sphinx:
3232
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
3333
python:
3434
install:
35-
- requirements: doc/requirements.txt
35+
- requirements: doc/requirements.txt
36+
- method: pip
37+
path: .

doc/conf.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,27 @@
66
import os
77
import sys
88

9+
# Handle Python 3.9+ compatibility for tomllib
10+
try:
11+
import tomllib
12+
except ModuleNotFoundError:
13+
import tomli as tomllib
14+
915
# path setup
1016
sys.path.insert(0, os.path.abspath(".."))
1117
sys.path.insert(0, os.path.abspath("../pgmq_sqlalchemy"))
1218

19+
# Read version from pyproject.toml
20+
_pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml")
21+
try:
22+
with open(_pyproject_path, "rb") as f:
23+
_pyproject_data = tomllib.load(f)
24+
_version = _pyproject_data["project"]["version"]
25+
except (FileNotFoundError, KeyError, OSError) as e:
26+
# Fallback to a default version if pyproject.toml is missing or invalid
27+
print(f"Warning: Could not read version from pyproject.toml: {e}")
28+
_version = "0.0.0"
29+
1330
extensions = [
1431
"sphinx_copybutton",
1532
"sphinx.ext.autodoc",
@@ -22,6 +39,13 @@
2239
project = "pgmq-sqlalchemy"
2340
copyright = f'2024-{time.strftime("%Y")}, the pgmq-sqlalchemy developers'
2441

42+
# Version information
43+
# The short X.Y version
44+
_version_parts = _version.split(".")
45+
version = ".".join(_version_parts[:2]) if len(_version_parts) >= 2 else _version
46+
# The full version, including alpha/beta/rc tags
47+
release = _version
48+
2549
source_suffix = {
2650
".rst": "restructuredtext",
2751
}

doc/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sphinx
22
sphinx-rtd-theme
33
sphinx-copybutton
4-
SQLAlchemy
4+
SQLAlchemy
5+
tomli; python_version < "3.11"

0 commit comments

Comments
 (0)