Skip to content

Commit 4a70486

Browse files
authored
Merge pull request #70 from pydn/fix/custom_module_init
Hotfixes for latest ComfyUI release
2 parents aeecc92 + 2b9dfbe commit 4a70486

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

comfyui_to_python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import black
1212

1313

14-
from utils import (
14+
from common import (
1515
import_custom_nodes,
1616
find_path,
1717
add_comfyui_directory_to_sys_path,

utils.py renamed to common.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Sequence, Mapping, Any, Union
33
import sys
44

5-
sys.path.append('../')
5+
sys.path.append("../")
66

77

88
def import_custom_nodes() -> None:
@@ -13,7 +13,7 @@ def import_custom_nodes() -> None:
1313
"""
1414
import asyncio
1515
import execution
16-
from nodes import init_custom_nodes
16+
from nodes import init_extra_nodes
1717
import server
1818

1919
# Creating a new event loop and setting it as the default loop
@@ -25,18 +25,18 @@ def import_custom_nodes() -> None:
2525
execution.PromptQueue(server_instance)
2626

2727
# Initializing custom nodes
28-
init_custom_nodes()
28+
init_extra_nodes()
2929

3030

3131
def find_path(name: str, path: str = None) -> str:
3232
"""
33-
Recursively looks at parent folders starting from the given path until it finds the given name.
33+
Recursively looks at parent folders starting from the given path until it finds the given name.
3434
Returns the path as a Path object if found, or None otherwise.
3535
"""
3636
# If no path is given, use the current working directory
3737
if path is None:
3838
path = os.getcwd()
39-
39+
4040
# Check if the current directory contains the name
4141
if name in os.listdir(path):
4242
path_name = os.path.join(path, name)
@@ -58,7 +58,7 @@ def add_comfyui_directory_to_sys_path() -> None:
5858
"""
5959
Add 'ComfyUI' to the sys.path
6060
"""
61-
comfyui_path = find_path('ComfyUI')
61+
comfyui_path = find_path("ComfyUI")
6262
if comfyui_path is not None and os.path.isdir(comfyui_path):
6363
sys.path.append(comfyui_path)
6464
print(f"'{comfyui_path}' added to sys.path")
@@ -68,15 +68,20 @@ def add_extra_model_paths() -> None:
6868
"""
6969
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
7070
"""
71-
from main import load_extra_path_config
71+
try:
72+
from main import load_extra_path_config
73+
except ImportError:
74+
print(
75+
"Could not import load_extra_path_config from main.py. Looking in utils.extra_config instead."
76+
)
77+
from utils.extra_config import load_extra_path_config
7278

7379
extra_model_paths = find_path("extra_model_paths.yaml")
74-
80+
7581
if extra_model_paths is not None:
7682
load_extra_path_config(extra_model_paths)
7783
else:
7884
print("Could not find the extra_model_paths config file.")
79-
8085

8186

8287
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
@@ -86,18 +91,18 @@ def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
8691
If the object is a mapping (like a dictionary), returns the value at the index-th key.
8792
8893
Some return a dictionary, in these cases, we look for the "results" key
89-
94+
9095
Args:
9196
obj (Union[Sequence, Mapping]): The object to retrieve the value from.
9297
index (int): The index of the value to retrieve.
93-
98+
9499
Returns:
95100
Any: The value at the given index.
96-
101+
97102
Raises:
98103
IndexError: If the index is out of bounds for the object and the object is not a mapping.
99104
"""
100105
try:
101106
return obj[index]
102107
except KeyError:
103-
return obj['result'][index]
108+
return obj["result"][index]

0 commit comments

Comments
 (0)