Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check_comfy_repo #108

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import webbrowser
from typing import Optional

import git
import questionary
import typer
from rich import print
Expand All @@ -27,7 +28,7 @@
from comfy_cli.workspace_manager import (
WorkspaceManager,
WorkspaceType,
check_comfy_repo,
get_comfy_repo,
)

logging.setup_logging()
Expand Down Expand Up @@ -230,8 +231,8 @@ def install(
if comfy_path is None:
comfy_path = utils.get_not_user_set_default_workspace()

is_comfy_path, repo_dir = check_comfy_repo(comfy_path)
if is_comfy_path and not restore:
comfy_repo: git.Repo = get_comfy_repo(comfy_path)
if comfy_repo and not restore:
print(
f"[bold red]ComfyUI is already installed at the specified path:[/bold red] {comfy_path}\n"
)
Expand All @@ -240,8 +241,8 @@ def install(
)
raise typer.Exit(code=1)

if repo_dir is not None:
comfy_path = str(repo_dir.working_dir)
if comfy_repo is not None:
comfy_path = str(comfy_repo.working_dir)

if checker.python_version.major < 3 or checker.python_version.minor < 9:
print(
Expand Down Expand Up @@ -707,8 +708,8 @@ def set_default(
)
raise typer.Exit(code=1)

is_comfy_repo, comfy_repo = check_comfy_repo(comfy_path)
if not is_comfy_repo:
comfy_repo = get_comfy_repo(comfy_path)
if not comfy_repo:
print(
f"\nSpecified path is not a ComfyUI path: {comfy_path}.\n",
file=sys.stderr,
Expand Down
4 changes: 2 additions & 2 deletions comfy_cli/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from comfy_cli import constants, ui, utils
from comfy_cli.constants import GPU_OPTION
from comfy_cli.workspace_manager import WorkspaceManager, check_comfy_repo
from comfy_cli.workspace_manager import WorkspaceManager, get_comfy_repo
from comfy_cli.command.custom_nodes.command import update_node_id_cache

workspace_manager = WorkspaceManager()
Expand Down Expand Up @@ -190,7 +190,7 @@ def execute(

if not os.path.exists(repo_dir):
subprocess.run(["git", "clone", url, repo_dir])
elif not check_comfy_repo(repo_dir)[0]:
elif not get_comfy_repo(repo_dir):
print(
f"[bold red]'{repo_dir}' already exists. But it is an invalid ComfyUI repository. Remove it and retry.[/bold red]"
)
Expand Down
37 changes: 23 additions & 14 deletions comfy_cli/workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ class ComfyLockYAMLStruct:
custom_nodes: List[CustomNode] = field(default_factory=list)


def check_comfy_repo(path):
def get_comfy_repo(path: str) -> Optional[git.Repo]:
"""
Check if the given path is a Comfy repository.

Args:
path (str): The path to check.

Returns:
Optional[str]: The repository object if the path is a Comfy repository, otherwise None.
"""
if not os.path.exists(path):
return False, None
return None
try:
repo = git.Repo(path, search_parent_directories=True)
path_is_comfy_repo = any(
Expand All @@ -76,13 +85,13 @@ def check_comfy_repo(path):
pass

if path_is_comfy_repo:
return path_is_comfy_repo, repo
return repo
else:
return False, None
return None
# Not in a git repo at all
# pylint: disable=E1101 # no-member
except git.exc.InvalidGitRepositoryError:
return False, None
return None


# Generate and update this following method using chatGPT
Expand Down Expand Up @@ -221,7 +230,7 @@ def get_workspace_path(self) -> Tuple[str, WorkspaceType]:
# Check for explicitly specified workspace first
specified_workspace = self.get_specified_workspace()
if specified_workspace:
if check_comfy_repo(specified_workspace):
if get_comfy_repo(specified_workspace):
return specified_workspace, WorkspaceType.SPECIFIED

print(
Expand All @@ -235,7 +244,7 @@ def get_workspace_path(self) -> Tuple[str, WorkspaceType]:
constants.CONFIG_KEY_RECENT_WORKSPACE
)
if recent_workspace:
if check_comfy_repo(recent_workspace):
if get_comfy_repo(recent_workspace):
return recent_workspace, WorkspaceType.RECENT
else:
print(
Expand All @@ -251,8 +260,8 @@ def get_workspace_path(self) -> Tuple[str, WorkspaceType]:
# Check for current workspace if requested
if self.use_here:
current_directory = os.getcwd()
found_comfy_repo, comfy_repo = check_comfy_repo(current_directory)
if found_comfy_repo:
comfy_repo = get_comfy_repo(current_directory)
if comfy_repo:
return comfy_repo.working_dir, WorkspaceType.CURRENT_DIR

print(
Expand All @@ -263,32 +272,32 @@ def get_workspace_path(self) -> Tuple[str, WorkspaceType]:
# Check the current directory for a ComfyUI
if self.use_here is None:
current_directory = os.getcwd()
found_comfy_repo, comfy_repo = check_comfy_repo(
comfy_repo = get_comfy_repo(
os.path.join(current_directory)
)
# If it's in a sub dir of the ComfyUI repo, get the repo working dir
if found_comfy_repo:
if comfy_repo:
return comfy_repo.working_dir, WorkspaceType.CURRENT_DIR

# Check for user-set default workspace
default_workspace = self.config_manager.get(
constants.CONFIG_KEY_DEFAULT_WORKSPACE
)

if default_workspace and check_comfy_repo(default_workspace)[0]:
if default_workspace and get_comfy_repo(default_workspace):
return default_workspace, WorkspaceType.DEFAULT

# Fallback to the most recent workspace if it exists
if self.use_recent is None:
recent_workspace = self.config_manager.get(
constants.CONFIG_KEY_RECENT_WORKSPACE
)
if recent_workspace and check_comfy_repo(recent_workspace)[0]:
if recent_workspace and get_comfy_repo(recent_workspace):
return recent_workspace, WorkspaceType.RECENT

# Check for comfy-cli default workspace
default_workspace = utils.get_not_user_set_default_workspace()
if check_comfy_repo(default_workspace)[0]:
if get_comfy_repo(default_workspace):
return default_workspace, WorkspaceType.DEFAULT

return None, WorkspaceType.NOT_FOUND
Expand Down
Loading