Skip to content

Commit e269af2

Browse files
committed
fix: retrive version from release dynamically in conf.py
1 parent 5359054 commit e269af2

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

doc/source/conf.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818
from importlib.metadata import version
1919
from pathlib import Path
20+
import requests
2021

2122
# If extensions (or modules to document with autodoc) are in another directory,
2223
# add these directories to sys.path here. If the directory is relative to the
@@ -68,11 +69,29 @@
6869
# |version| and |release|, also used in various other places throughout the
6970
# built documents.
7071

72+
def _get_latest_release_from_github(org: str, repo_name: str) -> str:
73+
"""Get the highest version release (including prereleases) from GitHub
74+
repository."""
75+
url = f"https://api.github.com/repos/{org}/{repo_name}/releases"
76+
response = requests.get(url)
77+
releases = response.json()
78+
valid_releases = [release for release in releases if "tag_name" in release]
79+
if not valid_releases:
80+
return "No valid releases found"
81+
latest_version_release = valid_releases[0]["tag_name"]
82+
return latest_version_release
83+
84+
85+
# Get the latest release version from GitHub repository
86+
org = "diffpy"
87+
repo_name = "diffpy.utils"
88+
latest_verion_from_github = _get_latest_release_from_github(org, repo_name)
89+
7190
fullversion = version(project)
7291
# The short X.Y version.
7392
version = "".join(fullversion.split(".post")[:1])
7493
# The full version, including alpha/beta/rc tags.
75-
release = fullversion
94+
release = latest_verion_from_github
7695

7796
# The language for content autogenerated by Sphinx. Refer to documentation
7897
# for a list of supported languages.

news/version-release.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Method to retrieve the latest package version from GitHub's release page in the official documentation. The latest release on GitHub is used to retrieve the latest version of the package instead of a tag.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

0 commit comments

Comments
 (0)