mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-07 21:08:34 +03:00
fix(plugins): use uv when pip is unavailable
This commit is contained in:
@@ -2479,6 +2479,69 @@ def test_optional_features_payload_preserves_legacy_flat_feishu_config(monkeypat
|
||||
assert "instances" not in saved
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"index_url",
|
||||
[
|
||||
"",
|
||||
"https://mirror.example/simple",
|
||||
],
|
||||
)
|
||||
def test_enable_uses_uv_when_tool_environment_has_no_pip(
|
||||
monkeypatch,
|
||||
index_url,
|
||||
):
|
||||
from nanobot import optional_features
|
||||
|
||||
calls: list[list[str]] = []
|
||||
call_envs: list[dict[str, str] | None] = []
|
||||
|
||||
def _run(
|
||||
argv: list[str],
|
||||
*,
|
||||
env: dict[str, str] | None = None,
|
||||
) -> subprocess.CompletedProcess[str]:
|
||||
calls.append(argv)
|
||||
call_envs.append(env)
|
||||
if len(calls) == 1:
|
||||
return subprocess.CompletedProcess(argv, 1, stdout="", stderr="No module named pip")
|
||||
if argv[0] == "uv":
|
||||
return subprocess.CompletedProcess(argv, 0, stdout="", stderr="")
|
||||
return subprocess.CompletedProcess(
|
||||
argv,
|
||||
1,
|
||||
stdout="",
|
||||
stderr="No module named ensurepip",
|
||||
)
|
||||
|
||||
monkeypatch.setattr("shutil.which", lambda name: "uv" if name == "uv" else None)
|
||||
monkeypatch.setenv("HTTPS_PROXY", "http://proxy.example:8080")
|
||||
monkeypatch.delenv("UV_INDEX_URL", raising=False)
|
||||
if index_url:
|
||||
monkeypatch.setenv("PIP_INDEX_URL", index_url)
|
||||
else:
|
||||
monkeypatch.delenv("PIP_INDEX_URL", raising=False)
|
||||
|
||||
assert optional_features.install_extra("feishu", ["lark-oapi>=1.5.0"], runner=_run).ok is True
|
||||
assert calls == [
|
||||
[sys.executable, "-m", "pip", "install", "lark-oapi>=1.5.0"],
|
||||
[
|
||||
"uv",
|
||||
"pip",
|
||||
"install",
|
||||
"--python",
|
||||
sys.executable,
|
||||
"lark-oapi>=1.5.0",
|
||||
],
|
||||
]
|
||||
assert call_envs[0] is None
|
||||
assert call_envs[1] is not None
|
||||
assert call_envs[1]["HTTPS_PROXY"] == "http://proxy.example:8080"
|
||||
if index_url:
|
||||
assert call_envs[1]["UV_INDEX_URL"] == index_url
|
||||
else:
|
||||
assert "UV_INDEX_URL" not in call_envs[1]
|
||||
|
||||
|
||||
def test_enable_bootstraps_pip_with_ensurepip(monkeypatch):
|
||||
from nanobot import optional_features
|
||||
|
||||
@@ -2490,6 +2553,8 @@ def test_enable_bootstraps_pip_with_ensurepip(monkeypatch):
|
||||
return subprocess.CompletedProcess(argv, 1, stdout="", stderr="No module named pip")
|
||||
return subprocess.CompletedProcess(argv, 0, stdout="", stderr="")
|
||||
|
||||
monkeypatch.setattr("shutil.which", lambda _name: None)
|
||||
|
||||
assert optional_features.install_extra("bedrock", None, runner=_run).ok is True
|
||||
assert calls == [
|
||||
[sys.executable, "-m", "pip", "install", "nanobot-ai[bedrock]"],
|
||||
|
||||
Reference in New Issue
Block a user