mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
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
This commit is contained in:
@@ -15,7 +15,7 @@ class CheckpointLoaderLM:
|
|||||||
extra folder paths, providing a unified interface for checkpoint loading.
|
extra folder paths, providing a unified interface for checkpoint loading.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = "CheckpointLoaderLM"
|
NAME = "Checkpoint Loader (LoraManager)"
|
||||||
CATEGORY = "Lora Manager/loaders"
|
CATEGORY = "Lora Manager/loaders"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -60,7 +60,7 @@ class CheckpointLoaderLM:
|
|||||||
if item.get("sub_type") == "checkpoint":
|
if item.get("sub_type") == "checkpoint":
|
||||||
file_path = item.get("file_path", "")
|
file_path = item.get("file_path", "")
|
||||||
if 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(
|
formatted_name = _format_model_name_for_comfyui(
|
||||||
file_path, model_roots
|
file_path, model_roots
|
||||||
)
|
)
|
||||||
@@ -94,7 +94,7 @@ class CheckpointLoaderLM:
|
|||||||
"""Load a checkpoint by name, supporting extra folder paths
|
"""Load a checkpoint by name, supporting extra folder paths
|
||||||
|
|
||||||
Args:
|
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:
|
Returns:
|
||||||
Tuple of (MODEL, CLIP, VAE)
|
Tuple of (MODEL, CLIP, VAE)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class UNETLoaderLM:
|
|||||||
Supports both regular diffusion models and GGUF format models.
|
Supports both regular diffusion models and GGUF format models.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = "UNETLoaderLM"
|
NAME = "Unet Loader (LoraManager)"
|
||||||
CATEGORY = "Lora Manager/loaders"
|
CATEGORY = "Lora Manager/loaders"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -61,7 +61,7 @@ class UNETLoaderLM:
|
|||||||
if item.get("sub_type") == "diffusion_model":
|
if item.get("sub_type") == "diffusion_model":
|
||||||
file_path = item.get("file_path", "")
|
file_path = item.get("file_path", "")
|
||||||
if 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(
|
formatted_name = _format_model_name_for_comfyui(
|
||||||
file_path, model_roots
|
file_path, model_roots
|
||||||
)
|
)
|
||||||
@@ -95,7 +95,7 @@ class UNETLoaderLM:
|
|||||||
"""Load a diffusion model by name, supporting extra folder paths
|
"""Load a diffusion model by name, supporting extra folder paths
|
||||||
|
|
||||||
Args:
|
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
|
weight_dtype: The dtype to use for model weights
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ def get_checkpoint_info_absolute(checkpoint_name):
|
|||||||
# Format the stored path as ComfyUI-style name
|
# Format the stored path as ComfyUI-style name
|
||||||
formatted_name = _format_model_name_for_comfyui(file_path, model_roots)
|
formatted_name = _format_model_name_for_comfyui(file_path, model_roots)
|
||||||
|
|
||||||
# Match by formatted name
|
# Match by formatted name (normalize separators for robust comparison)
|
||||||
if formatted_name == normalized_name or formatted_name == checkpoint_name:
|
if formatted_name.replace(os.sep, "/") == normalized_name or formatted_name == checkpoint_name:
|
||||||
return file_path, item
|
return file_path, item
|
||||||
|
|
||||||
# Also try matching by basename only (for backward compatibility)
|
# 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:
|
Returns:
|
||||||
ComfyUI-style model name with relative path and extension
|
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
|
# Find the matching root and get relative path
|
||||||
for root in model_roots:
|
for root in model_roots:
|
||||||
normalized_root = root.replace(os.sep, "/")
|
try:
|
||||||
# Ensure root ends with / for proper matching
|
# Normalize paths for comparison
|
||||||
if not normalized_root.endswith("/"):
|
norm_file = os.path.normcase(os.path.abspath(file_path))
|
||||||
normalized_root += "/"
|
norm_root = os.path.normcase(os.path.abspath(root))
|
||||||
|
|
||||||
if normalized_path.startswith(normalized_root):
|
# Add trailing separator for prefix check
|
||||||
rel_path = normalized_path[len(normalized_root) :]
|
if not norm_root.endswith(os.sep):
|
||||||
return rel_path
|
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
|
# If no root matches, just return the basename with extension
|
||||||
return os.path.basename(file_path)
|
return os.path.basename(file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user