Skip to content

Commit

Permalink
added install_* methods to StandalonePython
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Aug 23, 2024
1 parent 065a44c commit 7970655
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
37 changes: 36 additions & 1 deletion comfy_cli/standalone.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
from pathlib import Path
import shutil
import subprocess
import tarfile
from typing import Optional

import requests

from comfy_cli.constants import OS, PROC
from comfy_cli.utils import download_progress, get_os, get_proc
from comfy_cli.typing import PathLike
from comfy_cli.utils import download_progress, get_os, get_proc
from comfy_cli.uv import DependencyCompiler

_here = Path(__file__).expanduser().resolve().parent

_platform_targets = {
(OS.MACOS, PROC.ARM): "aarch64-apple-darwin",
Expand Down Expand Up @@ -85,3 +89,34 @@ def __init__(self, rpath: PathLike):
self.name = self.rpath.name
self.bin = self.rpath / "bin"
self.executable = self.bin / "python"

# upgrade pip if needed, install uv
self.pip_install("-U", "pip", "uv")

def run_module(self, mod: str, *args: list[str]):
cmd: list[str] = [
str(self.executable),
"-m",
mod,
*args,
]

subprocess.run(cmd, check=True)

def pip_install(self, *args: list[str]):
self.run_module("pip", "install", *args)

def uv_install(self, *args: list[str]):
self.run_module("uv", "pip", "install", *args)

def install_comfy_cli(self, dev: bool = False):
if dev:
self.uv_install(str(_here.parent))
else:
self.uv_install("comfy_cli")

def run_comfy_cli(self, *args: list[str]):
self.run_module("comfy_cli", *args)

def install_comfy(self, *args: list[str], gpu_arg: str = "--nvidia"):
self.run_comfy_cli("--here", "--skip-prompt", "install", "--fast-deps", gpu_arg, *args)
12 changes: 5 additions & 7 deletions comfy_cli/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from comfy_cli.typing import PathLike


def _run(cmd: list[str], cwd: PathLike) -> subprocess.CompletedProcess[Any]:
return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=True)
def _run(cmd: list[str], cwd: PathLike, check: bool = True) -> subprocess.CompletedProcess[Any]:
return subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, check=check)


def _check_call(cmd: list[str], cwd: Optional[PathLike] = None):
Expand Down Expand Up @@ -45,7 +45,7 @@ def parse_uv_compile_error(err: str) -> tuple[str, list[str]]:


class DependencyCompiler:
rocmPytorchUrl = "https://download.pytorch.org/whl/rocm6.0"
rocmPytorchUrl = "https://download.pytorch.org/whl/rocm6.1"
nvidiaPytorchUrl = "https://download.pytorch.org/whl/cu121"

overrideGpu = dedent(
Expand Down Expand Up @@ -77,10 +77,8 @@ def Find_Req_Files(*ders: PathLike) -> list[Path]:
@staticmethod
def Install_Build_Deps(executable: PathLike = sys.executable):
"""Use pip to install bare minimum requirements for uv to do its thing"""
if shutil.which("uv") is None:
cmd = [str(executable), "-m", "pip", "install", "--upgrade", "pip", "uv"]

_check_call(cmd=cmd)
cmd = [str(executable), "-m", "pip", "install", "--upgrade", "pip", "uv"]
_check_call(cmd=cmd)

@staticmethod
def Compile(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies = [
"tqdm",
"typer>=0.9.0",
"typing-extensions>=4.7.0",
"uv",
"websocket-client",
]

Expand Down

0 comments on commit 7970655

Please sign in to comment.