Skip to content

Commit 111fc6e

Browse files
authored
[Misc] Add generated git commit hash as vllm.__commit__ (#6386)
1 parent 75f64d8 commit 111fc6e

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# vllm commit id, generated by setup.py
2+
vllm/commit_id.py
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

setup.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import subprocess
77
import sys
8+
import warnings
89
from shutil import which
910
from typing import Dict, List
1011

@@ -26,6 +27,29 @@ def load_module_from_path(module_name, path):
2627
ROOT_DIR = os.path.dirname(__file__)
2728
logger = logging.getLogger(__name__)
2829

30+
31+
def embed_commit_hash():
32+
try:
33+
commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"],
34+
encoding="utf-8").strip()
35+
commit_contents = f'__commit__ = "{commit_id}"\n'
36+
37+
version_file = os.path.join(ROOT_DIR, "vllm", "commit_id.py")
38+
with open(version_file, "w", encoding="utf-8") as f:
39+
f.write(commit_contents)
40+
41+
except subprocess.CalledProcessError as e:
42+
warnings.warn(f"Failed to get commit hash:\n{e}",
43+
RuntimeWarning,
44+
stacklevel=2)
45+
except Exception as e:
46+
warnings.warn(f"Failed to embed commit hash:\n{e}",
47+
RuntimeWarning,
48+
stacklevel=2)
49+
50+
51+
embed_commit_hash()
52+
2953
# cannot import envs directly because it depends on vllm,
3054
# which is not installed yet
3155
envs = load_module_from_path('envs', os.path.join(ROOT_DIR, 'vllm', 'envs.py'))

tests/test_embedded_commit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import vllm
2+
3+
4+
def test_embedded_commit_defined():
5+
assert vllm.__commit__ != "COMMIT_HASH_PLACEHOLDER"
6+
# 7 characters is the length of a short commit hash
7+
assert len(vllm.__commit__) >= 7

vllm/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
from vllm.pooling_params import PoolingParams
1313
from vllm.sampling_params import SamplingParams
1414

15-
from .version import __version__
15+
from .version import __commit__, __version__
1616

1717
__all__ = [
18+
"__commit__",
1819
"__version__",
1920
"LLM",
2021
"ModelRegistry",

vllm/version.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
import warnings
2+
3+
try:
4+
import vllm.commit_id
5+
__commit__ = vllm.commit_id.__commit__
6+
except Exception as e:
7+
warnings.warn(f"Failed to read commit hash:\n{e}",
8+
RuntimeWarning,
9+
stacklevel=2)
10+
__commit__ = "COMMIT_HASH_PLACEHOLDER"
11+
112
__version__ = "0.5.1"

0 commit comments

Comments
 (0)