diff --git a/.gitignore b/.gitignore index 38d2ba11b..21a85d316 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ extra_model_paths.yaml venv/ web/extensions/* !web/extensions/logging.js.example -!web/extensions/core/ \ No newline at end of file +!web/extensions/core/ +startup-scripts/ \ No newline at end of file diff --git a/main.py b/main.py index 715649975..28b6e5b62 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,31 @@ +import os +import glob +import importlib.util + +# When the startup script is executed, it should ensure that it has minimal dependencies. +# This startup script can be executed while minimizing the impact of package locking caused by imports in Windows, especially during dependency installation processes. +startup_scripts_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), "startup-scripts") +script_files = glob.glob(os.path.join(startup_scripts_path, "*.py")) + +if os.path.exists(startup_scripts_path): + script_files = os.listdir(startup_scripts_path) + + # Import each script file to execute + for script_file in script_files: + if script_file.endswith(".py"): + script_path = os.path.join(startup_scripts_path, script_file) + module_name = os.path.splitext(script_file)[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_file} / {e}") + + +# Main code import asyncio import itertools -import os import shutil import threading import gc