Merge pull request #70 from pydn/fix/custom_module_init
Hotfixes for latest ComfyUI release
This commit is contained in:
@@ -11,7 +11,7 @@ from typing import Dict, List, Any, Callable, Tuple
|
||||
import black
|
||||
|
||||
|
||||
from utils import (
|
||||
from common import (
|
||||
import_custom_nodes,
|
||||
find_path,
|
||||
add_comfyui_directory_to_sys_path,
|
||||
|
||||
+18
-13
@@ -2,7 +2,7 @@ import os
|
||||
from typing import Sequence, Mapping, Any, Union
|
||||
import sys
|
||||
|
||||
sys.path.append('../')
|
||||
sys.path.append("../")
|
||||
|
||||
|
||||
def import_custom_nodes() -> None:
|
||||
@@ -13,7 +13,7 @@ def import_custom_nodes() -> None:
|
||||
"""
|
||||
import asyncio
|
||||
import execution
|
||||
from nodes import init_custom_nodes
|
||||
from nodes import init_extra_nodes
|
||||
import server
|
||||
|
||||
# Creating a new event loop and setting it as the default loop
|
||||
@@ -25,18 +25,18 @@ def import_custom_nodes() -> None:
|
||||
execution.PromptQueue(server_instance)
|
||||
|
||||
# Initializing custom nodes
|
||||
init_custom_nodes()
|
||||
init_extra_nodes()
|
||||
|
||||
|
||||
def find_path(name: str, path: str = None) -> str:
|
||||
"""
|
||||
Recursively looks at parent folders starting from the given path until it finds the given name.
|
||||
Recursively looks at parent folders starting from the given path until it finds the given name.
|
||||
Returns the path as a Path object if found, or None otherwise.
|
||||
"""
|
||||
# If no path is given, use the current working directory
|
||||
if path is None:
|
||||
path = os.getcwd()
|
||||
|
||||
|
||||
# Check if the current directory contains the name
|
||||
if name in os.listdir(path):
|
||||
path_name = os.path.join(path, name)
|
||||
@@ -58,7 +58,7 @@ def add_comfyui_directory_to_sys_path() -> None:
|
||||
"""
|
||||
Add 'ComfyUI' to the sys.path
|
||||
"""
|
||||
comfyui_path = find_path('ComfyUI')
|
||||
comfyui_path = find_path("ComfyUI")
|
||||
if comfyui_path is not None and os.path.isdir(comfyui_path):
|
||||
sys.path.append(comfyui_path)
|
||||
print(f"'{comfyui_path}' added to sys.path")
|
||||
@@ -68,15 +68,20 @@ def add_extra_model_paths() -> None:
|
||||
"""
|
||||
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
|
||||
"""
|
||||
from main import load_extra_path_config
|
||||
try:
|
||||
from main import load_extra_path_config
|
||||
except ImportError:
|
||||
print(
|
||||
"Could not import load_extra_path_config from main.py. Looking in utils.extra_config instead."
|
||||
)
|
||||
from utils.extra_config import load_extra_path_config
|
||||
|
||||
extra_model_paths = find_path("extra_model_paths.yaml")
|
||||
|
||||
|
||||
if extra_model_paths is not None:
|
||||
load_extra_path_config(extra_model_paths)
|
||||
else:
|
||||
print("Could not find the extra_model_paths config file.")
|
||||
|
||||
|
||||
|
||||
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:
|
||||
If the object is a mapping (like a dictionary), returns the value at the index-th key.
|
||||
|
||||
Some return a dictionary, in these cases, we look for the "results" key
|
||||
|
||||
|
||||
Args:
|
||||
obj (Union[Sequence, Mapping]): The object to retrieve the value from.
|
||||
index (int): The index of the value to retrieve.
|
||||
|
||||
|
||||
Returns:
|
||||
Any: The value at the given index.
|
||||
|
||||
|
||||
Raises:
|
||||
IndexError: If the index is out of bounds for the object and the object is not a mapping.
|
||||
"""
|
||||
try:
|
||||
return obj[index]
|
||||
except KeyError:
|
||||
return obj['result'][index]
|
||||
return obj["result"][index]
|
||||
Reference in New Issue
Block a user