mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-11 16:40:05 +08:00
Add support for custom load order of external nodes\n\n- Load modules based on custom_load_order.txt if available.\n- Modules not listed are loaded after those specified.
This commit is contained in:
parent
cf80d28689
commit
7845c36921
20
nodes.py
20
nodes.py
@ -2027,11 +2027,31 @@ def init_external_custom_nodes():
|
||||
base_node_names = set(NODE_CLASS_MAPPINGS.keys())
|
||||
node_paths = folder_paths.get_folder_paths("custom_nodes")
|
||||
node_import_times = []
|
||||
|
||||
# Path to the file specifying the load order for custom modules.
|
||||
# Each line in the file should represent a module name.
|
||||
module_order_path = 'custom_nodes/custom_load_order.txt'
|
||||
|
||||
# If the file exists, read module names from it; otherwise, use an empty list.
|
||||
if os.path.exists(module_order_path):
|
||||
with open(module_order_path, 'r') as file:
|
||||
ordered_modules = [line.strip() for line in file]
|
||||
else:
|
||||
ordered_modules = []
|
||||
|
||||
# Create a dictionary that maps module names to their index in 'ordered_modules'.
|
||||
# Modules not in this list will be assigned 'inf' to load them last.
|
||||
order_map = {name: i for i, name in enumerate(ordered_modules)}
|
||||
|
||||
for custom_node_path in node_paths:
|
||||
possible_modules = os.listdir(os.path.realpath(custom_node_path))
|
||||
if "__pycache__" in possible_modules:
|
||||
possible_modules.remove("__pycache__")
|
||||
|
||||
# Sort modules based on their order in 'order_map'.
|
||||
# Modules without an entry are sorted to load after those listed.
|
||||
possible_modules.sort(key=lambda x: order_map.get(x, float('inf')))
|
||||
|
||||
for possible_module in possible_modules:
|
||||
module_path = os.path.join(custom_node_path, possible_module)
|
||||
if os.path.isfile(module_path) and os.path.splitext(module_path)[1] != ".py": continue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user