Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/startup-script: Feature to avoid package installation errors when installing custom nodes. #856

Merged
merged 5 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ extra_model_paths.yaml
venv/
web/extensions/*
!web/extensions/logging.js.example
!web/extensions/core/
!web/extensions/core/
startup-scripts/
35 changes: 33 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import os
import importlib.util
import folder_paths


def execute_prestartup_script():
def execute_script(script_path):
if os.path.exists(script_path):
module_name = os.path.splitext(script_path)[0]
try:
spec = importlib.util.spec_from_file_location(module_name, script_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
except Exception as e:
print(f"Failed to execute startup-script: {script_path} / {e}")

node_paths = folder_paths.get_folder_paths("custom_nodes")
for custom_node_path in node_paths:
possible_modules = os.listdir(custom_node_path)

for possible_module in possible_modules:
module_path = os.path.join(custom_node_path, possible_module)
if os.path.isfile(module_path) or module_path.endswith(".disabled") or module_path == "__pycache__":
continue

script_path = os.path.join(module_path, "prestartup_script.py")
execute_script(script_path)


execute_prestartup_script()


# Main code
import asyncio
import itertools
import os
import shutil
import threading
import gc
Expand All @@ -22,7 +54,6 @@
import yaml

import execution
import folder_paths
import server
from server import BinaryEventTypes
from nodes import init_custom_nodes
Expand Down