Skip to content

Commit ed1b96d

Browse files
authored
[Version] Keep local commit id as it somehow help with debugging (#697)
* [Enhancement] Disable cache and append git commit ID to version in tilelang (#688) * Disabled caching in quickstart example for improved performance. * Added a function to retrieve the current git commit ID and appended it to the version string if not already present, enhancing version tracking and debugging capabilities. * revert quickstart
1 parent 17fafc1 commit ed1b96d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tilelang/version.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,24 @@
2424
with open(version_file_path, "r") as version_file:
2525
__version__ = version_file.read().strip()
2626

27+
28+
def get_git_commit_id() -> Union[str, None]:
29+
"""Get the current git commit hash by running git in the current file's directory."""
30+
try:
31+
return subprocess.check_output(['git', 'rev-parse', 'HEAD'],
32+
cwd=os.path.dirname(os.path.abspath(__file__)),
33+
stderr=subprocess.DEVNULL,
34+
encoding='utf-8').strip()
35+
except subprocess.SubprocessError:
36+
return None
37+
38+
39+
# Append git commit hash to version if not already present
40+
# NOTE(lei): Although the local commit id cannot capture locally staged changes,
41+
# the local commit id can help mitigate issues caused by incorrect cache to some extent,
42+
# so it should still be kept.
43+
if "+" not in __version__ and (commit_id := get_git_commit_id()):
44+
__version__ = f"{__version__}+{commit_id}"
45+
2746
# Define the public API for the module
2847
__all__ = ["__version__"]

0 commit comments

Comments
 (0)