Skip to content

Commit cdac435

Browse files
committed
add uv installation in becnhmark
1 parent d6d2d0d commit cdac435

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

mytonctrl/mytonctrl.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,18 @@ def upgrade_btc_teleport(local, ton, reinstall=False, branch: str = 'master', us
406406

407407
def run_benchmark(args: list):
408408
if shutil.which("uv") is None:
409-
color_print("{red}Error: uv is not installed. Install it: https://docs.astral.sh/uv/getting-started/installation/{endc}")
410-
return
409+
answer = input("uv is not installed. Install it? [y/n] ").strip().lower()
410+
if answer == "y":
411+
subprocess.run(["curl", "-LsSf", "https://astral.sh/uv/install.sh", "-o", "/tmp/uv_install.sh"], check=True)
412+
subprocess.run(["sh", "/tmp/uv_install.sh"], check=True)
413+
uv_local_bin = os.path.expanduser("~/.local/bin")
414+
if uv_local_bin not in os.environ.get("PATH", ""):
415+
os.environ["PATH"] = uv_local_bin + os.pathsep + os.environ.get("PATH", "")
416+
if shutil.which("uv") is None:
417+
color_print("{red}Error: uv installation failed{endc}")
418+
return
419+
else:
420+
return
411421

412422
if get_service_status("validator"):
413423
color_print("{red}Error: validator service is running. Stop it before running benchmark: `sudo systemctl stop validator`{endc}")

tests/integration/test_benchmark.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,44 @@
44
from unittest.mock import MagicMock
55

66

7-
def test_benchmark_uv_not_installed(cli, monkeypatch):
7+
def test_benchmark_uv_not_installed_decline(cli, monkeypatch):
88
monkeypatch.setattr(shutil, "which", lambda name: None)
9+
monkeypatch.setattr("builtins.input", lambda prompt: "n")
10+
11+
calls = []
12+
monkeypatch.setattr(subprocess, "run", lambda args, **kw: calls.append(args))
13+
14+
cli.execute("benchmark", no_color=True)
15+
assert len(calls) == 0
16+
17+
18+
def test_benchmark_uv_not_installed_install(cli, monkeypatch):
19+
installed = {"uv": False}
20+
21+
def fake_which(name):
22+
if name == "uv" and installed["uv"]:
23+
return "/usr/bin/uv"
24+
return None
25+
26+
monkeypatch.setattr(shutil, "which", fake_which)
27+
monkeypatch.setattr("builtins.input", lambda prompt: "y")
28+
29+
calls = []
30+
31+
def fake_subprocess_run(args, **kwargs):
32+
calls.append([str(a) for a in args])
33+
if args[:2] == ["sh", "/tmp/uv_install.sh"]:
34+
installed["uv"] = True
35+
return subprocess.CompletedProcess(args, 0)
36+
37+
monkeypatch.setattr(subprocess, "run", fake_subprocess_run)
38+
39+
from mytonctrl import mytonctrl as mytonctrl_module
40+
monkeypatch.setattr(mytonctrl_module, "get_service_status", lambda name: True)
41+
942
output = cli.execute("benchmark", no_color=True)
10-
assert "uv is not installed" in output
43+
assert calls[0] == ["curl", "-LsSf", "https://astral.sh/uv/install.sh", "-o", "/tmp/uv_install.sh"]
44+
assert calls[1] == ["sh", "/tmp/uv_install.sh"]
1145

1246

1347
def test_benchmark_validator_running(cli, monkeypatch):

0 commit comments

Comments
 (0)