mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2026-03-13 00:49:48 +00:00
Gradio 4 + WebUI 1.10
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
import dataclasses
|
||||
import os
|
||||
import threading
|
||||
import re
|
||||
@@ -10,6 +11,10 @@ from modules.gitpython_hack import Repo
|
||||
from modules.paths_internal import extensions_dir, extensions_builtin_dir, script_path # noqa: F401
|
||||
from modules_forge.config import always_disabled_extensions
|
||||
|
||||
extensions: list[Extension] = []
|
||||
extension_paths: dict[str, Extension] = {}
|
||||
loaded_extensions: dict[str, Exception] = {}
|
||||
|
||||
|
||||
os.makedirs(extensions_dir, exist_ok=True)
|
||||
|
||||
@@ -23,6 +28,13 @@ def active():
|
||||
return [x for x in extensions if x.enabled]
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class CallbackOrderInfo:
|
||||
name: str
|
||||
before: list
|
||||
after: list
|
||||
|
||||
|
||||
class ExtensionMetadata:
|
||||
filename = "metadata.ini"
|
||||
config: configparser.ConfigParser
|
||||
@@ -43,7 +55,7 @@ class ExtensionMetadata:
|
||||
self.canonical_name = self.config.get("Extension", "Name", fallback=canonical_name)
|
||||
self.canonical_name = canonical_name.lower().strip()
|
||||
|
||||
self.requires = self.get_script_requirements("Requires", "Extension")
|
||||
self.requires = None
|
||||
|
||||
def get_script_requirements(self, field, section, extra_section=None):
|
||||
"""reads a list of requirements from the config; field is the name of the field in the ini file,
|
||||
@@ -55,7 +67,15 @@ class ExtensionMetadata:
|
||||
if extra_section:
|
||||
x = x + ', ' + self.config.get(extra_section, field, fallback='')
|
||||
|
||||
return self.parse_list(x.lower())
|
||||
listed_requirements = self.parse_list(x.lower())
|
||||
res = []
|
||||
|
||||
for requirement in listed_requirements:
|
||||
loaded_requirements = (x for x in requirement.split("|") if x in loaded_extensions)
|
||||
relevant_requirement = next(loaded_requirements, requirement)
|
||||
res.append(relevant_requirement)
|
||||
|
||||
return res
|
||||
|
||||
def parse_list(self, text):
|
||||
"""converts a line from config ("ext1 ext2, ext3 ") into a python list (["ext1", "ext2", "ext3"])"""
|
||||
@@ -66,6 +86,22 @@ class ExtensionMetadata:
|
||||
# both "," and " " are accepted as separator
|
||||
return [x for x in re.split(r"[,\s]+", text.strip()) if x]
|
||||
|
||||
def list_callback_order_instructions(self):
|
||||
for section in self.config.sections():
|
||||
if not section.startswith("callbacks/"):
|
||||
continue
|
||||
|
||||
callback_name = section[10:]
|
||||
|
||||
if not callback_name.startswith(self.canonical_name):
|
||||
errors.report(f"Callback order section for extension {self.canonical_name} is referencing the wrong extension: {section}")
|
||||
continue
|
||||
|
||||
before = self.parse_list(self.config.get(section, 'Before', fallback=''))
|
||||
after = self.parse_list(self.config.get(section, 'After', fallback=''))
|
||||
|
||||
yield CallbackOrderInfo(callback_name, before, after)
|
||||
|
||||
|
||||
class Extension:
|
||||
lock = threading.Lock()
|
||||
@@ -156,14 +192,17 @@ class Extension:
|
||||
|
||||
def check_updates(self):
|
||||
repo = Repo(self.path)
|
||||
branch_name = f'{repo.remote().name}/{self.branch}'
|
||||
for fetch in repo.remote().fetch(dry_run=True):
|
||||
if self.branch and fetch.name != branch_name:
|
||||
continue
|
||||
if fetch.flags != fetch.HEAD_UPTODATE:
|
||||
self.can_update = True
|
||||
self.status = "new commits"
|
||||
return
|
||||
|
||||
try:
|
||||
origin = repo.rev_parse('origin')
|
||||
origin = repo.rev_parse(branch_name)
|
||||
if repo.head.commit != origin:
|
||||
self.can_update = True
|
||||
self.status = "behind HEAD"
|
||||
@@ -176,8 +215,10 @@ class Extension:
|
||||
self.can_update = False
|
||||
self.status = "latest"
|
||||
|
||||
def fetch_and_reset_hard(self, commit='origin'):
|
||||
def fetch_and_reset_hard(self, commit=None):
|
||||
repo = Repo(self.path)
|
||||
if commit is None:
|
||||
commit = f'{repo.remote().name}/{self.branch}'
|
||||
# Fix: `error: Your local changes to the following files would be overwritten by merge`,
|
||||
# because WSL2 Docker set 755 file permissions instead of 644, this results to the error.
|
||||
repo.git.fetch(all=True)
|
||||
@@ -187,6 +228,8 @@ class Extension:
|
||||
|
||||
def list_extensions():
|
||||
extensions.clear()
|
||||
extension_paths.clear()
|
||||
loaded_extensions.clear()
|
||||
|
||||
if shared.cmd_opts.disable_all_extensions:
|
||||
print("*** \"--disable-all-extensions\" arg was used, will not load any extensions ***")
|
||||
@@ -197,7 +240,6 @@ def list_extensions():
|
||||
elif shared.opts.disable_all_extensions == "extra":
|
||||
print("*** \"Disable all extensions\" option was set, will only load built-in extensions ***")
|
||||
|
||||
loaded_extensions = {}
|
||||
|
||||
# scan through extensions directory and load metadata
|
||||
for dirname in [extensions_builtin_dir, extensions_dir]:
|
||||
@@ -231,8 +273,12 @@ def list_extensions():
|
||||
)
|
||||
|
||||
extensions.append(extension)
|
||||
extension_paths[extension.path] = extension
|
||||
loaded_extensions[canonical_name] = extension
|
||||
|
||||
for extension in extensions:
|
||||
extension.metadata.requires = extension.metadata.get_script_requirements("Requires", "Extension")
|
||||
|
||||
# check for requirements
|
||||
for extension in extensions:
|
||||
if not extension.enabled:
|
||||
@@ -249,4 +295,16 @@ def list_extensions():
|
||||
continue
|
||||
|
||||
|
||||
extensions: list[Extension] = []
|
||||
def find_extension(filename):
|
||||
parentdir = os.path.dirname(os.path.realpath(filename))
|
||||
|
||||
while parentdir != filename:
|
||||
extension = extension_paths.get(parentdir)
|
||||
if extension is not None:
|
||||
return extension
|
||||
|
||||
filename = parentdir
|
||||
parentdir = os.path.dirname(filename)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user