Skip to content

Non-interactive mode #54

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

Merged
merged 6 commits into from
May 14, 2024
Merged
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
5 changes: 2 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ jobs:

- name: Run Tests
run: |
comfy --yes env
comfy tracking disable
comfy install --cpu
comfy --skip-prompt --no-enable-telemetry env
comfy --skip-prompt install --cpu
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ disable=
W0622, # redefined-builtin
W1113, # too-many-arguments
W0613, # unused-argument
W0718, # broad-exception-caught

[FORMAT]
max-line-length=120
Expand Down
97 changes: 66 additions & 31 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@
import uuid
import webbrowser
from typing import Optional
from comfy_cli.constants import GPU_OPTION

import questionary
import typer
from rich import print
from rich.console import Console
from typing_extensions import Annotated, List

from comfy_cli import constants, env_checker, logging, tracking, ui, utils
from comfy_cli.command import custom_nodes
from comfy_cli.command import install as install_inner
from comfy_cli.command.models import models as models_command
from comfy_cli.update import check_for_updates
from comfy_cli.config_manager import ConfigManager
from comfy_cli.constants import GPU_OPTION
from comfy_cli.env_checker import EnvChecker, check_comfy_server_running
from comfy_cli.update import check_for_updates
from comfy_cli.workspace_manager import (
WorkspaceManager,
check_comfy_repo,
WorkspaceType,
check_comfy_repo,
)

logging.setup_logging()
app = typer.Typer()
workspace_manager = WorkspaceManager()

console = Console()


def main():
app()
Expand Down Expand Up @@ -62,33 +65,53 @@ def help(ctx: typer.Context):
@app.callback(invoke_without_command=True)
def entry(
ctx: typer.Context,
workspace: Optional[str] = typer.Option(
default=None,
show_default=False,
help="Path to ComfyUI workspace",
callback=exclusivity_callback,
),
recent: Optional[bool] = typer.Option(
default=None,
show_default=False,
is_flag=True,
help="Execute from recent path",
callback=exclusivity_callback,
),
here: Optional[bool] = typer.Option(
default=None,
show_default=False,
is_flag=True,
help="Execute from current path",
callback=exclusivity_callback,
),
yes: bool = typer.Option(
False, "--yes", "-y", help="Enable without confirmation", is_flag=True
),
workspace: Annotated[
Optional[str],
typer.Option(
show_default=False,
help="Path to ComfyUI workspace",
callback=exclusivity_callback,
),
] = None,
recent: Annotated[
Optional[bool],
typer.Option(
show_default=False,
is_flag=True,
help="Execute from recent path",
callback=exclusivity_callback,
),
] = None,
here: Annotated[
Optional[bool],
typer.Option(
show_default=False,
is_flag=True,
help="Execute from current path",
callback=exclusivity_callback,
),
] = None,
skip_prompt: Annotated[
Optional[bool],
typer.Option(
show_default=False,
is_flag=True,
help="Do not prompt user for input, use default options",
),
] = None,
enable_telemetry: Annotated[
Optional[bool],
typer.Option(
show_default=False,
hidden=True,
is_flag=True,
help="Enable tracking",
),
] = True,
):
workspace_manager.setup_workspace_manager(workspace, here, recent)
workspace_manager.setup_workspace_manager(workspace, here, recent, skip_prompt)

tracking.prompt_tracking_consent(yes)
tracking.prompt_tracking_consent(skip_prompt, default_value=enable_telemetry)

