diff --git a/setup.py b/setup.py index 50f6f39cca488..ae1997a37319d 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ import re import subprocess import sys +import warnings from shutil import which from typing import Dict, List @@ -27,6 +28,33 @@ 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() + + version_file = os.path.join(ROOT_DIR, "vllm", "version.py") + with open(version_file, encoding="utf-8") as f: + version_contents = f.read() + + version_contents = version_contents.replace("COMMIT_HASH_PLACEHOLDER", + f"{commit_id}") + + with open(version_file, "w", encoding="utf-8") as f: + f.write(version_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')) diff --git a/tests/test_embedded_commit.py b/tests/test_embedded_commit.py new file mode 100644 index 0000000000000..529aeea77e74c --- /dev/null +++ b/tests/test_embedded_commit.py @@ -0,0 +1,5 @@ +import vllm + + +def test_embedded_commit_defined(): + assert len(vllm.__commit__) > 7 diff --git a/vllm/__init__.py b/vllm/__init__.py index e217059873bf5..318f078fdbee7 100644 --- a/vllm/__init__.py +++ b/vllm/__init__.py @@ -12,9 +12,10 @@ from vllm.pooling_params import PoolingParams from vllm.sampling_params import SamplingParams -from .version import __version__ +from .version import __commit__, __version__ __all__ = [ + "__commit__", "__version__", "LLM", "ModelRegistry", diff --git a/vllm/version.py b/vllm/version.py index 368411c8059c8..c6b85b483734b 100644 --- a/vllm/version.py +++ b/vllm/version.py @@ -1,2 +1,3 @@ # UPSTREAM SYNC: take downstream __version__ = "0.5.1" +__commit__ = "COMMIT_HASH_PLACEHOLDER"