@@ -1889,7 +1889,29 @@ def expand_image(self, image, left, top, right, bottom, feathering):
18891889EXTENSION_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
0 commit comments