5
5
import re
6
6
import subprocess
7
7
import sys
8
- import warnings
9
8
from pathlib import Path
10
9
from shutil import which
11
10
from typing import Dict , List
14
13
from packaging .version import Version , parse
15
14
from setuptools import Extension , find_packages , setup
16
15
from setuptools .command .build_ext import build_ext
16
+ from setuptools_scm import get_version
17
17
from torch .utils .cpp_extension import CUDA_HOME
18
18
19
19
@@ -28,34 +28,6 @@ def load_module_from_path(module_name, path):
28
28
ROOT_DIR = os .path .dirname (__file__ )
29
29
logger = logging .getLogger (__name__ )
30
30
31
-
32
- def embed_commit_hash ():
33
- try :
34
- if "BUILDKITE_COMMIT" in os .environ :
35
- # ci build
36
- commit_id = os .environ ["BUILDKITE_COMMIT" ]
37
- else :
38
- commit_id = subprocess .check_output (["git" , "rev-parse" , "HEAD" ],
39
- encoding = "utf-8" ).strip ()
40
-
41
- commit_contents = f'__commit__ = "{ commit_id } "\n '
42
-
43
- version_file = os .path .join (ROOT_DIR , "vllm" , "commit_id.py" )
44
- with open (version_file , "w" , encoding = "utf-8" ) as f :
45
- f .write (commit_contents )
46
-
47
- except subprocess .CalledProcessError as e :
48
- warnings .warn (f"Failed to get commit hash:\n { e } " ,
49
- RuntimeWarning ,
50
- stacklevel = 2 )
51
- except Exception as e :
52
- warnings .warn (f"Failed to embed commit hash:\n { e } " ,
53
- RuntimeWarning ,
54
- stacklevel = 2 )
55
-
56
-
57
- embed_commit_hash ()
58
-
59
31
# cannot import envs directly because it depends on vllm,
60
32
# which is not installed yet
61
33
envs = load_module_from_path ('envs' , os .path .join (ROOT_DIR , 'vllm' , 'envs.py' ))
@@ -381,21 +353,9 @@ def get_path(*filepath) -> str:
381
353
return os .path .join (ROOT_DIR , * filepath )
382
354
383
355
384
- def find_version (filepath : str ) -> str :
385
- """Extract version information from the given filepath.
386
-
387
- Adapted from https://github.com/ray-project/ray/blob/0b190ee1160eeca9796bc091e07eaebf4c85b511/python/setup.py
388
- """
389
- with open (filepath ) as fp :
390
- version_match = re .search (r"^__version__ = ['\"]([^'\"]*)['\"]" ,
391
- fp .read (), re .M )
392
- if version_match :
393
- return version_match .group (1 )
394
- raise RuntimeError ("Unable to find version string." )
395
-
396
-
397
356
def get_vllm_version () -> str :
398
- version = find_version (get_path ("vllm" , "version.py" ))
357
+ version = get_version ()
358
+ sep = "+" if "+" not in version else "." # dev versions might contain +
399
359
400
360
if _no_device ():
401
361
if envs .VLLM_TARGET_DEVICE == "empty" :
@@ -406,27 +366,27 @@ def get_vllm_version() -> str:
406
366
cuda_version_str = cuda_version .replace ("." , "" )[:3 ]
407
367
# skip this for source tarball, required for pypi
408
368
if "sdist" not in sys .argv :
409
- version += f"+ cu{ cuda_version_str } "
369
+ version += f"{ sep } cu{ cuda_version_str } "
410
370
elif _is_hip ():
411
371
# Get the HIP version
412
372
hipcc_version = get_hipcc_rocm_version ()
413
373
if hipcc_version != MAIN_CUDA_VERSION :
414
374
rocm_version_str = hipcc_version .replace ("." , "" )[:3 ]
415
- version += f"+ rocm{ rocm_version_str } "
375
+ version += f"{ sep } rocm{ rocm_version_str } "
416
376
elif _is_neuron ():
417
377
# Get the Neuron version
418
378
neuron_version = str (get_neuronxcc_version ())
419
379
if neuron_version != MAIN_CUDA_VERSION :
420
380
neuron_version_str = neuron_version .replace ("." , "" )[:3 ]
421
- version += f"+ neuron{ neuron_version_str } "
381
+ version += f"{ sep } neuron{ neuron_version_str } "
422
382
elif _is_openvino ():
423
- version += "+ openvino"
383
+ version += f" { sep } openvino"
424
384
elif _is_tpu ():
425
- version += "+ tpu"
385
+ version += f" { sep } tpu"
426
386
elif _is_cpu ():
427
- version += "+ cpu"
387
+ version += f" { sep } cpu"
428
388
elif _is_xpu ():
429
- version += "+ xpu"
389
+ version += f" { sep } xpu"
430
390
else :
431
391
raise RuntimeError ("Unknown runtime environment" )
432
392
0 commit comments