Refactor ComfyUI installation script to improve Python environment handling

- Replaced direct calls to `venv/bin/pip` with `python -m pip` to avoid execution errors on network mounts and improve compatibility.
- Introduced a new function `find_comfy_python` to locate the appropriate Python executable for ComfyUI installations.
- Updated the `pip_install_sage` function to utilize the new Python handling, enhancing installation reliability.
- Added tests to verify the new behavior of Python environment detection and installation processes, ensuring robustness.
This commit is contained in:
Leonid Pershin
2026-08-21 10:01:42 +03:00
parent 3e0a51cac4
commit 26f3be6e96
3 changed files with 190 additions and 21 deletions
+32
View File
@@ -44,6 +44,7 @@ def test_pip_fail_skips_extra_args(tmp_path, monkeypatch):
monkeypatch.setattr(mod, "MARKER", data / ".gpu-rent-perf-tuned")
monkeypatch.setattr(mod, "BACKENDS", backends)
monkeypatch.setattr(mod, "find_pip", lambda: pip)
monkeypatch.setattr(mod, "find_comfy_python", lambda: pip)
monkeypatch.setattr(mod, "pip_install_sage", lambda _p: False)
assert mod.main() == 0
@@ -79,6 +80,7 @@ def test_pip_ok_patches_extra_args(tmp_path, monkeypatch):
monkeypatch.setattr(mod, "MARKER", data / ".gpu-rent-perf-tuned")
monkeypatch.setattr(mod, "BACKENDS", backends)
monkeypatch.setattr(mod, "find_pip", lambda: pip)
monkeypatch.setattr(mod, "find_comfy_python", lambda: pip)
monkeypatch.setattr(mod, "pip_install_sage", lambda _p: True)
assert mod.main() == 0
@@ -127,9 +129,39 @@ def test_pip_fail_retries_next_run(tmp_path, monkeypatch):
monkeypatch.setattr(mod, "MARKER", marker)
monkeypatch.setattr(mod, "BACKENDS", backends)
monkeypatch.setattr(mod, "find_pip", lambda: pip)
monkeypatch.setattr(mod, "find_comfy_python", lambda: pip)
monkeypatch.setattr(mod, "pip_install_sage", lambda _p: True)
assert mod.main() == 0
new_m = json.loads(marker.read_text(encoding="utf-8"))
assert new_m["pip_ok"] is True
assert "--use-sage-attention" in backends.read_text(encoding="utf-8")
def test_pip_install_uses_python_dash_m(tmp_path, monkeypatch):
mod = _load()
py = tmp_path / "python"
py.write_text("", encoding="utf-8")
seen: list[list[str]] = []
def fake_call(cmd, env=None):
seen.append(list(cmd))
return 0
monkeypatch.setattr(mod, "sage_already_importable", lambda _p: False)
monkeypatch.setattr(mod.subprocess, "check_call", fake_call)
assert mod.pip_install_sage(py) is True
assert seen and seen[0][:4] == [str(py), "-m", "pip", "install"]
def test_pip_install_oserror_returns_false(tmp_path, monkeypatch):
mod = _load()
py = tmp_path / "python"
py.write_text("", encoding="utf-8")
def boom(*_a, **_k):
raise OSError(8, "Exec format error", str(py))
monkeypatch.setattr(mod, "sage_already_importable", lambda _p: False)
monkeypatch.setattr(mod.subprocess, "check_call", boom)
assert mod.pip_install_sage(py) is False