if ctx.invoked_subcommand is None:
print(
Expand Down Expand Up @@ -172,6 +195,9 @@ def install(

comfy_path = workspace_manager.get_specified_workspace()

if comfy_path is None:
comfy_path = workspace_manager.workspace_path

if comfy_path is None:
comfy_path = utils.get_not_user_set_default_workspace()

Expand Down Expand Up @@ -234,6 +260,12 @@ def install(
"[bold yellow]Feel free to follow this thread to manually install:\nhttps://github.com/comfyanonymous/ComfyUI/discussions/476[/bold yellow]"
)

if gpu is None and not cpu:
print(
"[bold red]No GPU option selected or `--cpu` enabled, use --\[gpu option] flag (e.g. --nvidia) to pick GPU. use `--cpu` to install for CPU. Exiting...[/bold red]"
)
raise typer.Exit(code=1)

install_inner.execute(
url,
manager_url,
Expand All @@ -242,7 +274,7 @@ def install(
skip_manager,
commit=commit,
gpu=gpu,
platform=platform,
plat=platform,
skip_torch_or_directml=skip_torch_or_directml,
skip_requirement=skip_requirement,
)
Expand All @@ -266,7 +298,6 @@ def update(
)
raise typer.Exit(code=1)

_env_checker = EnvChecker()
comfy_path = workspace_manager.workspace_path

if "all" == target:
Expand Down Expand Up @@ -482,7 +513,9 @@ def which():
def env():
check_for_updates()
_env_checker = EnvChecker()
_env_checker.print()
table = _env_checker.fill_print_table()
workspace_manager.fill_print_table(table)
console.print(table)


@app.command(hidden=True)
Expand Down Expand Up @@ -510,6 +543,7 @@ def feedback():
general_satisfaction_score = ui.prompt_select(
question="On a scale of 1 to 5, how satisfied are you with the Comfy CLI tool? (1 being very dissatisfied and 5 being very satisfied)",
choices=["1", "2", "3", "4", "5"],
force_prompting=True,
)
tracking.track_event(
"feedback_general_satisfaction", {"score": general_satisfaction_score}
Expand All @@ -519,6 +553,7 @@ def feedback():
usability_satisfaction_score = ui.prompt_select(
question="On a scale of 1 to 5, how satisfied are you with the usability and user experience of the Comfy CLI tool? (1 being very dissatisfied and 5 being very satisfied)",
choices=["1", "2", "3", "4", "5"],
force_prompting=True,
)
tracking.track_event(
"feedback_usability_satisfaction", {"score": usability_satisfaction_score}
Expand Down
15 changes: 12 additions & 3 deletions comfy_cli/command/custom_nodes/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def execute_cm_cli(args, channel=None, mode=None):

print(f"Execute from: {workspace_path}")

subprocess.run(cmd, env=new_env)
res = subprocess.run(cmd, env=new_env, check=True)
if res.returncode != 0:
print(f"Failed to execute: {cmd}", file=sys.stderr)
raise typer.Exit(code=1)
workspace_manager.set_recent_workspace(workspace_path)


Expand All @@ -71,7 +74,7 @@ def validate_comfyui_manager(_env_checker):

if manager_path is None:
print(
f"[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]"
"[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]"
)
raise typer.Exit(code=1)
elif not os.path.exists(manager_path):
Expand Down Expand Up @@ -422,7 +425,13 @@ def update_node_id_cache():

new_env = os.environ.copy()
new_env["COMFYUI_PATH"] = workspace_path
subprocess.check_output(cmd, env=new_env)
res = subprocess.run(cmd, env=new_env, check=True)
if res.returncode != 0:
typer.echo(
"Failed to update node id cache.",
err=True,
)
raise typer.Exit(code=1)
except Exception:
pass

Expand Down
19 changes: 15 additions & 4 deletions comfy_cli/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import sys

from rich import print
import typer

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

workspace_manager = WorkspaceManager()


def get_os_details():
os_name = platform.system() # e.g., Linux, Darwin (macOS), Windows
Expand Down Expand Up @@ -120,13 +123,21 @@ def execute(
skip_manager: bool,
commit=None,
gpu: constants.GPU_OPTION = None,
platform: constants.OS = None,
plat: constants.OS = None,
skip_torch_or_directml: bool = False,
skip_requirement: bool = False,
*args,
**kwargs,
):
print(f"Installing from '{url}' to '{comfy_path}'")

if not workspace_manager.skip_prompting:
res = ui.prompt_confirm_action(f"Install from {url} to {comfy_path}?")

if not res:
print("Aborting...")
raise typer.Exit(code=1)

print(f"Installing from [bold yellow]'{url}'[/bold yellow] to '{comfy_path}'")

repo_dir = comfy_path
parent_path = os.path.join(repo_dir, "..")
Expand All @@ -148,7 +159,7 @@ def execute(
subprocess.run(["git", "checkout", commit])

install_comfyui_dependencies(
repo_dir, gpu, platform, skip_torch_or_directml, skip_requirement
repo_dir, gpu, plat, skip_torch_or_directml, skip_requirement
)

WorkspaceManager().set_recent_workspace(repo_dir)
Expand Down
2 changes: 2 additions & 0 deletions comfy_cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class OS(Enum):
CONFIG_KEY_INSTALL_EVENT_TRIGGERED = "install_event_triggered"
CONFIG_KEY_BACKGROUND = "background"

DEFAULT_TRACKING_VALUE = True

COMFY_LOCK_YAML_FILE = "comfy.lock.yaml"

# TODO: figure out a better way to check if this is a comfy repo
Expand Down
4 changes: 2 additions & 2 deletions comfy_cli/env_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def check(self):
self.python_version = sys.version_info

# TODO: use ui.display_table
def print(self):
def fill_print_table(self):
table = Table(":laptop_computer: Environment", "Value")
table.add_row("Python Version", format_python_version(sys.version_info))
table.add_row("Python Executable", sys.executable)
Expand All @@ -120,4 +120,4 @@ def print(self):
else:
table.add_row("Comfy Server Running", "[bold red]No[/bold red]")

console.print(table)
return table
29 changes: 16 additions & 13 deletions comfy_cli/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

from comfy_cli import logging, ui, constants
from comfy_cli.config_manager import ConfigManager
from comfy_cli.workspace_manager import WorkspaceManager

# Ignore logs from urllib3 that Mixpanel uses.
logginglib.getLogger("urllib3").setLevel(logginglib.ERROR)

MIXPANEL_TOKEN = "93aeab8962b622d431ac19800ccc9f67"
DISABLE_TELEMETRY = os.getenv("DISABLE_TELEMETRY", False)
mp = Mixpanel(MIXPANEL_TOKEN) if MIXPANEL_TOKEN else None

# Generate a unique tracing ID per command.
Expand All @@ -24,24 +24,27 @@
user_id = config_manager.get(constants.CONFIG_KEY_USER_ID)
# tracking all events for a single command
tracing_id = str(uuid.uuid4())
workspace_manager = WorkspaceManager()

app = typer.Typer()


@app.command()
def enable():
set_tracking_enabled(True)
typer.echo(f"Tracking is now {'enabled' if enable else 'disabled'}.")
typer.echo(f"Tracking is now {'enabled'}.")
init_tracking(True)


@app.command()
def disable():
set_tracking_enabled(False)
typer.echo(f"Tracking is now {'enabled' if enable else 'disabled'}.")
typer.echo(f"Tracking is now {'disabled'}.")


def track_event(event_name: str, properties: any = {}):
def track_event(event_name: str, properties: any = None):
if properties is None:
properties = {}
logging.debug(
f"tracking event called with event_name: {event_name} and properties: {properties}"
)
Expand Down Expand Up @@ -89,13 +92,13 @@ def wrapper(*args, **kwargs):
return decorator


def prompt_tracking_consent(yes: bool = False):
def prompt_tracking_consent(skip_prompt: bool = False, default_value: bool = False):
tracking_enabled = config_manager.get(constants.CONFIG_KEY_ENABLE_TRACKING)
if tracking_enabled is not None:
return

if yes:
init_tracking(True)
if skip_prompt:
init_tracking(default_value)
else:
enable_tracking = ui.prompt_confirm_action(
"Do you agree to enable tracking to improve the application?"
Expand All @@ -112,12 +115,12 @@ def init_tracking(enable_tracking: bool):
if not enable_tracking:
return

user_id = config_manager.get(constants.CONFIG_KEY_USER_ID)
logging.debug(f'User identifier for tracking user_id found: {user_id}."')
if user_id is None:
user_id = str(uuid.uuid4())
config_manager.set(constants.CONFIG_KEY_USER_ID, user_id)
logging.debug(f'Setting user identifier for tracking user_id: {user_id}."')
curr_user_id = config_manager.get(constants.CONFIG_KEY_USER_ID)
logging.debug(f'User identifier for tracking user_id found: {curr_user_id}."')
if curr_user_id is None:
curr_user_id = str(uuid.uuid4())
config_manager.set(constants.CONFIG_KEY_USER_ID, curr_user_id)
logging.debug(f'Setting user identifier for tracking user_id: {curr_user_id}."')

# Note: only called once when the user interacts with the CLI for the
# first time iff the permission is granted.
Expand Down
Loading