mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
Keep option type definitions together...
and update type annotations. - Since there's no literal for sets, and because functions usually shouldn't be used as parameter defaults, use None as default and then use `set()` as default during init.
This commit is contained in:
+6
-1
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||
from installer import log
|
||||
|
||||
|
||||
def options_section(section_identifier: tuple[str, str], options_dict: dict[str, OptionInfo]):
|
||||
def options_section(section_identifier: tuple[str, str], options_dict: dict[str, OptionInfo | LegacyOption]):
|
||||
for v in options_dict.values():
|
||||
v.section = section_identifier
|
||||
return options_dict
|
||||
@@ -109,6 +109,11 @@ class OptionInfo:
|
||||
return f'OptionInfo: label="{self.label}" section="{self.section}" component="{self.component}" default="{self.default}" refresh="{self.refresh is not None}" change="{self.onchange is not None}" args={args} choices={choices}'
|
||||
|
||||
|
||||
class LegacyOption(OptionInfo):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
@dataclass
|
||||
class OptionsCategory:
|
||||
id: str
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import os
|
||||
import json
|
||||
import threading
|
||||
from typing import TYPE_CHECKING
|
||||
from modules import cmd_args, errors
|
||||
from modules.json_helpers import readfile, writefile
|
||||
from modules.shared_legacy import LegacyOption
|
||||
from modules.options import OptionInfo, LegacyOption
|
||||
from installer import log
|
||||
if TYPE_CHECKING:
|
||||
from modules.options import OptionInfo
|
||||
|
||||
|
||||
cmd_opts = cmd_args.parse_args()
|
||||
@@ -21,7 +18,9 @@ class Options():
|
||||
typemap = {int: float}
|
||||
debug = os.environ.get('SD_CONFIG_DEBUG', None) is not None
|
||||
|
||||
def __init__(self, options_templates:dict={}, restricted_opts:dict={}):
|
||||
def __init__(self, options_templates: dict[str, OptionInfo | LegacyOption] = {}, restricted_opts: set[str] | None = None):
|
||||
if restricted_opts is None:
|
||||
restricted_opts = set()
|
||||
self.data_labels = options_templates
|
||||
self.restricted_opts = restricted_opts
|
||||
self.data = {k: v.default for k, v in self.data_labels.items()}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ from modules.memstats import memory_stats, ram_stats # pylint: disable=unused-im
|
||||
from modules.interrogate.openclip import caption_models, caption_types, get_clip_models, refresh_clip_models
|
||||
from modules.interrogate.vqa import vlm_models, vlm_prompts, vlm_system, vlm_default
|
||||
from modules.ui_components import DropdownEditable
|
||||
from modules.options import OptionInfo, options_section
|
||||
from modules.options import OptionInfo, LegacyOption, options_section
|
||||
import modules.memmon
|
||||
import modules.styles
|
||||
import modules.paths as paths
|
||||
@@ -51,7 +51,7 @@ face_restorers = []
|
||||
yolo = None
|
||||
tab_names = []
|
||||
extra_networks: list[ExtraNetworksPage] = []
|
||||
options_templates = {}
|
||||
options_templates: dict[str, OptionInfo | LegacyOption] = {}
|
||||
hypernetworks = {}
|
||||
settings_components = {}
|
||||
restricted_opts = {
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import os
|
||||
import gradio as gr
|
||||
from modules import paths
|
||||
from modules.options import OptionInfo, options_section
|
||||
|
||||
|
||||
class LegacyOption(OptionInfo):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
from modules.options import LegacyOption, options_section
|
||||
|
||||
|
||||
legacy_options = options_section(('legacy_options', "Legacy options"), {
|
||||
|
||||
Reference in New Issue
Block a user