Added a function to load the directories in the optional file: extra_model_paths.yaml
This commit is contained in:
@@ -145,3 +145,6 @@ cython_debug/
|
||||
*.sql
|
||||
*.sqlite
|
||||
*.xml
|
||||
/workflow_api.json
|
||||
/workflow_api.py
|
||||
/custom_nodes/
|
||||
|
||||
@@ -10,9 +10,10 @@ from typing import Dict, List, Any, Callable, Tuple
|
||||
|
||||
import black
|
||||
|
||||
from utils import import_custom_nodes, add_comfyui_directory_to_sys_path, get_value_at_index
|
||||
|
||||
sys.path.append('../')
|
||||
sys.path.append('.')
|
||||
|
||||
from utils import import_custom_nodes, add_comfyui_directory_to_sys_path, get_value_at_index, add_extra_model_paths
|
||||
|
||||
from nodes import NODE_CLASS_MAPPINGS
|
||||
|
||||
@@ -306,11 +307,11 @@ class CodeGenerator:
|
||||
"""
|
||||
# Get the source code of the utils functions as a string
|
||||
func_strings = []
|
||||
for func in [add_comfyui_directory_to_sys_path, get_value_at_index]:
|
||||
for func in [add_comfyui_directory_to_sys_path, get_value_at_index, add_extra_model_paths]:
|
||||
func_strings.append(f'\n{inspect.getsource(func)}')
|
||||
# Define static import statements required for the script
|
||||
static_imports = ['import os', 'import random', 'import sys', 'from typing import Sequence, Mapping, Any, Union',
|
||||
'import torch'] + func_strings + ['\n\nadd_comfyui_directory_to_sys_path()']
|
||||
static_imports = ['import os', 'import random', 'from pathlib import Path', 'import sys', 'from typing import Sequence, Mapping, Any, Union',
|
||||
'import torch'] + func_strings + ['\n\nadd_comfyui_directory_to_sys_path()\nadd_extra_model_paths()\n']
|
||||
# Check if custom nodes should be included
|
||||
if custom_nodes:
|
||||
static_imports.append(f'\n{inspect.getsource(import_custom_nodes)}\n')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from typing import Sequence, Mapping, Any, Union
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
sys.path.append('../')
|
||||
@@ -54,6 +55,39 @@ def add_comfyui_directory_to_sys_path() -> None:
|
||||
# Start the search from the current working directory
|
||||
search_directory(start_path)
|
||||
|
||||
def add_extra_model_paths() -> Path:
|
||||
"""
|
||||
Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from main import load_extra_path_config
|
||||
|
||||
def find_config_file(path: str, name: str = "extra_model_paths.yaml") -> Path:
|
||||
# Check if the current directory contains the file
|
||||
if name in os.listdir(path):
|
||||
directory_path = os.path.join(path, name)
|
||||
print(f"{name} found: {directory_path}")
|
||||
return Path(directory_path)
|
||||
|
||||
# Get the parent directory
|
||||
parent_directory = os.path.dirname(path)
|
||||
|
||||
# If the parent directory is the same as the current directory, we've reached the root and stop the search
|
||||
if parent_directory == path:
|
||||
return
|
||||
|
||||
# Recursively call the function with the parent directory
|
||||
return find_config_file(parent_directory)
|
||||
|
||||
start_path = os.getcwd() # Get the current working directory
|
||||
file = find_config_file(start_path)
|
||||
|
||||
if os.path.isfile(file):
|
||||
load_extra_path_config(file)
|
||||
else:
|
||||
print("Could not find the extra_model_paths config file.")
|
||||
|
||||
|
||||
|
||||
def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
|
||||
"""Returns the value at the given index of a sequence or mapping.
|
||||
|
||||
Reference in New Issue
Block a user