Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions comfy_cli/command/custom_nodes/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,13 @@ def publish(
signed_url = response.signedUrl
zip_filename = NODE_ZIP_FILENAME
typer.echo("Creating zip file...")
zip_files(zip_filename)

includes = config.tool_comfy.includes if config and config.tool_comfy else []

if includes:
typer.echo(f"Including additional directories: {', '.join(includes)}")

zip_files(zip_filename, includes=includes)

# Upload the zip file to the signed URL
typer.echo("Uploading zip file...")
Expand Down Expand Up @@ -917,7 +923,13 @@ def pack():
raise typer.Exit(code=1)

zip_filename = NODE_ZIP_FILENAME
zip_files(zip_filename)
includes = config.tool_comfy.includes if config and config.tool_comfy else []

if includes:
typer.echo(f"Including additional directories: {', '.join(includes)}")

zip_files(zip_filename, includes=includes)

typer.echo(f"Created zip file: {NODE_ZIP_FILENAME}")
logging.info("Node has been packed successfully.")

Expand Down
63 changes: 42 additions & 21 deletions comfy_cli/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,60 @@ def download_file(url: str, local_filepath: pathlib.Path, headers: Optional[dict
raise DownloadException(f"Failed to download file.\n{status_reason}")


def zip_files(zip_filename):
def zip_files(zip_filename, includes=None):
"""
Zip all files in the current directory that are tracked by git.
Zip all files in the current directory that are tracked by git,
plus any additional directories specified in includes.
"""
includes = includes or []
included_paths = set()
git_files = []

try:
# Get list of git-tracked files using git ls-files
import subprocess

git_files = subprocess.check_output(["git", "ls-files"], text=True).splitlines()
# Zip only git-tracked files
with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zipf:
except (subprocess.SubprocessError, FileNotFoundError):
print("Warning: Not in a git repository or git not installed. Zipping all files.")

# Zip only git-tracked files
with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zipf:
if git_files:
for file_path in git_files:
if zip_filename in file_path:
continue
if os.path.exists(file_path):
zipf.write(file_path)
included_paths.add(file_path)
else:
print(f"File not found. Not including in zip: {file_path}")
return
except (subprocess.SubprocessError, FileNotFoundError):
print("Warning: Not in a git repository or git not installed. Zipping all files.")

with zipfile.ZipFile(zip_filename, "w", zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk("."):
if ".git" in dirs:
dirs.remove(".git")
for file in files:
file_path = os.path.join(root, file)
# Skip zipping the zip file itself
if zip_filename in file_path:
continue
relative_path = os.path.relpath(file_path, start=".")
zipf.write(file_path, relative_path)
else:
for root, dirs, files in os.walk("."):
if ".git" in dirs:
dirs.remove(".git")
for file in files:
file_path = os.path.join(root, file)
# Skip zipping the zip file itself
if zip_filename in file_path:
continue
relative_path = os.path.relpath(file_path, start=".")
zipf.write(file_path, relative_path)
included_paths.add(file_path)

for include_dir in includes:
include_dir = include_dir.lstrip('/')
if not os.path.exists(include_dir):
print(f"Warning: Included directory '{include_dir}' does not exist, creating empty directory")
zipf.writestr(f"{include_dir}/", "")
continue

for root, dirs, files in os.walk(include_dir):
for file in files:
file_path = os.path.join(root, file)
if zip_filename in file_path or file_path in included_paths:
continue
relative_path = os.path.relpath(file_path, start=".")
zipf.write(file_path, relative_path)
included_paths.add(file_path)


def upload_file_to_signed_url(signed_url: str, file_path: str):
Expand Down
2 changes: 2 additions & 0 deletions comfy_cli/registry/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def create_comfynode_config():
comfy["PublisherId"] = ""
comfy["DisplayName"] = "ComfyUI-AIT"
comfy["Icon"] = ""
comfy["includes"] = tomlkit.array()

tool.add("comfy", comfy)
document.add("tool", tool)
Expand Down Expand Up @@ -196,6 +197,7 @@ def extract_node_configuration(
display_name=comfy_data.get("DisplayName", ""),
icon=comfy_data.get("Icon", ""),
models=[Model(location=m["location"], model_url=m["model_url"]) for m in comfy_data.get("Models", [])],
includes=comfy_data.get("includes", []),
)

return PyProjectConfig(project=project, tool_comfy=comfy)
1 change: 1 addition & 0 deletions comfy_cli/registry/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ComfyConfig:
display_name: str = ""
icon: str = ""
models: List[Model] = field(default_factory=list)
includes: List[str] = field(default_factory=list)


@dataclass
Expand Down
Loading