Skip to content

Commit

Permalink
refactor(docs/conf.py): simplify version and tag detection logic for …
Browse files Browse the repository at this point in the history
…better readability and maintainability

The changes streamline the version and tag detection logic by removing redundant variables and consolidating the print statements. The logic now directly checks if the current commit has a version tag and constructs the release string accordingly. This improves code clarity and reduces unnecessary complexity.
  • Loading branch information
yxlao committed Jan 11, 2025
1 parent 2d6663e commit 42615ce
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,22 @@
.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 any HEAD tag matches the version pattern
version_tag = f"v{version}"
is_version_tagged = version_tag in head_tags
# Check if current commit has a version tag
is_version_tagged = f"v{version}" in head_tags
release = version if is_version_tagged else f"{version}+{git_hash}"

if not is_version_tagged:
release = f"{version}+{git_hash}"
print(f"- Docs version : {release} (not a version tagged commit)")
if is_version_tagged:
status = f"({git_hash} is version tagged as v{version})"
else:
release = version
print(
f"- Docs version: {release} ({git_hash} is version tagged as {version_tag})"
)
status = "(not a version tagged commit)"
print(f"- Docs version: {release} {status}")

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

0 comments on commit 42615ce

Please sign in to comment.