Files

74 lines
2.2 KiB
Python

#!/usr/bin/env python3
r"""Install ComfyUI Brightwire Tools into a ComfyUI custom_nodes folder.
From the repository root:
python install.py --comfyui C:\path\to\ComfyUI
or:
python install.py --custom-nodes C:\path\to\ComfyUI\custom_nodes
"""
from __future__ import annotations
import argparse
import shutil
from pathlib import Path
PACKAGE_DIR_NAME = "ComfyUI-Brightwire-Tools"
def _ignore(_dir: str, names: list[str]) -> set[str]:
ignored: set[str] = set()
for name in names:
if name in {".git", "__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache", "brightwire_cache"}:
ignored.add(name)
elif name.endswith((".pyc", ".pyo", ".log")):
ignored.add(name)
return ignored
def install(repo_root: Path, custom_nodes: Path, force: bool = True) -> Path:
source = repo_root / "custom_nodes" / PACKAGE_DIR_NAME
if not source.exists():
raise FileNotFoundError(f"Custom node package folder not found: {source}")
custom_nodes.mkdir(parents=True, exist_ok=True)
target = custom_nodes / PACKAGE_DIR_NAME
if target.exists():
if not force:
raise FileExistsError(f"Target already exists: {target}")
shutil.rmtree(target)
shutil.copytree(source, target, ignore=_ignore)
return target
def main() -> int:
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--comfyui", type=Path, help="Path to the ComfyUI root folder")
group.add_argument("--custom-nodes", type=Path, help="Path to the ComfyUI custom_nodes folder")
args = parser.parse_args()
repo_root = Path(__file__).resolve().parent
if args.custom_nodes:
custom_nodes = args.custom_nodes.resolve()
else:
comfyui = args.comfyui.resolve()
if not comfyui.exists():
raise SystemExit(f"ComfyUI path does not exist: {comfyui}")
custom_nodes = comfyui / "custom_nodes"
target = install(repo_root, custom_nodes, force=True)
print(f"Installed Brightwire Tools to: {target}")
print("Restart ComfyUI and hard-refresh your browser.")
return 0
if __name__ == "__main__":
raise SystemExit(main())