fallback to pip if uv failes
This commit is contained in:
+8
-3
@@ -1,4 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import copy
|
||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
@@ -18,10 +19,11 @@ def patch():
|
|||||||
|
|
||||||
@wraps(subprocess.__original_run)
|
@wraps(subprocess.__original_run)
|
||||||
def patched_run(*args, **kwargs):
|
def patched_run(*args, **kwargs):
|
||||||
|
_kwargs = copy.copy(kwargs)
|
||||||
if args:
|
if args:
|
||||||
command, *_args = args
|
command, *_args = args
|
||||||
else:
|
else:
|
||||||
command, _args = kwargs.pop("args", ""), ()
|
command, _args = _kwargs.pop("args", ""), ()
|
||||||
|
|
||||||
if isinstance(command, str):
|
if isinstance(command, str):
|
||||||
command = shlex.split(command)
|
command = shlex.split(command)
|
||||||
@@ -31,7 +33,7 @@ def patch():
|
|||||||
assert isinstance(command, list)
|
assert isinstance(command, list)
|
||||||
|
|
||||||
if "pip" not in command:
|
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 :]
|
cmd = command[command.index("pip") + 1 :]
|
||||||
|
|
||||||
@@ -40,6 +42,9 @@ def patch():
|
|||||||
|
|
||||||
modified_command = ["uv", "pip", *cmd]
|
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
|
subprocess.run = patched_run
|
||||||
|
|||||||
Reference in New Issue
Block a user