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

Initial apply of ruff formatting #157

Merged
merged 10 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: ruff_check

on:
push:
Expand All @@ -9,18 +9,19 @@ on:
- main

jobs:
lint:
ruff_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
- name: install ruff
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Lint with Pylint
run: pylint --disable=R **/*.py
pip install ruff
- name: lint check and then format check with ruff
run: |
ruff check
ruff format --check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/

#COMMON CONFIGs
.DS_Store
.ruff_cache
.src_port
.webpack_watch.log
*.swp
Expand Down
23 changes: 8 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.1
hooks:
- id: black
- repo: https://github.com/pylint-dev/pylint
rev: v2.16.2
hooks:
- id: pylint
args:
# Note: E0401 is disabled as pylint does not run in an environment
# where the package is installed
- --disable=R,E0401
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
52 changes: 25 additions & 27 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
[MASTER]
disable=
C0114, # missing-module-docstring
C0115, # missing-class-docstring
C0116, # missing-function-docstring
C0209, # consider-using-f-string
W0622, # redefined-builtin
W1113, # too-many-arguments
W0613, # unused-argument
W0718, # broad-exception-caught
W0511, # fixme
W0621, # redefined-outer-name
W1514, # unspecified-encoding
W0603, # global-statement
W1203, # logging-fstring-interpolation
W0212, # protected-access
C0301, # line-too-long
C0103, # invalid-name
W1510, # subprocess-run-check
W0707, # raise-missing-from
; [MASTER]
; disable=
; C0114, # missing-module-docstring
; C0115, # missing-class-docstring
; C0116, # missing-function-docstring
; C0209, # consider-using-f-string
; W0622, # redefined-builtin
; W1113, # too-many-arguments
; W0613, # unused-argument
; W0718, # broad-exception-caught
; W0511, # fixme
; W0621, # redefined-outer-name
; W1514, # unspecified-encoding
; W0603, # global-statement
; W1203, # logging-fstring-interpolation
; W0212, # protected-access
; C0301, # line-too-long
; W0707, # raise-missing-from

# TODO
W3101, # missing timeout on request
W0719, # broad-exception-raised
; # TODO
; W3101, # missing timeout on request
; W0719, # broad-exception-raised

[FORMAT]
max-line-length=120
; [FORMAT]
; max-line-length=120

[SIMILARITIES]
ignore-imports=yes
; [SIMILARITIES]
; ignore-imports=yes
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
Loading
Loading