Skip to content

Commit

Permalink
Initial apply of ruff formatting (#157)
Browse files Browse the repository at this point in the history
* initial apply of ruff lint/format via `pre-commit run --all-files`

* fixed all initial non-autofixable complaints of new linter `ruff check`
  • Loading branch information
telamonian authored Aug 20, 2024
1 parent d7c0f52 commit b7cb2a3
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 576 deletions.
87 changes: 23 additions & 64 deletions comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from rich import print
from rich.console import Console
from typing_extensions import Annotated, List
from comfy_cli import constants, env_checker, logging, tracking, utils, ui

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 import run as run_inner
Expand Down Expand Up @@ -44,9 +45,7 @@ def validate(self, _ctx: typer.Context, param: typer.CallbackParam, value: str):
if value is not None and param.name not in self.group:
self.group.append(param.name)
if len(self.group) > 1:
raise typer.BadParameter(
f"option `{param.name}` is mutually exclusive with option `{self.group.pop()}`"
)
raise typer.BadParameter(f"option `{param.name}` is mutually exclusive with option `{self.group.pop()}`")
return value


Expand Down Expand Up @@ -123,9 +122,7 @@ def entry(
tracking.prompt_tracking_consent(skip_prompt, default_value=enable_telemetry)

if ctx.invoked_subcommand is None:
print(
"[bold yellow]Welcome to Comfy CLI![/bold yellow]: https://github.com/Comfy-Org/comfy-cli"
)
print("[bold yellow]Welcome to Comfy CLI![/bold yellow]: https://github.com/Comfy-Org/comfy-cli")
print(ctx.get_help())
ctx.exit()

Expand Down Expand Up @@ -180,9 +177,7 @@ def install(
callback=g_gpu_exclusivity.validate,
),
] = None,
cuda_version: Annotated[
CUDAVersion, typer.Option(show_default=True)
] = CUDAVersion.v12_1,
cuda_version: Annotated[CUDAVersion, typer.Option(show_default=True)] = CUDAVersion.v12_1,
amd: Annotated[
Optional[bool],
typer.Option(
Expand Down Expand Up @@ -216,9 +211,7 @@ def install(
callback=g_gpu_exclusivity.validate,
),
] = None,
commit: Annotated[
Optional[str], typer.Option(help="Specify commit hash for ComfyUI")
] = None,
commit: Annotated[Optional[str], typer.Option(help="Specify commit hash for ComfyUI")] = None,
fast_deps: Annotated[
Optional[bool],
typer.Option(
Expand All @@ -235,9 +228,7 @@ def install(

is_comfy_installed_at_path, repo_dir = check_comfy_repo(comfy_path)
if is_comfy_installed_at_path and not restore:
print(
f"[bold red]ComfyUI is already installed at the specified path:[/bold red] {comfy_path}\n"
)
print(f"[bold red]ComfyUI is already installed at the specified path:[/bold red] {comfy_path}\n")
print(
"[bold yellow]If you want to restore dependencies, add the '--restore' option.[/bold yellow]",
)
Expand All @@ -247,12 +238,8 @@ def install(
comfy_path = str(repo_dir.working_dir)

if checker.python_version.major < 3 or checker.python_version.minor < 9:
print(
"[bold red]Python version 3.9 or higher is required to run ComfyUI.[/bold red]"
)
print(
f"You are currently using Python version {env_checker.format_python_version(checker.python_version)}."
)
print("[bold red]Python version 3.9 or higher is required to run ComfyUI.[/bold red]")
print(f"You are currently using Python version {env_checker.format_python_version(checker.python_version)}.")
platform = utils.get_os()
if cpu:
print("[bold yellow]Installing for CPU[/bold yellow]")
Expand All @@ -274,9 +261,7 @@ def install(
return None

if nvidia and platform == constants.OS.MACOS:
print(
"[bold red]Nvidia GPU is never on MacOS. What are you smoking? 🤔[/bold red]"
)
print("[bold red]Nvidia GPU is never on MacOS. What are you smoking? 🤔[/bold red]")
raise typer.Exit(code=1)

if platform != constants.OS.MACOS and m_series:
Expand Down Expand Up @@ -305,14 +290,10 @@ def install(
)

if gpu == GPU_OPTION.INTEL_ARC:
print(
"[bold yellow]Installing on Intel ARC is not yet completely supported[/bold yellow]"
)
print("[bold yellow]Installing on Intel ARC is not yet completely supported[/bold yellow]")
env_check = env_checker.EnvChecker()
if env_check.conda_env is None:
print(
"[bold red]Intel ARC support requires conda environment to be activated.[/bold red]"
)
print("[bold red]Intel ARC support requires conda environment to be activated.[/bold red]")
raise typer.Exit(code=1)
if intel_arc is None:
confirm_result = ui.prompt_confirm_action(
Expand Down Expand Up @@ -381,9 +362,7 @@ def update(
custom_nodes.command.update_node_id_cache()


@app.command(
help="Run API workflow file using the ComfyUI launched by `comfy launch --background`"
)
@app.command(help="Run API workflow file using the ComfyUI launched by `comfy launch --background`")
@tracking.track_command()
def run(
workflow: Annotated[str, typer.Option(help="Path to the workflow API json file.")],
Expand All @@ -397,9 +376,7 @@ def run(
] = False,
host: Annotated[
Optional[str],
typer.Option(
help="The IP/hostname where the ComfyUI instance is running, e.g. 127.0.0.1 or localhost."
),
typer.Option(help="The IP/hostname where the ComfyUI instance is running, e.g. 127.0.0.1 or localhost."),
] = None,
port: Annotated[
Optional[int],
Expand Down Expand Up @@ -438,9 +415,7 @@ def run(

def validate_comfyui(_env_checker):
if _env_checker.comfy_repo is None:
print(
"[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]"
)
print("[bold red]If ComfyUI is not installed, this feature cannot be used.[/bold red]")
raise typer.Exit(code=1)


Expand All @@ -460,19 +435,15 @@ def stop():
if not is_killed:
print("[bold red]Failed to stop ComfyUI in the background.[/bold red]\n")
else:
print(
f"[bold yellow]Background ComfyUI is stopped.[/bold yellow] ({bg_info[0]}:{bg_info[1]})"
)
print(f"[bold yellow]Background ComfyUI is stopped.[/bold yellow] ({bg_info[0]}:{bg_info[1]})")

ConfigManager().remove_background()


@app.command(help="Launch ComfyUI: ?[--background] ?[-- <extra args ...>]")
@tracking.track_command()
def launch(
background: Annotated[
bool, typer.Option(help="Launch ComfyUI in background")
] = False,
background: Annotated[bool, typer.Option(help="Launch ComfyUI in background")] = False,
extra: List[str] = typer.Argument(None),
):
launch_command(background, extra)
Expand All @@ -482,9 +453,7 @@ def launch(
@tracking.track_command()
def set_default(
workspace_path: str,
launch_extras: Annotated[
str, typer.Option(help="Specify extra options for launch")
] = "",
launch_extras: Annotated[str, typer.Option(help="Specify extra options for launch")] = "",
):
comfy_path = os.path.abspath(os.path.expanduser(workspace_path))

Expand Down Expand Up @@ -536,17 +505,13 @@ def env():
@app.command(hidden=True)
@tracking.track_command()
def nodes():
print(
"\n[bold red] No such command, did you mean 'comfy node' instead?[/bold red]\n"
)
print("\n[bold red] No such command, did you mean 'comfy node' instead?[/bold red]\n")


@app.command(hidden=True)
@tracking.track_command()
def models():
print(
"\n[bold red] No such command, did you mean 'comfy model' instead?[/bold red]\n"
)
print("\n[bold red] No such command, did you mean 'comfy model' instead?[/bold red]\n")


@app.command(help="Provide feedback on the Comfy CLI tool.")
Expand All @@ -560,24 +525,18 @@ def feedback():
choices=["1", "2", "3", "4", "5"],
force_prompting=True,
)
tracking.track_event(
"feedback_general_satisfaction", {"score": general_satisfaction_score}
)
tracking.track_event("feedback_general_satisfaction", {"score": general_satisfaction_score})

# Usability and User Experience
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}
)
tracking.track_event("feedback_usability_satisfaction", {"score": usability_satisfaction_score})

# Additional Feature-Specific Feedback
if questionary.confirm(
"Do you want to provide additional feature-specific feedback on our GitHub page?"
).ask():
if questionary.confirm("Do you want to provide additional feature-specific feedback on our GitHub page?").ask():
tracking.track_event("feedback_additional")
webbrowser.open("https://github.com/Comfy-Org/comfy-cli/issues/new/choose")

Expand Down
2 changes: 2 additions & 0 deletions comfy_cli/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import custom_nodes, install

__all__ = ["custom_nodes", "install"]
2 changes: 2 additions & 0 deletions comfy_cli/command/custom_nodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .command import app, manager_app

__all__ = ["app", "manager_app"]
16 changes: 4 additions & 12 deletions comfy_cli/command/custom_nodes/bisect_custom_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def set_custom_node_enabled_states(self):
execute_cm_cli(["disable", *self.inactive_nodes])

def __str__(self):
active_list = "\n".join(
[f"{i + 1:3}. {node}" for i, node in enumerate(self.active)]
)
active_list = "\n".join([f"{i + 1:3}. {node}" for i, node in enumerate(self.active)])
return f"""BisectState(status={self.status})
set of nodes with culprit: {len(self.range)}
set of nodes to test: {len(self.active)}
Expand All @@ -131,9 +129,7 @@ def __str__(self):
+ "?[-- <extra args ...>]"
)
def start(
pinned_nodes: Annotated[
str, typer.Option(help="Pinned nodes always enable during the bisect")
] = "",
pinned_nodes: Annotated[str, typer.Option(help="Pinned nodes always enable during the bisect")] = "",
extra: list[str] = typer.Argument(None),
):
"""Start a new bisect session. The initial state is bad with all custom nodes
Expand Down Expand Up @@ -171,9 +167,7 @@ def start(
bad()


@bisect_app.command(
help="Mark the current active set as good, indicating the problem is outside the test set."
)
@bisect_app.command(help="Mark the current active set as good, indicating the problem is outside the test set.")
def good():
state = BisectState.load()
if state.status != "running":
Expand All @@ -192,9 +186,7 @@ def good():
launch_command(background=False, extra=state.launch_args)


@bisect_app.command(
help="Mark the current active set as bad, indicating the problem is within the test set."
)
@bisect_app.command(help="Mark the current active set as bad, indicating the problem is within the test set.")
def bad():
state = BisectState.load()
if state.status != "running":
Expand Down
17 changes: 6 additions & 11 deletions comfy_cli/command/custom_nodes/cm_cli_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

# set of commands that invalidate (ie require an update of) dependencies after they are run
_dependency_cmds = {
'install',
'reinstall',
"install",
"reinstall",
}


def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None:
_config_manager = ConfigManager()

Expand All @@ -29,9 +30,7 @@ def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None
print("\n[bold red]ComfyUI path is not resolved.[/bold red]\n", file=sys.stderr)
raise typer.Exit(code=1)

cm_cli_path = os.path.join(
workspace_path, "custom_nodes", "ComfyUI-Manager", "cm-cli.py"
)
cm_cli_path = os.path.join(workspace_path, "custom_nodes", "ComfyUI-Manager", "cm-cli.py")
if not os.path.exists(cm_cli_path):
print(
f"\n[bold red]ComfyUI-Manager not found: {cm_cli_path}[/bold red]\n",
Expand All @@ -51,18 +50,14 @@ def execute_cm_cli(args, channel=None, fast_deps=False, mode=None) -> str | None
cmd += ["--mode", mode]

new_env = os.environ.copy()
session_path = os.path.join(
_config_manager.get_config_path(), "tmp", str(uuid.uuid4())
)
session_path = os.path.join(_config_manager.get_config_path(), "tmp", str(uuid.uuid4()))
new_env["__COMFY_CLI_SESSION__"] = session_path
new_env["COMFYUI_PATH"] = workspace_path

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

try:
result = subprocess.run(
cmd, env=new_env, check=True, capture_output=True, text=True
)
result = subprocess.run(cmd, env=new_env, check=True, capture_output=True, text=True)
print(result.stdout)

if fast_deps and args[0] in _dependency_cmds:
Expand Down
Loading

0 comments on commit b7cb2a3

Please sign in to comment.