|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Installs extra dependencies from a requirements file using uv. |
| 16 | +
|
| 17 | +This script is designed to be run to install dependencies specified in |
| 18 | +'extra_post_train_deps_from_github.txt', which is expected to be in the same directory. |
| 19 | +It first ensures 'uv' is installed and then uses it to install the packages |
| 20 | +listed in the requirements file. |
| 21 | +""" |
| 22 | + |
| 23 | +import os |
| 24 | +import subprocess |
| 25 | +import sys |
| 26 | +from pathlib import Path |
| 27 | + |
| 28 | + |
| 29 | +def main(): |
| 30 | + """ |
| 31 | + Installs extra dependencies specified in extra_post_train_deps_from_github.txt using uv. |
| 32 | +
|
| 33 | + This script looks for 'extra_post_train_deps_from_github.txt' relative to its own location. |
| 34 | + It executes 'uv pip install -r <path_to_extra_deps.txt> --resolution=lowest'. |
| 35 | + """ |
| 36 | + script_dir = Path(__file__).resolve().parent |
| 37 | + |
| 38 | + os.environ['VLLM_TARGET_DEVICE'] = 'tpu' |
| 39 | + |
| 40 | + # Adjust this path if your extra_post_train_deps_from_github.txt is in a different location, |
| 41 | + # e.g., script_dir / "data" / "extra_post_train_deps_from_github.txt" |
| 42 | + extra_deps_file = script_dir / "extra_post_train_deps_from_github.txt" |
| 43 | + |
| 44 | + if not extra_deps_file.exists(): |
| 45 | + print(f"Error: '{extra_deps_file}' not found.") |
| 46 | + print("Please ensure 'extra_post_train_deps_from_github.txt' is in the correct location relative to the script.") |
| 47 | + sys.exit(1) |
| 48 | + # Check if 'uv' is available in the environment |
| 49 | + try: |
| 50 | + subprocess.run([sys.executable, "-m", "pip", "install", "uv"], check=True, capture_output=True) |
| 51 | + subprocess.run([sys.executable, "-m", "uv", "--version"], check=True, capture_output=True) |
| 52 | + except subprocess.CalledProcessError as e: |
| 53 | + print(f"Error checking uv version: {e}") |
| 54 | + print(f"Stderr: {e.stderr.decode()}") |
| 55 | + sys.exit(1) |
| 56 | + |
| 57 | + command = [ |
| 58 | + sys.executable, # Use the current Python executable's pip to ensure the correct environment |
| 59 | + "-m", |
| 60 | + "uv", |
| 61 | + "pip", |
| 62 | + "install", |
| 63 | + "-r", |
| 64 | + str(extra_deps_file), |
| 65 | + "--no-deps", |
| 66 | + ] |
| 67 | + |
| 68 | + print(f"Installing extra dependencies from '{extra_deps_file}' using uv...") |
| 69 | + print(f"Running command: {' '.join(command)}") |
| 70 | + |
| 71 | + try: |
| 72 | + # Run the command |
| 73 | + process = subprocess.run(command, check=True, capture_output=True, text=True) |
| 74 | + print("Extra dependencies installed successfully!") |
| 75 | + print("--- Output from uv ---") |
| 76 | + print(process.stdout) |
| 77 | + if process.stderr: |
| 78 | + print("--- Errors/Warnings from uv (if any) ---") |
| 79 | + print(process.stderr) |
| 80 | + except subprocess.CalledProcessError as e: |
| 81 | + print("Failed to install extra dependencies.") |
| 82 | + print(f"Command '{' '.join(e.cmd)}' returned non-zero exit status {e.returncode}.") |
| 83 | + print("--- Stderr ---") |
| 84 | + print(e.stderr) |
| 85 | + print("--- Stdout ---") |
| 86 | + print(e.stdout) |
| 87 | + sys.exit(e.returncode) |
| 88 | + except (OSError, FileNotFoundError) as e: |
| 89 | + print(f"An OS-level error occurred while trying to run uv: {e}") |
| 90 | + sys.exit(1) |
| 91 | + |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + main() |
0 commit comments