Skip to content

Commit 2b184dd

Browse files
cermengyoukaichao
andauthored
[Misc][Installation] Improve source installation script and doc (#9309)
Co-authored-by: youkaichao <youkaichao@126.com>
1 parent 00298e0 commit 2b184dd

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

docs/source/getting_started/installation.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Latest code can contain bugs and may not be stable. Please use it with caution.
8484
Build from source
8585
==================
8686

87+
.. _python-only-build:
88+
8789
Python-only build (without compilation)
8890
----------------------------------------
8991

@@ -114,6 +116,23 @@ The script will:
114116

115117
Now, you can edit the Python code in the current directory, and the changes will be reflected when you run vLLM.
116118

119+
Once you have finished editing or want to install another vLLM wheel, you should exit the development environment using `the same script <https://github.com/vllm-project/vllm/blob/main/python_only_dev.py>`_ with the ``--quit-dev``(or ``-q`` for short) flag:
120+
121+
.. code-block:: console
122+
123+
$ python python_only_dev.py --quit-dev
124+
125+
The script with ``--quit-dev`` flag will:
126+
127+
* Remove the symbolic link from the current directory to the vLLM package.
128+
* Restore the original vLLM package from the backup.
129+
130+
If you update the vLLM wheel and want to rebuild from the source and make further edits, you will need to start `all above <#python-only-build>`_ over again.
131+
132+
.. note::
133+
134+
There is a possibility that your source code may have a different commit ID compared to the latest vLLM wheel, which could potentially lead to unknown errors.
135+
It is recommended to use the same commit ID for the source code as the vLLM wheel you have installed. Please refer to `the above section <#install-the-latest-code>`_ for instructions on how to install a specified wheel.
117136

118137
Full build (with compilation)
119138
---------------------------------

python_only_dev.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# enable python only development
22
# copy compiled files to the current directory directly
33

4+
import argparse
45
import os
56
import shutil
67
import subprocess
78
import sys
9+
import warnings
10+
11+
parser = argparse.ArgumentParser(
12+
description="Development mode for python-only code")
13+
parser.add_argument('-q',
14+
'--quit-dev',
15+
action='store_true',
16+
help='Set the flag to quit development mode')
17+
args = parser.parse_args()
818

919
# cannot directly `import vllm` , because it will try to
1020
# import from the current directory
@@ -37,18 +47,46 @@
3747
# "vllm/_version.py", # not available in nightly wheels yet
3848
]
3949

40-
for file in files_to_copy:
41-
src = os.path.join(package_path, file)
42-
dst = file
43-
print(f"Copying {src} to {dst}")
44-
shutil.copyfile(src, dst)
50+
# Try to create _version.py to avoid version related warning
51+
# Refer to https://github.com/vllm-project/vllm/pull/8771
52+
try:
53+
from setuptools_scm import get_version
54+
get_version(write_to="vllm/_version.py")
55+
except ImportError:
56+
warnings.warn(
57+
"To avoid warnings related to vllm._version, "
58+
"you should install setuptools-scm by `pip install setuptools-scm`",
59+
stacklevel=2)
60+
61+
if not args.quit_dev:
62+
for file in files_to_copy:
63+
src = os.path.join(package_path, file)
64+
dst = file
65+
print(f"Copying {src} to {dst}")
66+
shutil.copyfile(src, dst)
67+
68+
pre_built_vllm_path = os.path.join(package_path, "vllm")
69+
tmp_path = os.path.join(package_path, "vllm_pre_built")
70+
current_vllm_path = os.path.join(cwd, "vllm")
71+
72+
print(f"Renaming {pre_built_vllm_path} to {tmp_path} for backup")
73+
os.rename(pre_built_vllm_path, tmp_path)
4574

46-
pre_built_vllm_path = os.path.join(package_path, "vllm")
47-
tmp_path = os.path.join(package_path, "vllm_pre_built")
48-
current_vllm_path = os.path.join(cwd, "vllm")
75+
print(f"Linking {current_vllm_path} to {pre_built_vllm_path}")
76+
os.symlink(current_vllm_path, pre_built_vllm_path)
77+
else:
78+
vllm_symlink_path = os.path.join(package_path, "vllm")
79+
vllm_backup_path = os.path.join(package_path, "vllm_pre_built")
80+
current_vllm_path = os.path.join(cwd, "vllm")
4981

50-
print(f"Renaming {pre_built_vllm_path} to {tmp_path}")
51-
os.rename(pre_built_vllm_path, tmp_path)
82+
print(f"Unlinking {current_vllm_path} to {vllm_symlink_path}")
83+
assert os.path.islink(
84+
vllm_symlink_path
85+
), f"not in dev mode: {vllm_symlink_path} is not a symbolic link"
86+
assert current_vllm_path == os.readlink(
87+
vllm_symlink_path
88+
), "current directory is not the source code of package"
89+
os.unlink(vllm_symlink_path)
5290

53-
print(f"linking {current_vllm_path} to {pre_built_vllm_path}")
54-
os.symlink(current_vllm_path, pre_built_vllm_path)
91+
print(f"Recovering backup from {vllm_backup_path} to {vllm_symlink_path}")
92+
os.rename(vllm_backup_path, vllm_symlink_path)

0 commit comments

Comments
 (0)