Skip to content

Commit 99abcbe

Browse files
authored
feat/startup-script: Feature to avoid package installation errors when installing custom nodes. (Comfy-Org#856)
* support startup script for installation without locking on windows * modified: Instead of executing scripts from the startup-scripts directory, I will change it to execute the prestartup_script.py for each custom node.
1 parent 606a537 commit 99abcbe

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ extra_model_paths.yaml
1313
venv/
1414
web/extensions/*
1515
!web/extensions/logging.js.example
16-
!web/extensions/core/
16+
!web/extensions/core/
17+
startup-scripts/

main.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
1+
import os
2+
import importlib.util
3+
import folder_paths
4+
5+
6+
def execute_prestartup_script():
7+
def execute_script(script_path):
8+
if os.path.exists(script_path):
9+
module_name = os.path.splitext(script_path)[0]
10+
try:
11+
spec = importlib.util.spec_from_file_location(module_name, script_path)
12+
module = importlib.util.module_from_spec(spec)
13+
spec.loader.exec_module(module)
14+
except Exception as e:
15+
print(f"Failed to execute startup-script: {script_path} / {e}")
16+
17+
node_paths = folder_paths.get_folder_paths("custom_nodes")
18+
for custom_node_path in node_paths:
19+
possible_modules = os.listdir(custom_node_path)
20+
21+
for possible_module in possible_modules:
22+
module_path = os.path.join(custom_node_path, possible_module)
23+
if os.path.isfile(module_path) or module_path.endswith(".disabled") or module_path == "__pycache__":
24+
continue
25+
26+
script_path = os.path.join(module_path, "prestartup_script.py")
27+
execute_script(script_path)
28+
29+
30+
execute_prestartup_script()
31+
32+
33+
# Main code
134
import asyncio
235
import itertools
3-
import os
436
import shutil
537
import threading
638
import gc
@@ -22,7 +54,6 @@
2254
import yaml
2355

2456
import execution
25-
import folder_paths
2657
import server
2758
from server import BinaryEventTypes
2859
from nodes import init_custom_nodes

0 commit comments

Comments
 (0)