From 9d1accfea0844af8dfcc40f314be44b439a3c09f Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 28 Feb 2025 23:51:37 +0900 Subject: [PATCH] fallback to pip if uv failes --- modules/uv_hook.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/uv_hook.py b/modules/uv_hook.py index f9360012d..21cb2fb93 100644 --- a/modules/uv_hook.py +++ b/modules/uv_hook.py @@ -1,4 +1,5 @@ import sys +import copy import shlex import subprocess from functools import wraps @@ -18,10 +19,11 @@ def patch(): @wraps(subprocess.__original_run) def patched_run(*args, **kwargs): + _kwargs = copy.copy(kwargs) if args: command, *_args = args else: - command, _args = kwargs.pop("args", ""), () + command, _args = _kwargs.pop("args", ""), () if isinstance(command, str): command = shlex.split(command) @@ -31,7 +33,7 @@ def patch(): assert isinstance(command, list) if "pip" not in command: - return subprocess.__original_run([*command, *_args], **kwargs) + return subprocess.__original_run([*command, *_args], **_kwargs) cmd = command[command.index("pip") + 1 :] @@ -40,6 +42,9 @@ def patch(): modified_command = ["uv", "pip", *cmd] - return subprocess.__original_run([*modified_command, *_args], **kwargs) + result = subprocess.__original_run([*modified_command, *_args], **_kwargs) + if result.returncode != 0: + return subprocess.__original_run(*args, **kwargs) + return result subprocess.run = patched_run