mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-09 06:04:31 +08:00
refactor: ruff
This commit is contained in:
parent
222254896c
commit
46a6afcc19
@ -3,10 +3,8 @@ import sys
|
||||
import traceback
|
||||
import json
|
||||
import asyncio
|
||||
import subprocess
|
||||
import concurrent
|
||||
import threading
|
||||
import yaml
|
||||
from typing import Optional
|
||||
|
||||
import typer
|
||||
|
||||
@ -15,7 +15,7 @@ from git.remote import RemoteProgress
|
||||
comfy_path = os.environ.get('COMFYUI_PATH')
|
||||
|
||||
if comfy_path is None:
|
||||
print(f"\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
|
||||
print("\n[bold yellow]WARN: The `COMFYUI_PATH` environment variable is not set. Assuming `custom_nodes/ComfyUI-Manager/../../` as the ComfyUI path.[/bold yellow]", file=sys.stderr)
|
||||
comfy_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
from manager_util import *
|
||||
import zipfile
|
||||
import requests
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
import manager_util
|
||||
|
||||
base_url = "https://api.comfy.org"
|
||||
|
||||
@ -10,7 +9,7 @@ base_url = "https://api.comfy.org"
|
||||
async def get_cnr_data(page=1, limit=1000, cache_mode=True):
|
||||
try:
|
||||
uri = f'{base_url}/nodes?page={page}&limit={limit}'
|
||||
json_obj = await get_data_with_cache(uri, cache_mode=cache_mode)
|
||||
json_obj = await manager_util.get_data_with_cache(uri, cache_mode=cache_mode)
|
||||
|
||||
for v in json_obj['nodes']:
|
||||
if 'latest_version' not in v:
|
||||
@ -19,7 +18,7 @@ async def get_cnr_data(page=1, limit=1000, cache_mode=True):
|
||||
return json_obj['nodes']
|
||||
except:
|
||||
res = {}
|
||||
print(f"Cannot connect to comfyregistry.")
|
||||
print("Cannot connect to comfyregistry.")
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@ -112,8 +112,8 @@ def check_invalid_nodes():
|
||||
check(disabled_dir)
|
||||
|
||||
if len(invalid_nodes):
|
||||
print(f"\n-------------------- ComfyUI-Manager invalid nodes notice ----------------")
|
||||
print(f"\nNodes requiring reinstallation have been detected:\n(Directly delete the corresponding path and reinstall.)\n")
|
||||
print("\n-------------------- ComfyUI-Manager invalid nodes notice ----------------")
|
||||
print("\nNodes requiring reinstallation have been detected:\n(Directly delete the corresponding path and reinstall.)\n")
|
||||
|
||||
for x in invalid_nodes.values():
|
||||
print(x)
|
||||
@ -780,7 +780,7 @@ class UnifiedManager:
|
||||
|
||||
if os.path.exists(install_script_path) and install_script_path not in self.processed_install:
|
||||
self.processed_install.add(install_script_path)
|
||||
print(f"Install: install script")
|
||||
print("Install: install script")
|
||||
install_cmd = [sys.executable, "install.py"]
|
||||
return try_install_script(url, repo_path, install_cmd, instant_execution=instant_execution)
|
||||
|
||||
@ -1230,16 +1230,16 @@ class UnifiedManager:
|
||||
remote.fetch()
|
||||
except Exception as e:
|
||||
if 'detected dubious' in str(e):
|
||||
print(f"[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository")
|
||||
print("[ComfyUI-Manager] Try fixing 'dubious repository' error on 'ComfyUI' repository")
|
||||
safedir_path = comfy_path.replace('\\', '/')
|
||||
subprocess.run(['git', 'config', '--global', '--add', 'safe.directory', safedir_path])
|
||||
try:
|
||||
remote.fetch()
|
||||
except Exception:
|
||||
print(f"\n[ComfyUI-Manager] Failed to fixing repository setup. Please execute this command on cmd: \n"
|
||||
f"-----------------------------------------------------------------------------------------\n"
|
||||
print("\n[ComfyUI-Manager] Failed to fixing repository setup. Please execute this command on cmd: \n"
|
||||
"-----------------------------------------------------------------------------------------\n"
|
||||
f'git config --global --add safe.directory "{safedir_path}"\n'
|
||||
f"-----------------------------------------------------------------------------------------\n")
|
||||
"-----------------------------------------------------------------------------------------\n")
|
||||
|
||||
commit_hash = repo.head.commit.hexsha
|
||||
remote_commit_hash = repo.refs[f'{remote_name}/{branch_name}'].object.hexsha
|
||||
@ -1360,7 +1360,7 @@ class UnifiedManager:
|
||||
await self.reload('cache')
|
||||
await self.get_custom_nodes('default', 'cache')
|
||||
|
||||
print(f"Migration: STAGE 1")
|
||||
print("Migration: STAGE 1")
|
||||
moves = []
|
||||
|
||||
# migrate nightly inactive
|
||||
@ -1371,7 +1371,7 @@ class UnifiedManager:
|
||||
new_path = os.path.join(custom_nodes_path, '.disabled', f"{x}@nightly")
|
||||
moves.append((v, new_path))
|
||||
|
||||
print(f"Migration: STAGE 2")
|
||||
print("Migration: STAGE 2")
|
||||
# migrate active nodes
|
||||
for x, v in self.active_nodes.items():
|
||||
if v[0] not in ['nightly']:
|
||||
@ -1385,7 +1385,7 @@ class UnifiedManager:
|
||||
|
||||
self.reserve_migration(moves)
|
||||
|
||||
print(f"DONE (Migration reserved)")
|
||||
print("DONE (Migration reserved)")
|
||||
|
||||
|
||||
unified_manager = UnifiedManager()
|
||||
@ -2678,7 +2678,7 @@ async def restore_snapshot(snapshot_path, git_helper_extras=None):
|
||||
for k, v in unified_manager.repo_cnr_map.items():
|
||||
cnr_repo_map[v['id']] = k
|
||||
|
||||
print(f"Restore snapshot.")
|
||||
print("Restore snapshot.")
|
||||
|
||||
postinstalls = []
|
||||
|
||||
@ -2729,7 +2729,7 @@ async def restore_snapshot(snapshot_path, git_helper_extras=None):
|
||||
if hasattr(ps, 'postinstall'):
|
||||
postinstalls.append(ps.postinstall)
|
||||
else:
|
||||
print(f"cm-cli: unexpected [0001]")
|
||||
print("cm-cli: unexpected [0001]")
|
||||
|
||||
# for nightly restore
|
||||
git_info = info.get('git_custom_nodes')
|
||||
|
||||
@ -17,7 +17,7 @@ from server import PromptServer
|
||||
import manager_core as core
|
||||
import manager_util
|
||||
import cm_global
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
print(f"### Loading: ComfyUI-Manager ({core.version_str})")
|
||||
|
||||
@ -482,7 +482,7 @@ async def update_all(request):
|
||||
else:
|
||||
status = 201
|
||||
|
||||
print(f"\nDone.")
|
||||
print("\nDone.")
|
||||
return web.json_response(res, status=status, content_type='application/json')
|
||||
except:
|
||||
traceback.print_exc()
|
||||
@ -920,7 +920,7 @@ async def fix_custom_node(request):
|
||||
res = core.unified_manager.unified_fix(node_name, node_ver)
|
||||
|
||||
if res.result:
|
||||
print(f"After restarting ComfyUI, please refresh the browser.")
|
||||
print("After restarting ComfyUI, please refresh the browser.")
|
||||
return web.json_response({}, content_type='application/json')
|
||||
|
||||
print(f"ERROR: An error occurred while fixing '{node_name}@{node_ver}'.")
|
||||
@ -940,7 +940,7 @@ async def install_custom_node_git_url(request):
|
||||
print(f"Already installed: '{res.target}'")
|
||||
return web.Response(status=200)
|
||||
elif res.result:
|
||||
print(f"After restarting ComfyUI, please refresh the browser.")
|
||||
print("After restarting ComfyUI, please refresh the browser.")
|
||||
return web.Response(status=200)
|
||||
|
||||
print(res.msg)
|
||||
@ -979,7 +979,7 @@ async def uninstall_custom_node(request):
|
||||
res = core.unified_manager.unified_uninstall(node_name, is_unknown)
|
||||
|
||||
if res.result:
|
||||
print(f"After restarting ComfyUI, please refresh the browser.")
|
||||
print("After restarting ComfyUI, please refresh the browser.")
|
||||
return web.json_response({}, content_type='application/json')
|
||||
|
||||
print(f"ERROR: An error occurred while uninstalling '{node_name}'.")
|
||||
@ -1006,7 +1006,7 @@ async def update_custom_node(request):
|
||||
core.clear_pip_cache()
|
||||
|
||||
if res.result:
|
||||
print(f"After restarting ComfyUI, please refresh the browser.")
|
||||
print("After restarting ComfyUI, please refresh the browser.")
|
||||
return web.json_response({}, content_type='application/json')
|
||||
|
||||
print(f"ERROR: An error occurred while updating '{node_name}'.")
|
||||
@ -1080,7 +1080,7 @@ async def disable_node(request):
|
||||
|
||||
@routes.get("/manager/migrate_unmanaged_nodes")
|
||||
async def migrate_unmanaged_nodes(request):
|
||||
print(f"[ComfyUI-Manager] Migrating unmanaged nodes...")
|
||||
print("[ComfyUI-Manager] Migrating unmanaged nodes...")
|
||||
await core.unified_manager.migrate_unmanaged_nodes()
|
||||
print("Done.")
|
||||
return web.Response(status=200)
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import traceback
|
||||
|
||||
import aiohttp
|
||||
import json
|
||||
import threading
|
||||
@ -115,7 +113,7 @@ async def get_data(uri, silent=False):
|
||||
json_obj = json.loads(json_text)
|
||||
|
||||
if not silent:
|
||||
print(f" [DONE]")
|
||||
print(" [DONE]")
|
||||
|
||||
return json_obj
|
||||
|
||||
|
||||
@ -457,7 +457,7 @@ if os.path.exists(restore_snapshot_path):
|
||||
else:
|
||||
print(prefix, msg, end="")
|
||||
|
||||
print(f"[ComfyUI-Manager] Restore snapshot.")
|
||||
print("[ComfyUI-Manager] Restore snapshot.")
|
||||
new_env = os.environ.copy()
|
||||
new_env["COMFYUI_PATH"] = comfy_path
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user