Skip to content

Commit 22d9764

Browse files
committed
docs(conf.py): improve version detection logic for documentation builds by checking if the current commit is version-tagged and printing detailed version information for debugging
1 parent 5ffea7a commit 22d9764

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

docs/conf.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,45 @@
1818
# Get version from camtools package
1919
version = ct.__version__
2020

21-
# Get git commit hash
21+
# When building a version-tagged commit, only use the version as "release". Otherwise,
22+
# use the version number and the git hash as "release".
23+
print("[Detecting docs version]")
2224
try:
2325
git_hash = (
2426
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
2527
.decode("ascii")
2628
.strip()
2729
)
28-
release = f"{version}+{git_hash}"
30+
all_tags = (
31+
subprocess.check_output(["git", "tag", "--list"])
32+
.decode("ascii")
33+
.strip()
34+
.split()
35+
)
36+
head_tags = (
37+
subprocess.check_output(["git", "tag", "--points-at", "HEAD"])
38+
.decode("ascii")
39+
.strip()
40+
.split()
41+
)
42+
43+
print(f"- Version : {version}")
44+
print(f"- Git hash : {git_hash}")
45+
print(f"- All tags : {all_tags}")
46+
print(f"- HEAD tags : {head_tags}")
47+
48+
# Check if current commit has a version tag
49+
if f"v{version}" in head_tags:
50+
release = version
51+
status = f"({git_hash} is version tagged as v{version})"
52+
else:
53+
release = f"{version}+{git_hash}"
54+
status = "(not a version tagged commit)"
55+
print(f"- Docs version: {release} {status}")
56+
2957
except subprocess.CalledProcessError:
3058
release = version
59+
print(f"- Docs version : {release} (cannot detect git information)")
3160

3261
project = "CamTools"
3362
copyright = "2024, Yixing Lao"

0 commit comments

Comments
 (0)