Skip to content

Commit

Permalink
allow specification of python executable in DependencyCompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Aug 23, 2024
1 parent 07b066e commit 065a44c
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions comfy_cli/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,25 @@ def Find_Req_Files(*ders: PathLike) -> list[Path]:
]

@staticmethod
def Install_Build_Deps():
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 = [sys.executable, "-m", "pip", "install", "--upgrade", "pip", "uv"]
cmd = [str(executable), "-m", "pip", "install", "--upgrade", "pip", "uv"]

_check_call(cmd=cmd)

@staticmethod
def Compile(
cwd: PathLike,
reqFiles: list[PathLike],
executable: PathLike = sys.executable,
index_strategy: str = "unsafe-best-match",
override: Optional[PathLike] = None,
out: Optional[PathLike] = None,
index_strategy: Optional[str] = "unsafe-best-match",
resolve_strategy: Optional[str] = None,
) -> subprocess.CompletedProcess[Any]:
cmd = [
sys.executable,
str(executable),
"-m",
"uv",
"pip",
Expand Down Expand Up @@ -147,13 +148,14 @@ def Compile(
def Install(
cwd: PathLike,
reqFile: list[PathLike],
override: Optional[PathLike] = None,
extraUrl: Optional[str] = None,
index_strategy: Optional[str] = "unsafe-best-match",
dry: bool = False,
executable: PathLike = sys.executable,
extraUrl: Optional[str] = None,
index_strategy: str = "unsafe-best-match",
override: Optional[PathLike] = None,
) -> subprocess.CompletedProcess[Any]:
cmd = [
sys.executable,
str(executable),
"-m",
"uv",
"pip",
Expand All @@ -180,12 +182,13 @@ def Install(
def Sync(
cwd: PathLike,
reqFile: list[PathLike],
extraUrl: Optional[str] = None,
index_strategy: Optional[str] = "unsafe-best-match",
dry: bool = False,
executable: PathLike = sys.executable,
extraUrl: Optional[str] = None,
index_strategy: str = "unsafe-best-match",
) -> subprocess.CompletedProcess[Any]:
cmd = [
sys.executable,
str(executable),
"-m",
"uv",
"pip",
Expand Down Expand Up @@ -223,14 +226,16 @@ def Resolve_Gpu(gpu: Union[str, None]):
def __init__(
self,
cwd: PathLike = ".",
reqFilesCore: Optional[list[PathLike]] = None,
reqFilesExt: Optional[list[PathLike]] = None,
executable: PathLike = sys.executable,
gpu: Optional[str] = None,
outName: str = "requirements.compiled",
reqFilesCore: Optional[list[PathLike]] = None,
reqFilesExt: Optional[list[PathLike]] = None,
):
self.cwd = Path(cwd)
self.reqFiles = [Path(reqFile) for reqFile in reqFilesExt] if reqFilesExt is not None else None
self.executable = executable
self.gpu = DependencyCompiler.Resolve_Gpu(gpu)
self.reqFiles = [Path(reqFile) for reqFile in reqFilesExt] if reqFilesExt is not None else None

self.gpuUrl = (
DependencyCompiler.nvidiaPytorchUrl
Expand Down Expand Up @@ -261,7 +266,12 @@ def make_override(self):
f.write(DependencyCompiler.overrideGpu.format(gpu=self.gpu, gpuUrl=self.gpuUrl))
f.write("\n\n")

completed = DependencyCompiler.Compile(cwd=self.cwd, reqFiles=self.reqFilesCore, override=self.override)
completed = DependencyCompiler.Compile(
cwd=self.cwd,
reqFiles=self.reqFilesCore,
executable=self.executable,
override=self.override
)

with open(self.override, "a") as f:
f.write("# ensure that core comfyui deps take precedence over any 3rd party extension deps\n")
Expand All @@ -278,6 +288,7 @@ def compile_core_plus_ext(self):
DependencyCompiler.Compile(
cwd=self.cwd,
reqFiles=(self.reqFilesCore + self.reqFilesExt),
executable=self.executable,
override=self.override,
out=self.out,
resolve_strategy="ask",
Expand All @@ -295,14 +306,16 @@ def install_core_plus_ext(self):
DependencyCompiler.Install(
cwd=self.cwd,
reqFile=self.out,
override=self.override,
executable=self.executable,
extraUrl=self.gpuUrl,
override=self.override,
)

def sync_core_plus_ext(self):
DependencyCompiler.Sync(
cwd=self.cwd,
reqFile=self.out,
executable=self.executable,
extraUrl=self.gpuUrl,
)

Expand All @@ -328,7 +341,7 @@ def handle_opencv(self):
f.write(line)

def install_comfy_deps(self):
DependencyCompiler.Install_Build_Deps()
DependencyCompiler.Install_Build_Deps(executable=self.executable)

self.make_override()
self.compile_core_plus_ext()
Expand Down

0 comments on commit 065a44c

Please sign in to comment.