Skip to content

Commit 83f70a8

Browse files
authored
Add __module__ to node info (comfyanonymous#3936)
Use more explicit name 'python_module' Parse abs ath Move parse to nodes.py
1 parent f1a01c2 commit 83f70a8

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

nodes.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,29 @@ def expand_image(self, image, left, top, right, bottom, feathering):
18891889
EXTENSION_WEB_DIRS = {}
18901890

18911891

1892-
def load_custom_node(module_path, ignore=set()):
1892+
def get_relative_module_name(module_path: str) -> str:
1893+
"""
1894+
Returns the module name based on the given module path.
1895+
Examples:
1896+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "custom_nodes.my_custom_node"
1897+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node") -> "custom_nodes.my_custom_node"
1898+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/") -> "custom_nodes.my_custom_node"
1899+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "custom_nodes.my_custom_node"
1900+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__") -> "custom_nodes.my_custom_node"
1901+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__/") -> "custom_nodes.my_custom_node"
1902+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes.my
1903+
Args:
1904+
module_path (str): The path of the module.
1905+
Returns:
1906+
str: The module name.
1907+
"""
1908+
relative_path = os.path.relpath(module_path, folder_paths.base_path)
1909+
if os.path.isfile(module_path):
1910+
relative_path = os.path.splitext(relative_path)[0]
1911+
return relative_path.replace(os.sep, '.')
1912+
1913+
1914+
def load_custom_node(module_path: str, ignore=set()) -> bool:
18931915
module_name = os.path.basename(module_path)
18941916
if os.path.isfile(module_path):
18951917
sp = os.path.splitext(module_path)
@@ -1913,9 +1935,10 @@ def load_custom_node(module_path, ignore=set()):
19131935
EXTENSION_WEB_DIRS[module_name] = web_dir
19141936

19151937
if hasattr(module, "NODE_CLASS_MAPPINGS") and getattr(module, "NODE_CLASS_MAPPINGS") is not None:
1916-
for name in module.NODE_CLASS_MAPPINGS:
1938+
for name, node_cls in module.NODE_CLASS_MAPPINGS.items():
19171939
if name not in ignore:
1918-
NODE_CLASS_MAPPINGS[name] = module.NODE_CLASS_MAPPINGS[name]
1940+
NODE_CLASS_MAPPINGS[name] = node_cls
1941+
node_cls.RELATIVE_PYTHON_MODULE = get_relative_module_name(module_path)
19191942
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS") and getattr(module, "NODE_DISPLAY_NAME_MAPPINGS") is not None:
19201943
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
19211944
return True

server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ def node_info(node_class):
416416
info['name'] = node_class
417417
info['display_name'] = nodes.NODE_DISPLAY_NAME_MAPPINGS[node_class] if node_class in nodes.NODE_DISPLAY_NAME_MAPPINGS.keys() else node_class
418418
info['description'] = obj_class.DESCRIPTION if hasattr(obj_class,'DESCRIPTION') else ''
419+
info['python_module'] = getattr(obj_class, "RELATIVE_PYTHON_MODULE", "nodes")
419420
info['category'] = 'sd'
420421
if hasattr(obj_class, 'OUTPUT_NODE') and obj_class.OUTPUT_NODE == True:
421422
info['output_node'] = True

0 commit comments

Comments
 (0)