From 7dcd33ab381fcc8788eb05cdfec4c6b7e0c57358 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Sun, 15 Sep 2024 20:30:24 +0900 Subject: [PATCH 1/4] Add. --- comfy_cli/uv.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/comfy_cli/uv.py b/comfy_cli/uv.py index 8bfcd85..0191df5 100644 --- a/comfy_cli/uv.py +++ b/comfy_cli/uv.py @@ -19,6 +19,7 @@ def _run(cmd: list[str], cwd: PathLike, check: bool = True) -> subprocess.Comple def _check_call(cmd: list[str], cwd: Optional[PathLike] = None): """uses check_call to run pip, as reccomended by the pip maintainers. see https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program""" + print("Running:", " ".join(cmd)) subprocess.check_call(cmd, cwd=cwd) @@ -326,8 +327,8 @@ def Wheel( return _check_call(cmd, cwd) @staticmethod - def Resolve_Gpu(gpu: Union[GPU_OPTION, None]): - if gpu is None: + def Resolve_Gpu(gpu: GPU_OPTION): + if gpu is None or gpu is GPU_OPTION.CPU: try: tver = metadata.version("torch") if "+cu" in tver: @@ -345,7 +346,7 @@ def __init__( self, cwd: PathLike = ".", executable: PathLike = sys.executable, - gpu: Union[GPU_OPTION, None] = None, + gpu: GPU_OPTION = GPU_OPTION.CPU, outDir: PathLike = ".", outName: str = "requirements.compiled", reqFilesCore: Optional[list[PathLike]] = None, From a280250f4bf95496f74c5728a913688a464dafb8 Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Wed, 13 Nov 2024 13:58:11 -0800 Subject: [PATCH 2/4] Catch errro.. --- comfy_cli/command/custom_nodes/command.py | 8 +------- comfy_cli/command/install.py | 5 ++++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/comfy_cli/command/custom_nodes/command.py b/comfy_cli/command/custom_nodes/command.py index 50b4ef6..5972aa2 100644 --- a/comfy_cli/command/custom_nodes/command.py +++ b/comfy_cli/command/custom_nodes/command.py @@ -491,13 +491,7 @@ def update_node_id_cache(): new_env = os.environ.copy() new_env["COMFYUI_PATH"] = workspace_path - res = subprocess.run(cmd, env=new_env, check=True) - if res.returncode != 0: - typer.echo( - "Failed to update node id cache.", - err=True, - ) - raise typer.Exit(code=1) + subprocess.run(cmd, env=new_env, check=True) # `update, disable, enable, fix` allows `all` param diff --git a/comfy_cli/command/install.py b/comfy_cli/command/install.py index b80cba2..8892393 100644 --- a/comfy_cli/command/install.py +++ b/comfy_cli/command/install.py @@ -244,7 +244,10 @@ def execute( depComp.install_deps() if not skip_manager: - update_node_id_cache() + try: + update_node_id_cache() + except subprocess.CalledProcessError as e: + rprint(f"Failed to update node id cache: {e}") os.chdir(repo_dir) From f9d28bca8e12b3e8eae364d65261086b0299de9a Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Wed, 13 Nov 2024 14:01:13 -0800 Subject: [PATCH 3/4] Update ruff. --- comfy_cli/uv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comfy_cli/uv.py b/comfy_cli/uv.py index 0191df5..3b6cf75 100644 --- a/comfy_cli/uv.py +++ b/comfy_cli/uv.py @@ -4,7 +4,7 @@ from importlib import metadata from pathlib import Path from textwrap import dedent -from typing import Any, Optional, Union, cast +from typing import Any, Optional, cast from comfy_cli import ui from comfy_cli.constants import GPU_OPTION, OS From d589d1094057e2ce6e9941e4a310c732792383ad Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Wed, 13 Nov 2024 14:02:24 -0800 Subject: [PATCH 4/4] Revert. --- comfy_cli/uv.py | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/comfy_cli/uv.py b/comfy_cli/uv.py index 3b6cf75..2a89b3e 100644 --- a/comfy_cli/uv.py +++ b/comfy_cli/uv.py @@ -4,12 +4,11 @@ from importlib import metadata from pathlib import Path from textwrap import dedent -from typing import Any, Optional, cast +from typing import Any, Optional, Union, cast from comfy_cli import ui -from comfy_cli.constants import GPU_OPTION, OS +from comfy_cli.constants import GPU_OPTION from comfy_cli.typing import PathLike -from comfy_cli.utils import get_os def _run(cmd: list[str], cwd: PathLike, check: bool = True) -> subprocess.CompletedProcess[Any]: @@ -19,7 +18,6 @@ def _run(cmd: list[str], cwd: PathLike, check: bool = True) -> subprocess.Comple def _check_call(cmd: list[str], cwd: Optional[PathLike] = None): """uses check_call to run pip, as reccomended by the pip maintainers. see https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program""" - print("Running:", " ".join(cmd)) subprocess.check_call(cmd, cwd=cwd) @@ -80,21 +78,28 @@ class DependencyCompiler: """ ).strip() - reqNames = { + reqNames = ( "requirements.txt", "pyproject.toml", "setup.cfg", "setup.py", - } + ) @staticmethod def Find_Req_Files(*ders: PathLike) -> list[Path]: - return [ - file # fmt: skip - for der in ders - for file in Path(der).absolute().iterdir() - if file.name in DependencyCompiler.reqNames - ] + reqFiles = [] + for der in ders: + reqFound = False + for reqName in DependencyCompiler.reqNames: + for file in Path(der).absolute().iterdir(): + if file.name == reqName: + reqFiles.append(file) + reqFound = True + break + if reqFound: + break + + return reqFiles @staticmethod def Install_Build_Deps(executable: PathLike = sys.executable): @@ -185,7 +190,7 @@ def Install( override: Optional[PathLike] = None, reqs: Optional[list[str]] = None, reqFile: Optional[list[PathLike]] = None, - ) -> subprocess.CompletedProcess[Any]: + ) -> None: cmd = [ str(executable), "-m", @@ -233,7 +238,7 @@ def Sync( executable: PathLike = sys.executable, extraUrl: Optional[str] = None, index_strategy: str = "unsafe-best-match", - ) -> subprocess.CompletedProcess[Any]: + ) -> None: cmd = [ str(executable), "-m", @@ -263,7 +268,7 @@ def Download( out: Optional[PathLike] = None, reqs: Optional[list[str]] = None, reqFile: Optional[list[PathLike]] = None, - ) -> subprocess.CompletedProcess[Any]: + ) -> None: """For now, the `download` cmd has no uv support, so use pip""" cmd = [ str(executable), @@ -299,7 +304,7 @@ def Wheel( out: Optional[PathLike] = None, reqs: Optional[list[str]] = None, reqFile: Optional[list[PathLike]] = None, - ) -> subprocess.CompletedProcess[Any]: + ) -> None: """For now, the `wheel` cmd has no uv support, so use pip""" cmd = [ str(executable), @@ -327,8 +332,8 @@ def Wheel( return _check_call(cmd, cwd) @staticmethod - def Resolve_Gpu(gpu: GPU_OPTION): - if gpu is None or gpu is GPU_OPTION.CPU: + def Resolve_Gpu(gpu: Union[GPU_OPTION, None]): + if gpu is None: try: tver = metadata.version("torch") if "+cu" in tver: @@ -346,7 +351,7 @@ def __init__( self, cwd: PathLike = ".", executable: PathLike = sys.executable, - gpu: GPU_OPTION = GPU_OPTION.CPU, + gpu: Union[GPU_OPTION, None] = None, outDir: PathLike = ".", outName: str = "requirements.compiled", reqFilesCore: Optional[list[PathLike]] = None, @@ -400,8 +405,6 @@ def make_override(self): f.write(DependencyCompiler.overrideGpu.format(gpu=self.gpu, gpuUrl=self.gpuUrl)) f.write("\n\n") - # TODO: remove numpy<2 override once torch is compatible with numpy>=2 - if get_os() == OS.WINDOWS: f.write("numpy<2\n") f.write("\n\n") @@ -481,20 +484,20 @@ def compile_deps(self): def install_deps(self): DependencyCompiler.Install( cwd=self.cwd, - reqFile=[self.out], executable=self.executable, extra_index_url=self.gpuUrl, override=self.override, + reqFile=[self.out], ) def install_dists(self): DependencyCompiler.Install( cwd=self.cwd, - reqFile=[self.out], executable=self.executable, find_links=[self.outDir / "dists"], no_deps=True, no_index=True, + reqFile=[self.out], ) def install_wheels(self):