diff --git a/app/node_replace_manager.py b/app/node_replace_manager.py index b513d7bc2..92a0949ab 100644 --- a/app/node_replace_manager.py +++ b/app/node_replace_manager.py @@ -8,36 +8,30 @@ if TYPE_CHECKING: class NodeReplaceManager: - """ - Manages node replacement registrations. - - Stores replacements as instance state (not module-level globals) to support - process isolation via pyisolate, where extensions run in separate processes - and communicate via RPC. - """ - + """Manages node replacement registrations.""" + def __init__(self): self._replacements: dict[str, list[NodeReplace]] = {} - + def register(self, node_replace: NodeReplace): """Register a node replacement mapping.""" self._replacements.setdefault(node_replace.old_node_id, []).append(node_replace) - + def get_replacement(self, old_node_id: str) -> list[NodeReplace] | None: """Get replacements for an old node ID.""" return self._replacements.get(old_node_id) - + def has_replacement(self, old_node_id: str) -> bool: """Check if a replacement exists for an old node ID.""" return old_node_id in self._replacements - + def as_dict(self): """Serialize all replacements to dict.""" return { - k: [v.as_dict() for v in v_list] + k: [v.as_dict() for v in v_list] for k, v_list in self._replacements.items() } - + def add_routes(self, routes): @routes.get("/node_replacements") async def get_node_replacements(request): diff --git a/comfy_api/latest/__init__.py b/comfy_api/latest/__init__.py index d5b4875e3..8ae2a5a00 100644 --- a/comfy_api/latest/__init__.py +++ b/comfy_api/latest/__init__.py @@ -24,16 +24,7 @@ class ComfyAPI_latest(ComfyAPIBase): class NodeReplacement(ProxiedSingleton): async def register(self, node_replace: 'node_replace.NodeReplace') -> None: - """ - Register a node replacement mapping. - - This async method supports process isolation via pyisolate, where - extensions run in separate processes. The call is RPC'd to the host - process where PromptServer and NodeReplaceManager live. - - Args: - node_replace: A NodeReplace object defining the old->new mapping - """ + """Register a node replacement mapping.""" from server import PromptServer PromptServer.instance.node_replace_manager.register(node_replace) diff --git a/comfy_api/latest/_node_replace.py b/comfy_api/latest/_node_replace.py index b55cd8a69..89c8c144f 100644 --- a/comfy_api/latest/_node_replace.py +++ b/comfy_api/latest/_node_replace.py @@ -1,27 +1,8 @@ from __future__ import annotations -import warnings from typing import Any -def register_node_replacement(node_replace: NodeReplace): - """ - Register node replacement. - - .. deprecated:: - Use ``ComfyAPI.node_replacement.register()`` instead. - This synchronous function does not work with process isolation (pyisolate). - """ - warnings.warn( - "register_node_replacement() is deprecated. " - "Use 'await ComfyAPI.node_replacement.register()' instead for pyisolate compatibility.", - DeprecationWarning, - stacklevel=2 - ) - from server import PromptServer - PromptServer.instance.node_replace_manager.register(node_replace) - - class NodeReplace: """ Defines a possible node replacement, mapping inputs and outputs of the old node to the new node. @@ -42,9 +23,7 @@ class NodeReplace: self.output_mapping = output_mapping def as_dict(self): - """ - Create serializable representation of the node replacement. - """ + """Create serializable representation of the node replacement.""" return { "new_node_id": self.new_node_id, "old_node_id": self.old_node_id, @@ -70,9 +49,7 @@ class InputMap: } class OldId(_Assign): - """ - Connect the input of the old node with given id to new node when replacing. - """ + """Connect the input of the old node with given id to new node when replacing.""" def __init__(self, old_id: str): super().__init__("old_id") self.old_id = old_id @@ -83,9 +60,7 @@ class InputMap: } class SetValue(_Assign): - """ - Use the given value for the input of the new node when replacing; assumes input is a widget. - """ + """Use the given value for the input of the new node when replacing; assumes input is a widget.""" def __init__(self, value: Any): super().__init__("set_value") self.value = value @@ -107,9 +82,7 @@ class InputMap: class OutputMap: - """ - Map outputs of node replacement via indexes, as that's how outputs are stored. - """ + """Map outputs of node replacement via indexes, as that's how outputs are stored.""" def __init__(self, new_idx: int, old_idx: int): self.new_idx = new_idx self.old_idx = old_idx