Files
ComfyUI_frontend/tools/devtools/nodes/models.py
Christian Byrne 14c07fd734 [refactor] reorganize devtools test nodes into modules (#6020)
## Summary

Refactored monolithic devtools node definitions into organized module
structure for better maintainability and separation of concerns.

## Changes

- **What**: Split 700+ line `dev_nodes.py` into modular structure under
`tools/devtools/nodes/` with categorized files: `errors.py`,
`inputs.py`, `models.py`, `remote.py`
- **Dependencies**: None

## Review Focus

Module import structure and ensure all node registrations are properly
preserved in the consolidated mappings.

**Before:**
```
tools/devtools/
├── __init__.py
└── dev_nodes.py (738 lines)
```

**After:**
```
tools/devtools/
├── __init__.py
├── dev_nodes.py (65 lines - imports only)
└── nodes/
    ├── __init__.py (consolidated mappings)
    ├── errors.py (error/debug nodes)
    ├── inputs.py (input/widget nodes)
    ├── models.py (model/patch nodes)
    └── remote.py (remote/combo nodes)
```

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6020-refactor-reorganize-devtools-test-nodes-into-modules-2896d73d365081e89efef7e88ca8fee3)
by [Unito](https://www.unito.io)
2025-10-11 15:29:29 -07:00

85 lines
2.3 KiB
Python

from __future__ import annotations
import os
import torch
import comfy.utils as utils
from comfy.model_patcher import ModelPatcher
import nodes
import folder_paths
class DummyPatch(torch.nn.Module):
def __init__(self, module: torch.nn.Module, dummy_float: float = 0.0):
super().__init__()
self.module = module
self.dummy_float = dummy_float
def forward(self, *args, **kwargs):
if isinstance(self.module, DummyPatch):
raise Exception(f"Calling nested dummy patch! {self.dummy_float}")
return self.module(*args, **kwargs)
class ObjectPatchNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("MODEL",),
"target_module": ("STRING", {"multiline": True}),
},
"optional": {
"dummy_float": ("FLOAT", {"default": 0.0}),
},
}
RETURN_TYPES = ("MODEL",)
FUNCTION = "apply_patch"
CATEGORY = "DevTools"
DESCRIPTION = "A node that applies an object patch"
def apply_patch(
self, model: ModelPatcher, target_module: str, dummy_float: float = 0.0
) -> ModelPatcher:
module = utils.get_attr(model.model, target_module)
work_model = model.clone()
work_model.add_object_patch(target_module, DummyPatch(module, dummy_float))
return (work_model,)
class LoadAnimatedImageTest(nodes.LoadImage):
@classmethod
def INPUT_TYPES(s):
input_dir = folder_paths.get_input_directory()
files = [
f
for f in os.listdir(input_dir)
if os.path.isfile(os.path.join(input_dir, f)) and f.endswith(".webp")
]
files = folder_paths.filter_files_content_types(files, ["image"])
return {
"required": {"image": (sorted(files), {"animated_image_upload": True})},
}
NODE_CLASS_MAPPINGS = {
"DevToolsObjectPatchNode": ObjectPatchNode,
"DevToolsLoadAnimatedImageTest": LoadAnimatedImageTest,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"DevToolsObjectPatchNode": "Object Patch Node",
"DevToolsLoadAnimatedImageTest": "Load Animated Image",
}
__all__ = [
"DummyPatch",
"ObjectPatchNode",
"LoadAnimatedImageTest",
"NODE_CLASS_MAPPINGS",
"NODE_DISPLAY_NAME_MAPPINGS",
]