Skip to content

Commit

Permalink
uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Haoming02 committed Jan 8, 2025
1 parent 021154d commit 11cb9ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions modules/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# Whether to default to printing command output
default_command_live = (os.environ.get('WEBUI_LAUNCH_LIVE_OUTPUT') == "1")
uv = (os.environ.get('UV') == "1")

os.environ.setdefault('GRADIO_ANALYTICS_ENABLED', 'False')

Expand Down Expand Up @@ -88,6 +89,13 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_
if desc is not None:
print(desc)

if uv:
original_command = None
if re.search(r"-m\s*pip", command):
original_command = command
_, dep = command.split("pip")
command = f"uv pip {dep}".replace("--prefer-binary", "")

run_kwargs = {
"args": command,
"shell": True,
Expand All @@ -102,6 +110,14 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_
result = subprocess.run(**run_kwargs)

if result.returncode != 0:
if uv and original_command is not None:
print("uv install failed; falling back to pip install")
run_kwargs["args"] = original_command
result = subprocess.run(**run_kwargs)

if result.returncode == 0:
return (result.stdout or "")

error_bits = [
f"{errdesc or 'Error running command'}.",
f"Command: {command}",
Expand Down
7 changes: 6 additions & 1 deletion webui.bat
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ goto :show_stdout_stderr

:upgrade_pip
"%VENV_DIR%\Scripts\Python.exe" -m pip install --upgrade pip
if %ERRORLEVEL% == 0 goto :activate_venv
if %ERRORLEVEL% == 0 goto :check_uv
echo Warning: Failed to upgrade PIP version

:check_uv
if defined UV ("%VENV_DIR%\Scripts\Python.exe" -m pip install uv)
if %ERRORLEVEL% == 0 goto :activate_venv
echo Warning: Failed to install UV package

:activate_venv
set PYTHON="%VENV_DIR%\Scripts\Python.exe"
call "%VENV_DIR%\Scripts\activate.bat"
Expand Down

0 comments on commit 11cb9ac

Please sign in to comment.