mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-08-03 10:50:23 +00:00
Add option to preload extensions
By creating a file called "preload.py" in an extension folder and declaring a preload(parser) method, we can add extra command-line args for an extension.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
from importlib.machinery import SourceFileLoader
|
||||
|
||||
import git
|
||||
|
||||
from modules import paths, shared
|
||||
|
||||
|
||||
extensions = []
|
||||
extensions_dir = os.path.join(paths.script_path, "extensions")
|
||||
|
||||
@@ -84,3 +84,24 @@ def list_extensions():
|
||||
|
||||
extension = Extension(name=dirname, path=path, enabled=dirname not in shared.opts.disabled_extensions)
|
||||
extensions.append(extension)
|
||||
|
||||
|
||||
def preload_extensions(parser):
|
||||
if not os.path.isdir(extensions_dir):
|
||||
return
|
||||
|
||||
for dirname in sorted(os.listdir(extensions_dir)):
|
||||
path = os.path.join(extensions_dir, dirname)
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
for file in os.listdir(path):
|
||||
if "preload.py" in file:
|
||||
full_file = os.path.join(path, file)
|
||||
print(f"Got preload file: {full_file}")
|
||||
|
||||
try:
|
||||
ext = SourceFileLoader("preload", full_file).load_module()
|
||||
parser = ext.preload(parser)
|
||||
except Exception as e:
|
||||
print(f"Exception preloading script: {e}")
|
||||
return parser
|
Reference in New Issue
Block a user