Skip to content

Commit

Permalink
default to not packing/unpacking wheels into standalone python bundle (
Browse files Browse the repository at this point in the history
…#184)

* only pack/unpack wheels into the python bundle if `pack-wheels` arg is passed to `standalone` cmd

* fix typing nits
  • Loading branch information
telamonian authored Sep 15, 2024
1 parent cb20165 commit 3d9b73e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
11 changes: 9 additions & 2 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ def standalone(
help="setuptools-style requirement specificer pointing to an instance of comfy-cli",
),
] = "comfy-cli",
pack_wheels: Annotated[
bool,
typer.Option(
show_default=False,
help="Pack requirement wheels in archive when creating standalone bundle",
),
] = False,
platform: Annotated[
Optional[constants.OS],
typer.Option(
Expand Down Expand Up @@ -605,10 +612,10 @@ def standalone(

if rehydrate:
sty = StandalonePython.FromTarball(fpath="python.tgz")
sty.rehydrate_comfy_deps()
sty.rehydrate_comfy_deps(packWheels=pack_wheels)
else:
sty = StandalonePython.FromDistro(platform=platform, proc=proc)
sty.dehydrate_comfy_deps(comfyDir=comfy_path, extraSpecs=cli_spec)
sty.dehydrate_comfy_deps(comfyDir=comfy_path, extraSpecs=[cli_spec], packWheels=pack_wheels)
sty.to_tarball()


Expand Down
24 changes: 15 additions & 9 deletions comfy_cli/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def clean(self):
for pycache in self.rpath.glob("**/__pycache__"):
shutil.rmtree(pycache)

def run_module(self, mod: str, *args: list[str]):
def run_module(self, mod: str, *args: str):
cmd: list[str] = [
str(self.executable),
"-m",
Expand All @@ -125,10 +125,10 @@ def run_module(self, mod: str, *args: list[str]):

subprocess.run(cmd, check=True)

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

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

def install_comfy_cli(self, dev: bool = False):
Expand All @@ -137,16 +137,17 @@ def install_comfy_cli(self, dev: bool = False):
else:
self.uv_install("comfy_cli")

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

def install_comfy(self, *args: list[str], gpu_arg: str = "--nvidia"):
def install_comfy(self, *args: str, gpu_arg: str = "--nvidia"):
self.run_comfy_cli("--here", "--skip-prompt", "install", "--fast-deps", gpu_arg, *args)

def dehydrate_comfy_deps(
self,
comfyDir: PathLike,
extraSpecs: Optional[list[str]] = None,
packWheels: bool = False,
):
self.dep_comp = DependencyCompiler(
cwd=comfyDir,
Expand All @@ -156,14 +157,19 @@ def dehydrate_comfy_deps(
)
self.dep_comp.compile_deps()

skip_uv = get_os() == OS.WINDOWS
self.dep_comp.fetch_dep_wheels(skip_uv=skip_uv)
if packWheels:
skip_uv = get_os() == OS.WINDOWS
self.dep_comp.fetch_dep_wheels(skip_uv=skip_uv)

def rehydrate_comfy_deps(self):
def rehydrate_comfy_deps(self, packWheels: bool = False):
self.dep_comp = DependencyCompiler(
executable=self.executable, outDir=self.rpath, reqFilesCore=[], reqFilesExt=[]
)
self.dep_comp.install_wheels_directly()

if packWheels:
self.dep_comp.install_wheels_directly()
else:
self.dep_comp.install_deps()

def to_tarball(self, outPath: Optional[PathLike] = None, show_progress: bool = True):
# remove any __pycache__ before creating archive
Expand Down
12 changes: 6 additions & 6 deletions comfy_cli/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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",
Expand Down Expand Up @@ -232,7 +232,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",
Expand Down Expand Up @@ -262,7 +262,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),
Expand Down Expand Up @@ -298,7 +298,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),
Expand Down Expand Up @@ -480,20 +480,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):
Expand Down

0 comments on commit 3d9b73e

Please sign in to comment.