Skip to content

Commit

Permalink
Fix bug with custom nodes on other drives.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Jul 16, 2024
1 parent 136c93c commit 33346fd
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,29 +1890,29 @@ def expand_image(self, image, left, top, right, bottom, feathering):
EXTENSION_WEB_DIRS = {}


def get_relative_module_name(module_path: str) -> str:
def get_module_name(module_path: str) -> str:
"""
Returns the module name based on the given module path.
Examples:
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__/") -> "custom_nodes.my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes.my
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__/") -> "my_custom_node"
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes
Args:
module_path (str): The path of the module.
Returns:
str: The module name.
"""
relative_path = os.path.relpath(module_path, folder_paths.base_path)
base_path = os.path.basename(module_path)
if os.path.isfile(module_path):
relative_path = os.path.splitext(relative_path)[0]
return relative_path.replace(os.sep, '.')
base_path = os.path.splitext(base_path)[0]
return base_path


def load_custom_node(module_path: str, ignore=set()) -> bool:
def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes") -> bool:
module_name = os.path.basename(module_path)
if os.path.isfile(module_path):
sp = os.path.splitext(module_path)
Expand All @@ -1939,7 +1939,7 @@ def load_custom_node(module_path: str, ignore=set()) -> bool:
for name, node_cls in module.NODE_CLASS_MAPPINGS.items():
if name not in ignore:
NODE_CLASS_MAPPINGS[name] = node_cls
node_cls.RELATIVE_PYTHON_MODULE = get_relative_module_name(module_path)
node_cls.RELATIVE_PYTHON_MODULE = "{}.{}".format(module_parent, get_module_name(module_path))
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS") and getattr(module, "NODE_DISPLAY_NAME_MAPPINGS") is not None:
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
return True
Expand Down Expand Up @@ -1974,7 +1974,7 @@ def init_external_custom_nodes():
if os.path.isfile(module_path) and os.path.splitext(module_path)[1] != ".py": continue
if module_path.endswith(".disabled"): continue
time_before = time.perf_counter()
success = load_custom_node(module_path, base_node_names)
success = load_custom_node(module_path, base_node_names, module_parent="custom_nodes")
node_import_times.append((time.perf_counter() - time_before, module_path, success))

if len(node_import_times) > 0:
Expand Down Expand Up @@ -2040,7 +2040,7 @@ def init_builtin_extra_nodes():

import_failed = []
for node_file in extras_files:
if not load_custom_node(os.path.join(extras_dir, node_file)):
if not load_custom_node(os.path.join(extras_dir, node_file), module_parent="comfy_extras"):
import_failed.append(node_file)

return import_failed
Expand Down

0 comments on commit 33346fd

Please sign in to comment.