From 42615ceedd19218bc85b4f0b16bb348571b3f57f Mon Sep 17 00:00:00 2001 From: Yixing Lao Date: Sat, 11 Jan 2025 20:13:00 +0800 Subject: [PATCH] refactor(docs/conf.py): simplify version and tag detection logic for 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. --- docs/conf.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f1bd4fb..e8bca74 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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)")