[Misc] Add generated git commit hash as vllm.__commit__ (#6386)
This commit is contained in:
24
setup.py
24
setup.py
@@ -5,6 +5,7 @@ import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import warnings
|
||||
from shutil import which
|
||||
from typing import Dict, List
|
||||
|
||||
@@ -26,6 +27,29 @@ def load_module_from_path(module_name, path):
|
||||
ROOT_DIR = os.path.dirname(__file__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def embed_commit_hash():
|
||||
try:
|
||||
commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"],
|
||||
encoding="utf-8").strip()
|
||||
commit_contents = f'__commit__ = "{commit_id}"\n'
|
||||
|
||||
version_file = os.path.join(ROOT_DIR, "vllm", "commit_id.py")
|
||||
with open(version_file, "w", encoding="utf-8") as f:
|
||||
f.write(commit_contents)
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
warnings.warn(f"Failed to get commit hash:\n{e}",
|
||||
RuntimeWarning,
|
||||
stacklevel=2)
|
||||
except Exception as e:
|
||||
warnings.warn(f"Failed to embed commit hash:\n{e}",
|
||||
RuntimeWarning,
|
||||
stacklevel=2)
|
||||
|
||||
|
||||
embed_commit_hash()
|
||||
|
||||
# cannot import envs directly because it depends on vllm,
|
||||
# which is not installed yet
|
||||
envs = load_module_from_path('envs', os.path.join(ROOT_DIR, 'vllm', 'envs.py'))
|
||||
|
||||
Reference in New Issue
Block a user