Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(conf.py): do not include git hash in docs for version-tagged commits #87

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,45 @@
# Get version from camtools package
version = ct.__version__

# Get git commit hash
# When building a version-tagged commit, only use the version as "release". Otherwise,
# use the version number and the git hash as "release".
print("[Detecting docs version]")
try:
git_hash = (
subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
.decode("ascii")
.strip()
)
release = f"{version}+{git_hash}"
all_tags = (
subprocess.check_output(["git", "tag", "--list"])
.decode("ascii")
.strip()
.split()
)
head_tags = (
subprocess.check_output(["git", "tag", "--points-at", "HEAD"])
.decode("ascii")
.strip()
.split()
)

print(f"- Version : {version}")
print(f"- Git hash : {git_hash}")
print(f"- All tags : {all_tags}")
print(f"- HEAD tags : {head_tags}")

# Check if current commit has a version tag
if f"v{version}" in head_tags:
release = version
status = f"(commit {git_hash} is version tagged as v{version})"
else:
release = f"{version}+{git_hash}"
status = f"(commit {git_hash} is not version tagged)"
print(f"- Docs version: {release} {status}")

except subprocess.CalledProcessError:
release = version
print(f"- Docs version : {release} (cannot detect git information)")

project = "CamTools"
copyright = "2024, Yixing Lao"
Expand Down
Loading