From 0ef414d17e0193ac7d2c475ab1f6df0fd75ff77d Mon Sep 17 00:00:00 2001 From: Will Miao Date: Wed, 18 Mar 2026 21:33:19 +0800 Subject: [PATCH] feat: standardize Checkpoint/Unet loader names and use OS-native path separators - Rename nodes to 'Checkpoint Loader (LoraManager)' and 'Unet Loader (LoraManager)'\n- Use os.sep for relative path formatting in model COMBO inputs\n- Update path matching to be robust across OS separators\n- Update docstrings and comments --- py/nodes/checkpoint_loader.py | 6 +++--- py/nodes/unet_loader.py | 6 +++--- py/utils/utils.py | 27 +++++++++++++++------------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/py/nodes/checkpoint_loader.py b/py/nodes/checkpoint_loader.py index 51b447f9..6a949a76 100644 --- a/py/nodes/checkpoint_loader.py +++ b/py/nodes/checkpoint_loader.py @@ -15,7 +15,7 @@ class CheckpointLoaderLM: extra folder paths, providing a unified interface for checkpoint loading. """ - NAME = "CheckpointLoaderLM" + NAME = "Checkpoint Loader (LoraManager)" CATEGORY = "Lora Manager/loaders" @classmethod @@ -60,7 +60,7 @@ class CheckpointLoaderLM: if item.get("sub_type") == "checkpoint": file_path = item.get("file_path", "") if file_path: - # Format as ComfyUI-style: "folder/model_name.ext" + # Format using relative path with OS-native separator formatted_name = _format_model_name_for_comfyui( file_path, model_roots ) @@ -94,7 +94,7 @@ class CheckpointLoaderLM: """Load a checkpoint by name, supporting extra folder paths Args: - ckpt_name: The name of the checkpoint to load (format: "folder/model_name.ext") + ckpt_name: The name of the checkpoint to load (relative path with extension) Returns: Tuple of (MODEL, CLIP, VAE) diff --git a/py/nodes/unet_loader.py b/py/nodes/unet_loader.py index 34e7f5c2..64704904 100644 --- a/py/nodes/unet_loader.py +++ b/py/nodes/unet_loader.py @@ -16,7 +16,7 @@ class UNETLoaderLM: Supports both regular diffusion models and GGUF format models. """ - NAME = "UNETLoaderLM" + NAME = "Unet Loader (LoraManager)" CATEGORY = "Lora Manager/loaders" @classmethod @@ -61,7 +61,7 @@ class UNETLoaderLM: if item.get("sub_type") == "diffusion_model": file_path = item.get("file_path", "") if file_path: - # Format as ComfyUI-style: "folder/model_name.ext" + # Format using relative path with OS-native separator formatted_name = _format_model_name_for_comfyui( file_path, model_roots ) @@ -95,7 +95,7 @@ class UNETLoaderLM: """Load a diffusion model by name, supporting extra folder paths Args: - unet_name: The name of the diffusion model to load (format: "folder/model_name.ext") + unet_name: The name of the diffusion model to load (relative path with extension) weight_dtype: The dtype to use for model weights Returns: diff --git a/py/utils/utils.py b/py/utils/utils.py index d7bba5d9..ef2a333f 100644 --- a/py/utils/utils.py +++ b/py/utils/utils.py @@ -148,8 +148,8 @@ def get_checkpoint_info_absolute(checkpoint_name): # Format the stored path as ComfyUI-style name formatted_name = _format_model_name_for_comfyui(file_path, model_roots) - # Match by formatted name - if formatted_name == normalized_name or formatted_name == checkpoint_name: + # Match by formatted name (normalize separators for robust comparison) + if formatted_name.replace(os.sep, "/") == normalized_name or formatted_name == checkpoint_name: return file_path, item # Also try matching by basename only (for backward compatibility) @@ -200,19 +200,22 @@ def _format_model_name_for_comfyui(file_path: str, model_roots: list) -> str: Returns: ComfyUI-style model name with relative path and extension """ - # Normalize path separators - normalized_path = file_path.replace(os.sep, "/") - # Find the matching root and get relative path for root in model_roots: - normalized_root = root.replace(os.sep, "/") - # Ensure root ends with / for proper matching - if not normalized_root.endswith("/"): - normalized_root += "/" + try: + # Normalize paths for comparison + norm_file = os.path.normcase(os.path.abspath(file_path)) + norm_root = os.path.normcase(os.path.abspath(root)) - if normalized_path.startswith(normalized_root): - rel_path = normalized_path[len(normalized_root) :] - return rel_path + # Add trailing separator for prefix check + if not norm_root.endswith(os.sep): + norm_root += os.sep + + if norm_file.startswith(norm_root): + # Use os.path.relpath to get relative path with OS-native separator + return os.path.relpath(file_path, root) + except (ValueError, TypeError): + continue # If no root matches, just return the basename with extension return os.path.basename(file_path)