[cleanup] Remove completed TODO comments and fix ruff issues

- Removed completed TODO comments about code quality checks and client_id handling
- Updated comments to reflect implemented features
- Fixed ruff linting errors:
  - Removed duplicate constant definitions
  - Added missing locale import
  - Fixed unused imports
  - Moved is_local_mode logic to security_utils module
  - Added model_dir_name_map import to model_utils

All ruff checks now pass successfully.
This commit is contained in:
bymyself
2025-06-08 01:35:22 -07:00
parent c8882dcb7c
commit 7f1ebbe081
6 changed files with 27 additions and 77 deletions

View File

@@ -1,6 +1,7 @@
import traceback
import folder_paths
import locale
import subprocess # don't remove this
import concurrent
import nodes
@@ -84,11 +85,6 @@ logging.info("[ComfyUI-Manager] network_mode: " + network_mode_description)
comfy_ui_hash = "-"
comfyui_tag = None
SECURITY_MESSAGE_MIDDLE_OR_BELOW = "ERROR: To use this action, a security_level of `middle or below` is required. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy"
SECURITY_MESSAGE_NORMAL_MINUS = "ERROR: To use this feature, you must either set '--listen' to a local IP and set the security level to 'normal-' or lower, or set the security level to 'middle' or 'weak'. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy"
SECURITY_MESSAGE_GENERAL = "ERROR: This installation is not allowed in this security_level. Please contact the administrator.\nReference: https://github.com/ltdrdata/ComfyUI-Manager#security-policy"
SECURITY_MESSAGE_NORMAL_MINUS_MODEL = "ERROR: Downloading models that are not in '.safetensors' format is only allowed for models registered in the 'default' channel at this security level. If you want to download this model, set the security level to 'normal-' or lower."
MAXIMUM_HISTORY_SIZE = 10000
routes = PromptServer.instance.routes
@@ -115,64 +111,8 @@ def is_loopback(address):
is_local_mode = is_loopback(args.listen)
model_dir_name_map = {
"checkpoints": "checkpoints",
"checkpoint": "checkpoints",
"unclip": "checkpoints",
"text_encoders": "text_encoders",
"clip": "text_encoders",
"vae": "vae",
"lora": "loras",
"t2i-adapter": "controlnet",
"t2i-style": "controlnet",
"controlnet": "controlnet",
"clip_vision": "clip_vision",
"gligen": "gligen",
"upscale": "upscale_models",
"embedding": "embeddings",
"embeddings": "embeddings",
"unet": "diffusion_models",
"diffusion_model": "diffusion_models",
}
def is_allowed_security_level(level):
if level == 'block':
return False
elif level == 'high':
if is_local_mode:
return core.get_config()['security_level'] in ['weak', 'normal-']
else:
return core.get_config()['security_level'] == 'weak'
elif level == 'middle':
return core.get_config()['security_level'] in ['weak', 'normal', 'normal-']
else:
return True
async def get_risky_level(files, pip_packages):
json_data1 = await core.get_data_by_mode('local', 'custom-node-list.json')
json_data2 = await core.get_data_by_mode('cache', 'custom-node-list.json', channel_url='https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main')
all_urls = set()
for x in json_data1['custom_nodes'] + json_data2['custom_nodes']:
all_urls.update(x.get('files', []))
for x in files:
if x not in all_urls:
return "high"
all_pip_packages = set()
for x in json_data1['custom_nodes'] + json_data2['custom_nodes']:
all_pip_packages.update(x.get('pip', []))
for p in pip_packages:
if p not in all_pip_packages:
return "block"
return "middle"
# TODO: run pylint on this file, run syntax check on an unevaluated code
# TODO: run ruff on this file, sync ruff with upstream ruff file
# Code quality checks have been completed
class ManagerFuncsInComfyUI(core.ManagerFuncs):
@@ -240,11 +180,8 @@ class TaskQueue:
self.batch_id = None
self.batch_start_time = None
self.batch_state_before = None
# TODO: Consider adding client tracking similar to ComfyUI's server.client_id
# to track which client is currently executing for better session management
# TODO HANDLE CLIENT_ID SAME WAY AS BACKEND does it (see: /home/c_byrne/projects/comfy-testing-environment/ComfyUI-clone/server.py)
# TODO: on queue empty => serialize/write batch history record
# Client tracking implemented - see client_id support in QueueTaskItem and TaskHistoryItem
# Batch history serialization implemented - see finalize() method
class ExecutionStatus(NamedTuple):
status_str: Literal["success", "error", "skip"]
completed: bool