Skip to content

Commit 41de8cd

Browse files
authored
update ruff, enable PyUpgrade rule (#303)
1 parent 9745e19 commit 41de8cd

File tree

19 files changed

+70
-73
lines changed

19 files changed

+70
-73
lines changed

.github/.codecov.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
codecov:
2+
allow_coverage_offsets: true # Avoid "Missing base report" due to committing with "[CI skip]"
3+
14
comment:
2-
require_changes: true
35
layout: "diff, files"
46

57
coverage:
68
status:
79
project:
810
default:
9-
target: auto
10-
threshold: 1%
11-
patch: off
11+
threshold: 0.5%

.github/workflows/pytest.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ jobs:
3333
pytest --cov=comfy_cli --cov-report=xml .
3434
3535
- name: Upload coverage to Codecov
36-
uses: codecov/codecov-action@v4
36+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
3737
with:
3838
token: ${{ secrets.CODECOV_TOKEN }}
3939
files: ./coverage.xml
4040
flags: unittests
4141
name: codecov-umbrella
4242
fail_ci_if_error: true
43+
verbose: true

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
(^.*\.(json|txt)$)
1515
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.6.1
17+
rev: v0.12.4
1818
hooks:
1919
# Run the linter.
2020
- id: ruff

comfy_cli/cmdline.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
import subprocess
33
import sys
44
import webbrowser
5-
from typing import Optional
5+
from typing import Annotated, Optional
66

77
import questionary
88
import typer
99
from rich import print as rprint
1010
from rich.console import Console
11-
from typing_extensions import Annotated, List
1211

1312
from comfy_cli import constants, env_checker, logging, tracking, ui, utils
1413
from comfy_cli.command import custom_nodes
@@ -487,7 +486,7 @@ def stop():
487486
@tracking.track_command()
488487
def launch(
489488
background: Annotated[bool, typer.Option(help="Launch ComfyUI in background")] = False,
490-
extra: List[str] = typer.Argument(None),
489+
extra: list[str] = typer.Argument(None),
491490
):
492491
launch_command(background, extra)
493492

comfy_cli/command/custom_nodes/bisect_custom_nodes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import json
44
import os
55
from pathlib import Path
6-
from typing import Literal, NamedTuple
6+
from typing import Annotated, Literal, NamedTuple
77

88
import typer
9-
from typing_extensions import Annotated
109

1110
from comfy_cli.command.custom_nodes.cm_cli_util import execute_cm_cli
1211
from comfy_cli.command.launch import launch as launch_command

comfy_cli/command/custom_nodes/command.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
import subprocess
55
import sys
66
import uuid
7-
from typing import Optional
7+
from typing import Annotated, Optional
88

99
import typer
1010
from rich import print
1111
from rich.console import Console
12-
from typing_extensions import Annotated, List
1312

1413
from comfy_cli import logging, tracking, ui, utils
1514
from comfy_cli.command.custom_nodes.bisect_custom_nodes import bisect_app
@@ -151,7 +150,7 @@ def execute_install_script(repo_path):
151150
# import pdb
152151
# pdb.set_trace()
153152
print("Install: pip packages")
154-
with open(requirements_path, "r", encoding="utf-8") as requirements_file:
153+
with open(requirements_path, encoding="utf-8") as requirements_file:
155154
for line in requirements_file:
156155
# From Yoland: disable pip override
157156
# package_name = remap_pip_package(line.strip())
@@ -269,7 +268,7 @@ def node_completer(incomplete: str) -> list[str]:
269268
config_manager = ConfigManager()
270269
tmp_path = os.path.join(config_manager.get_config_path(), "tmp", "node-cache.list")
271270

272-
with open(tmp_path, "r", encoding="UTF-8", errors="ignore") as cache_file:
271+
with open(tmp_path, encoding="UTF-8", errors="ignore") as cache_file:
273272
return [node_id for node_id in cache_file.readlines() if node_id.startswith(incomplete)]
274273

275274
except Exception:
@@ -285,7 +284,7 @@ def node_or_all_completer(incomplete: str) -> list[str]:
285284
if "all".startswith(incomplete):
286285
all_opt = ["all"]
287286

288-
with open(tmp_path, "r", encoding="UTF-8", errors="ignore") as cache_file:
287+
with open(tmp_path, encoding="UTF-8", errors="ignore") as cache_file:
289288
return [node_id for node_id in cache_file.readlines() if node_id.startswith(incomplete)] + all_opt
290289

291290
except Exception:
@@ -384,7 +383,7 @@ def simple_show(
384383
@app.command(help="Install custom nodes")
385384
@tracking.track_command("node")
386385
def install(
387-
nodes: List[str] = typer.Argument(..., help="List of custom nodes to install", autocompletion=node_completer),
386+
nodes: list[str] = typer.Argument(..., help="List of custom nodes to install", autocompletion=node_completer),
388387
channel: Annotated[
389388
Optional[str],
390389
typer.Option(
@@ -431,7 +430,7 @@ def install(
431430
@app.command(help="Reinstall custom nodes")
432431
@tracking.track_command("node")
433432
def reinstall(
434-
nodes: List[str] = typer.Argument(..., help="List of custom nodes to reinstall", autocompletion=node_completer),
433+
nodes: list[str] = typer.Argument(..., help="List of custom nodes to reinstall", autocompletion=node_completer),
435434
channel: Annotated[
436435
Optional[str],
437436
typer.Option(
@@ -466,7 +465,7 @@ def reinstall(
466465
@app.command(help="Uninstall custom nodes")
467466
@tracking.track_command("node")
468467
def uninstall(
469-
nodes: List[str] = typer.Argument(..., help="List of custom nodes to uninstall", autocompletion=node_completer),
468+
nodes: list[str] = typer.Argument(..., help="List of custom nodes to uninstall", autocompletion=node_completer),
470469
channel: Annotated[
471470
Optional[str],
472471
typer.Option(
@@ -512,7 +511,7 @@ def update_node_id_cache():
512511
@app.command(help="Update custom nodes or ComfyUI")
513512
@tracking.track_command("node")
514513
def update(
515-
nodes: List[str] = typer.Argument(
514+
nodes: list[str] = typer.Argument(
516515
...,
517516
help="[all|List of custom nodes to update]",
518517
autocompletion=node_or_all_completer,
@@ -541,7 +540,7 @@ def update(
541540
@app.command(help="Disable custom nodes")
542541
@tracking.track_command("node")
543542
def disable(
544-
nodes: List[str] = typer.Argument(
543+
nodes: list[str] = typer.Argument(
545544
...,
546545
help="[all|List of custom nodes to disable]",
547546
autocompletion=node_or_all_completer,
@@ -568,7 +567,7 @@ def disable(
568567
@app.command(help="Enable custom nodes")
569568
@tracking.track_command("node")
570569
def enable(
571-
nodes: List[str] = typer.Argument(
570+
nodes: list[str] = typer.Argument(
572571
...,
573572
help="[all|List of custom nodes to enable]",
574573
autocompletion=node_or_all_completer,
@@ -595,7 +594,7 @@ def enable(
595594
@app.command(help="Fix dependencies of custom nodes")
596595
@tracking.track_command("node")
597596
def fix(
598-
nodes: List[str] = typer.Argument(
597+
nodes: list[str] = typer.Argument(
599598
...,
600599
help="[all|List of custom nodes to fix]",
601600
autocompletion=node_or_all_completer,

comfy_cli/command/install.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import platform
33
import subprocess
44
import sys
5-
from typing import Dict, List, Optional, TypedDict
5+
from typing import Optional, TypedDict
66
from urllib.parse import urlparse
77

88
import requests
@@ -389,7 +389,7 @@ def handle_github_rate_limit(response):
389389
raise GitHubRateLimitError(message)
390390

391391

392-
def fetch_github_releases(repo_owner: str, repo_name: str) -> List[Dict[str, str]]:
392+
def fetch_github_releases(repo_owner: str, repo_name: str) -> list[dict[str, str]]:
393393
"""
394394
Fetch the list of releases from the GitHub API.
395395
Handles rate limiting by logging the wait time.
@@ -425,11 +425,11 @@ class GithubRelease(TypedDict):
425425
download_url: str
426426

427427

428-
def parse_releases(releases: List[Dict[str, str]]) -> List[GithubRelease]:
428+
def parse_releases(releases: list[dict[str, str]]) -> list[GithubRelease]:
429429
"""
430430
Parse the list of releases fetched from the GitHub API into a list of GithubRelease objects.
431431
"""
432-
parsed_releases: List[GithubRelease] = []
432+
parsed_releases: list[GithubRelease] = []
433433
for release in releases:
434434
tag = release["tag_name"]
435435
if tag.lower() in ["latest", "nightly"]:
@@ -441,7 +441,7 @@ def parse_releases(releases: List[Dict[str, str]]) -> List[GithubRelease]:
441441
return parsed_releases
442442

443443

444-
def select_version(releases: List[GithubRelease], version: str) -> Optional[GithubRelease]:
444+
def select_version(releases: list[GithubRelease], version: str) -> Optional[GithubRelease]:
445445
"""
446446
Given a list of Github releases, select the release that matches the specified version.
447447
"""

comfy_cli/command/models/models.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import os
22
import pathlib
33
import sys
4-
from typing import List, Optional, Tuple
4+
from typing import Annotated, Optional
55
from urllib.parse import unquote, urlparse
66

77
import requests
88
import typer
99
from rich import print
10-
from typing_extensions import Annotated
1110

1211
from comfy_cli import constants, tracking, ui
1312
from comfy_cli.config_manager import ConfigManager
@@ -39,7 +38,7 @@ def potentially_strip_param_url(path_name: str) -> str:
3938
return path_name
4039

4140

42-
def check_huggingface_url(url: str) -> Tuple[bool, Optional[str], Optional[str], Optional[str], Optional[str]]:
41+
def check_huggingface_url(url: str) -> tuple[bool, Optional[str], Optional[str], Optional[str], Optional[str]]:
4342
"""
4443
Check if the given URL is a Hugging Face URL and extract relevant information.
4544
@@ -76,7 +75,7 @@ def check_huggingface_url(url: str) -> Tuple[bool, Optional[str], Optional[str],
7675
return True, repo_id, filename, folder_name, branch_name
7776

7877

79-
def check_civitai_url(url: str) -> Tuple[bool, bool, int, int]:
78+
def check_civitai_url(url: str) -> tuple[bool, bool, int, int]:
8079
"""
8180
Returns:
8281
is_civitai_model_url: True if the url is a civitai model url
@@ -314,7 +313,7 @@ def remove(
314313
help="The relative path from the current workspace where the models are stored.",
315314
show_default=True,
316315
),
317-
model_names: Optional[List[str]] = typer.Option(
316+
model_names: Optional[list[str]] = typer.Option(
318317
None,
319318
help="List of model filenames to delete, separated by spaces",
320319
show_default=False,

comfy_cli/command/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_renderables(self):
9898
)
9999

100100
for task in self.tasks:
101-
percent = "[progress.percentage]{task.percentage:>3.0f}%".format(task=task)
101+
percent = "[progress.percentage]{task.percentage:>3.0f}%".format(task=task) # noqa
102102
if task.fields.get("progress_type") == "overall":
103103
overall_table = Table.grid(*table_columns, padding=(0, 1), expand=self.expand)
104104
overall_table.add_row(BarColumn().render(task), percent, TimeElapsedColumn().render(task))

comfy_cli/config_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import configparser
22
import os
33
from importlib.metadata import version
4-
from typing import Optional, Tuple
4+
from typing import Optional
55

66
from comfy_cli import constants, logging
77
from comfy_cli.utils import get_os, is_running, singleton
88

99

1010
@singleton
11-
class ConfigManager(object):
11+
class ConfigManager:
1212
def __init__(self):
1313
self.config = configparser.ConfigParser()
14-
self.background: Optional[Tuple[str, int, int]] = None
14+
self.background: Optional[tuple[str, int, int]] = None
1515
self.load()
1616

1717
@staticmethod

0 commit comments

Comments
 (0)