COMFY_DIR alone manages ComfyUI: derive the launch command from the standard venv layout
This commit is contained in:
@@ -9,13 +9,54 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ComfyLayout returns the interpreter and script path of a standard ComfyUI
|
||||
// venv install rooted at dir for the given GOOS: .venv\Scripts\python.exe
|
||||
// on Windows, .venv/bin/python elsewhere. The script is main.py — either in
|
||||
// a ComfyUI subdirectory or directly under dir, whichever exists (the
|
||||
// subdirectory form wins ties and is the default when neither exists yet,
|
||||
// so the caller's missing-file warning points at the documented layout).
|
||||
func ComfyLayout(goos, dir string) (python, script string) {
|
||||
if goos == "windows" {
|
||||
python = filepath.Join(dir, ".venv", "Scripts", "python.exe")
|
||||
} else {
|
||||
python = filepath.Join(dir, ".venv", "bin", "python")
|
||||
}
|
||||
script = filepath.Join(dir, "ComfyUI", "main.py")
|
||||
if _, err := os.Stat(script); err != nil {
|
||||
if _, err := os.Stat(filepath.Join(dir, "main.py")); err == nil {
|
||||
script = filepath.Join(dir, "main.py")
|
||||
}
|
||||
}
|
||||
return python, script
|
||||
}
|
||||
|
||||
// DefaultComfyCommand builds the launch command for the standard venv
|
||||
// layout (see ComfyLayout): the script is passed relative to dir so dir
|
||||
// stays the working directory, and --port is taken from comfyURL when the
|
||||
// URL carries one.
|
||||
func DefaultComfyCommand(goos, dir, comfyURL string) string {
|
||||
python, script := ComfyLayout(goos, dir)
|
||||
rel, err := filepath.Rel(dir, script)
|
||||
if err != nil {
|
||||
rel = script
|
||||
}
|
||||
cmd := `"` + python + `" ` + rel
|
||||
if u, err := url.Parse(comfyURL); err == nil && u.Port() != "" {
|
||||
cmd += " --port " + u.Port()
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Process is one managed child process.
|
||||
type Process struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user