Skip to content

Commit

Permalink
Different executable paths for Windows / Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang committed Aug 28, 2024
1 parent a046f24 commit 9aa06d0
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions comfy_cli/standalone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
import shutil
import subprocess
import tarfile
Expand Down Expand Up @@ -63,7 +64,7 @@ def download_standalone_python(
return download_progress(url, fname, cwd=cwd)


class StandalonePython:
class StandalonePythonBase:
@staticmethod
def FromDistro(
platform: Optional[str] = None,
Expand All @@ -82,10 +83,10 @@ def FromDistro(
flavor=flavor,
cwd=cwd,
)
return StandalonePython.FromTarball(fpath, name)
return StandalonePythonBase.FromTarball(fpath, name)

@staticmethod
def FromTarball(fpath: PathLike, name: PathLike = "python"):
def FromTarball(fpath: PathLike, name: PathLike = "python") -> "StandalonePythonBase":
fpath = Path(fpath)

with tarfile.open(fpath) as tar:
Expand All @@ -103,13 +104,21 @@ def FromTarball(fpath: PathLike, name: PathLike = "python"):
tar.extractall()

shutil.move(old_rpath, rpath)
return StandalonePython(rpath=rpath)

if platform.system() == "Windows":
return StandlonePythonWindows(rpath=rpath)
return StandalonePythonUnix(rpath=rpath)

def __init__(self, rpath: PathLike):
self.rpath = Path(rpath)
self.name = self.rpath.name
self.bin = self.rpath / "bin"
self.executable = self.bin / "python"
# Determine the correct paths based on the platform
if platform.system() == "Windows":
self.bin = self.rpath
self.executable = self.bin / "python.exe"
else: # Linux and macOS
self.bin = self.rpath / "bin"
self.executable = self.bin / "python"

# paths to store package artifacts
self.cache = self.rpath / "cache"
Expand Down Expand Up @@ -209,3 +218,19 @@ def _filter(tinfo: tarfile.TarInfo):
if progress:
barProg.advance(addTar, _size)
pathProg.update(pathTar, description="")


class StandalonePythonUnix(StandalonePythonBase):
def get_bin_path(self) -> Path:
return self.rpath / "bin"

def get_executable_path(self) -> Path:
return self.bin / "python"


class StandlonePythonWindows(StandalonePythonBase):
def get_bin_path(self) -> Path:
return self.rpath

def get_executable_path(self) -> Path:
return self.bin / "python.exe"

0 comments on commit 9aa06d0

Please sign in to comment.