From 48ab48cc30c8f9ff0d6af3ed537989489f33d4c9 Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Wed, 17 Sep 2025 06:28:06 +0900 Subject: [PATCH] fixed: more complete `uv` support * Previously, only `uv` installed inside a venv was properly handled. Now `uv` installed outside the venv is also supported. * Even if `use_uv=False`, `uv` is used as a fallback when `pip` is unavailable. * Even if `use_uv=True`, `pip` is used as a fallback when `uv` is unavailable. https://github.com/Comfy-Org/ComfyUI-Manager/issues/2125 --- glob/manager_core.py | 2 +- glob/manager_util.py | 69 +++++++++++++++++++++++++++++++++++++------- pyproject.toml | 2 +- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/glob/manager_core.py b/glob/manager_core.py index b52658a7..d77b042c 100644 --- a/glob/manager_core.py +++ b/glob/manager_core.py @@ -43,7 +43,7 @@ import manager_downloader from node_package import InstalledNodePackage -version_code = [3, 36] +version_code = [3, 37] version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '') diff --git a/glob/manager_util.py b/glob/manager_util.py index b3db7b97..5d6a58c7 100644 --- a/glob/manager_util.py +++ b/glob/manager_util.py @@ -15,6 +15,7 @@ import re import logging import platform import shlex +from functools import lru_cache cache_lock = threading.Lock() @@ -34,18 +35,64 @@ def add_python_path_to_env(): os.environ['PATH'] = os.path.dirname(sys.executable)+sep+os.environ['PATH'] +@lru_cache(maxsize=2) +def get_pip_cmd(force_uv=False): + """ + Get the base pip command, with automatic fallback to uv if pip is unavailable. + + Args: + force_uv (bool): If True, use uv directly without trying pip + + Returns: + list: Base command for pip operations + """ + embedded = 'python_embeded' in sys.executable + + # Try pip first (unless forcing uv) + if not force_uv: + try: + test_cmd = [sys.executable] + (['-s'] if embedded else []) + ['-m', 'pip', '--version'] + subprocess.check_output(test_cmd, stderr=subprocess.DEVNULL, timeout=5) + return [sys.executable] + (['-s'] if embedded else []) + ['-m', 'pip'] + except Exception: + logging.warning("[ComfyUI-Manager] python -m pip not available. Falling back to uv.") + + # Try uv (either forced or pip failed) + import shutil + + # Try uv as Python module + try: + test_cmd = [sys.executable] + (['-s'] if embedded else []) + ['-m', 'uv', '--version'] + subprocess.check_output(test_cmd, stderr=subprocess.DEVNULL, timeout=5) + logging.info("[ComfyUI-Manager] Using uv as Python module for pip operations.") + return [sys.executable] + (['-s'] if embedded else []) + ['-m', 'uv', 'pip'] + except Exception: + pass + + # Try standalone uv + if shutil.which('uv'): + logging.info("[ComfyUI-Manager] Using standalone uv for pip operations.") + return ['uv', 'pip'] + + # Nothing worked + logging.error("[ComfyUI-Manager] Neither python -m pip nor uv are available. Cannot proceed with package operations.") + raise Exception("Neither pip nor uv are available for package management") + + def make_pip_cmd(cmd): - if 'python_embeded' in sys.executable: - if use_uv: - return [sys.executable, '-s', '-m', 'uv', 'pip'] + cmd - else: - return [sys.executable, '-s', '-m', 'pip'] + cmd - else: - # FIXED: https://github.com/ltdrdata/ComfyUI-Manager/issues/1667 - if use_uv: - return [sys.executable, '-m', 'uv', 'pip'] + cmd - else: - return [sys.executable, '-m', 'pip'] + cmd + """ + Create a pip command by combining the cached base pip command with the given arguments. + + Args: + cmd (list): List of pip command arguments (e.g., ['install', 'package']) + + Returns: + list: Complete command list ready for subprocess execution + """ + global use_uv + base_cmd = get_pip_cmd(force_uv=use_uv) + return base_cmd + cmd + # DON'T USE StrictVersion - cannot handle pre_release version # try: diff --git a/pyproject.toml b/pyproject.toml index 8d369067..26c15f74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-manager" description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI." -version = "3.36" +version = "3.37" license = { file = "LICENSE.txt" } dependencies = ["GitPython", "PyGithub", "matrix-nio", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions", "toml", "uv", "chardet"]