Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Embed hash in setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarbuzzi committed Jun 26, 2024
1 parent 56824a1 commit d732f35
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
7 changes: 0 additions & 7 deletions .github/actions/nm-build-vllm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ runs:
COMMIT=${{ github.sha }}
VENV="${{ inputs.venv }}-${COMMIT:0:7}"
# add git commit hash to `vllm/version.py`
echo "__commit__ = '$COMMIT'" >> vllm/version.py
# update import line in `vllm/__init__.py`
sed -i 's/import __version__/import __commit__, __version__/' vllm/__init__.py
# update "__all__" list in `vllm/__init__.py`
sed -i 's/"__version__",/"__commit__",\n "__version__",/' vllm/__init__.py
source $(pyenv root)/versions/${{ inputs.python }}/envs/${VENV}/bin/activate
pip3 install -r requirements-cuda.txt -r requirements-build.txt
# whl
Expand Down
27 changes: 27 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import subprocess
import sys
import warnings
from shutil import which
from typing import Dict, List

Expand All @@ -27,6 +28,32 @@ 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', '--short', '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("None", 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'))
Expand Down
3 changes: 2 additions & 1 deletion vllm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions vllm/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# UPSTREAM SYNC: take downstream
__version__ = "0.5.1"
__commit__ = None

0 comments on commit d732f35

Please sign in to comment.