[Doc] Add --force-overwrite option to generate_cmake_presets.py (#24375)

Signed-off-by: elvischenv <219235043+elvischenv@users.noreply.github.com>
This commit is contained in:
elvischenv 2025-09-17 09:45:29 +08:00 committed by GitHub
parent 64ad551878
commit 3059b9cc6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 8 deletions

View File

@ -40,6 +40,16 @@ python tools/generate_cmake_presets.py
The script will prompt you if it cannot automatically determine certain paths (e.g., `nvcc` or a specific Python executable for your vLLM development environment). Follow the on-screen prompts. If an existing `CMakeUserPresets.json` is found, the script will ask for confirmation before overwriting it. The script will prompt you if it cannot automatically determine certain paths (e.g., `nvcc` or a specific Python executable for your vLLM development environment). Follow the on-screen prompts. If an existing `CMakeUserPresets.json` is found, the script will ask for confirmation before overwriting it.
**Force overwrite existing file:**
To automatically overwrite an existing `CMakeUserPresets.json` without prompting, use the `--force-overwrite` flag:
```console
python tools/generate_cmake_presets.py --force-overwrite
```
This is particularly useful in automated scripts or CI/CD environments where interactive prompts are not desired.
After running the script, a `CMakeUserPresets.json` file will be created in the root of your vLLM repository. After running the script, a `CMakeUserPresets.json` file will be created in the root of your vLLM repository.
### Example `CMakeUserPresets.json` ### Example `CMakeUserPresets.json`

View File

@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import argparse
import json import json
import multiprocessing import multiprocessing
import os import os
@ -26,7 +27,8 @@ def get_cpu_cores():
return multiprocessing.cpu_count() return multiprocessing.cpu_count()
def generate_presets(output_path="CMakeUserPresets.json"): def generate_presets(output_path="CMakeUserPresets.json",
force_overwrite=False):
"""Generates the CMakeUserPresets.json file.""" """Generates the CMakeUserPresets.json file."""
print("Attempting to detect your system configuration...") print("Attempting to detect your system configuration...")
@ -143,12 +145,15 @@ def generate_presets(output_path="CMakeUserPresets.json"):
output_file_path = os.path.join(project_root, output_path) output_file_path = os.path.join(project_root, output_path)
if os.path.exists(output_file_path): if os.path.exists(output_file_path):
overwrite = input( if force_overwrite:
f"'{output_file_path}' already exists. Overwrite? (y/N): ").strip( print(f"Overwriting existing file '{output_file_path}'")
).lower() else:
if overwrite != 'y': overwrite = input(
print("Generation cancelled.") f"'{output_file_path}' already exists. Overwrite? (y/N): "
return ).strip().lower()
if overwrite != 'y':
print("Generation cancelled.")
return
try: try:
with open(output_file_path, "w") as f: with open(output_file_path, "w") as f:
@ -166,4 +171,12 @@ def generate_presets(output_path="CMakeUserPresets.json"):
if __name__ == "__main__": if __name__ == "__main__":
generate_presets() parser = argparse.ArgumentParser()
parser.add_argument(
"--force-overwrite",
action="store_true",
help="Force overwrite existing CMakeUserPresets.json without prompting"
)
args = parser.parse_args()
generate_presets(force_overwrite=args.force_overwrite)