Skip to content

Commit 33346fd

Browse files
Fix bug with custom nodes on other drives.
1 parent 136c93c commit 33346fd

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

nodes.py

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

18921892

1893-
def get_relative_module_name(module_path: str) -> str:
1893+
def get_module_name(module_path: str) -> str:
18941894
"""
18951895
Returns the module name based on the given module path.
18961896
Examples:
1897-
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "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/") -> "custom_nodes.my_custom_node"
1900-
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "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/__init__/") -> "custom_nodes.my_custom_node"
1903-
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes.my
1897+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.py") -> "my_custom_node"
1898+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node") -> "my_custom_node"
1899+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/") -> "my_custom_node"
1900+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__.py") -> "my_custom_node"
1901+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__") -> "my_custom_node"
1902+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node/__init__/") -> "my_custom_node"
1903+
get_module_name("C:/Users/username/ComfyUI/custom_nodes/my_custom_node.disabled") -> "custom_nodes
19041904
Args:
19051905
module_path (str): The path of the module.
19061906
Returns:
19071907
str: The module name.
19081908
"""
1909-
relative_path = os.path.relpath(module_path, folder_paths.base_path)
1909+
base_path = os.path.basename(module_path)
19101910
if os.path.isfile(module_path):
1911-
relative_path = os.path.splitext(relative_path)[0]
1912-
return relative_path.replace(os.sep, '.')
1911+
base_path = os.path.splitext(base_path)[0]
1912+
return base_path
19131913

19141914

1915-
def load_custom_node(module_path: str, ignore=set()) -> bool:
1915+
def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes") -> bool:
19161916
module_name = os.path.basename(module_path)
19171917
if os.path.isfile(module_path):
19181918
sp = os.path.splitext(module_path)
@@ -1939,7 +1939,7 @@ def load_custom_node(module_path: str, ignore=set()) -> bool:
19391939
for name, node_cls in module.NODE_CLASS_MAPPINGS.items():
19401940
if name not in ignore:
19411941
NODE_CLASS_MAPPINGS[name] = node_cls
1942-
node_cls.RELATIVE_PYTHON_MODULE = get_relative_module_name(module_path)
1942+
node_cls.RELATIVE_PYTHON_MODULE = "{}.{}".format(module_parent, get_module_name(module_path))
19431943
if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS") and getattr(module, "NODE_DISPLAY_NAME_MAPPINGS") is not None:
19441944
NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS)
19451945
return True
@@ -1974,7 +1974,7 @@ def init_external_custom_nodes():
19741974
if os.path.isfile(module_path) and os.path.splitext(module_path)[1] != ".py": continue
19751975
if module_path.endswith(".disabled"): continue
19761976
time_before = time.perf_counter()
1977-
success = load_custom_node(module_path, base_node_names)
1977+
success = load_custom_node(module_path, base_node_names, module_parent="custom_nodes")
19781978
node_import_times.append((time.perf_counter() - time_before, module_path, success))
19791979

19801980
if len(node_import_times) > 0:
@@ -2040,7 +2040,7 @@ def init_builtin_extra_nodes():
20402040

20412041
import_failed = []
20422042
for node_file in extras_files:
2043-
if not load_custom_node(os.path.join(extras_dir, node_file)):
2043+
if not load_custom_node(os.path.join(extras_dir, node_file), module_parent="comfy_extras"):
20442044
import_failed.append(node_file)
20452045

20462046
return import_failed

0 commit comments

Comments
 (0)