From 71b29c996b39b81a42585ef95bdb5f315e1e4d23 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 18 Apr 2023 14:31:40 -0400 Subject: [PATCH] change script/extension loading priorities --- README.md | 23 ++++++------- TODO.md | 14 ++++++-- extensions-builtin/sd-extension-system-info | 2 +- extensions-builtin/sd-webui-controlnet | 2 +- modules/generation_parameters_copypaste.py | 7 ++-- modules/postprocessing.py | 2 ++ modules/scripts.py | 36 ++++++++++++++------- setup.py | 9 ++++++ 8 files changed, 65 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 08b960dae..8c1d82593 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you are looking an amazing simple-to-use Stable Diffusion tool, I'd suggest [
-![screenshot](javscript/black-orange.jpg) +![screenshot](javascript/black-orange.jpg)
@@ -37,8 +37,6 @@ If you are looking an amazing simple-to-use Stable Diffusion tool, I'd suggest [ - Majority of settings configurable via UI without the need for command line flags e.g, cross-optimization methods, system folders, etc. -### UI - ### Optimizations - Optimized for `Torch` 2.0 @@ -65,10 +63,11 @@ Hand-picked list of extensions that are deeply integrated into core workflows: ### User Interface -- Includes support for **Gradio themes** - *Settings* -> *User interface* -> *UI theme* - Includes updated **UI**: reskinned and reorganized Black and orange dark theme with fixed width options panels and larger previews +- Includes support for **Gradio themes** + *Settings* -> *User interface* -> *UI theme* + Link to themes list & previews: ### Removed @@ -124,13 +123,15 @@ Full startup sequence is logged in `setup.log`, so if you encounter any issues, The launcher can perform automatic update of main repository, requirements, extensions and submodules: -- Main repository: +- **Main repository**: Update is *not* performed by default, enable with `--upgrade` flag -- Requirements: - Check is performed on each startup and missing requirements are auto-installed, can be skipped with `--skip-requirements` flag -- Extensions and submodules: - Update is performed on each startup and installer for each extension is started, can be skipped with `--skip-extensions` flag -- If timestamp of last sucessful setup is newer than actual repository version or version of newest extension, launcher will run in *quick* mode +- **Requirements**: + Check is performed on each startup and missing requirements are auto-installed + Can be skipped with `--skip-requirements` flag +- **Extensions and submodules**: + Update is performed on each startup and installer for each extension is started + Can be skipped with `--skip-extensions` flag +- **Quick mode**: Automatically enabled if timestamp of last sucessful setup is newer than actual repository version or version of newest extension
diff --git a/TODO.md b/TODO.md index bd6571c94..60ee862b1 100644 --- a/TODO.md +++ b/TODO.md @@ -93,10 +93,18 @@ Tech that can be integrated as part of the core workflow... ### Update - reconnect ui to active session on browser restart + this is one of most frequently asked for items, finally figured it out works for text and image generation, but not for process as there is no progress bar reported there to start with -- force unload `xformers` when not used, improves compatibility with AMD/M1 -- add `styles.csv` to UI settings to allow customizing path +- force unload `xformers` when not used + improves compatibility with AMD/M1 platforms +- add `styles.csv` to UI settings to allow customizing path +- add `--skip-git` to cmd flags for power users that want + to skip all git checks and operations and perform manual updates - add `--disable-queue` to cmd flags that disables Gradio queues (experimental) this forces it to use HTTP instead of WebSockets and can help on unreliable network connections -- allow scripts & extensions to set loading priority, fixes `ScuNet` +- set scripts & extensions loading priority and allow custom priorities + fixes random extension issues: + `ScuNet` upscaler dissapearing, `Additional Networks` not showing up on XYZ axis, etc. - improve html loading order +- remove some `asserts` causing runtime errors and replace with user-friendly messages +- update README.md diff --git a/extensions-builtin/sd-extension-system-info b/extensions-builtin/sd-extension-system-info index b0a4fd79b..52cd26c76 160000 --- a/extensions-builtin/sd-extension-system-info +++ b/extensions-builtin/sd-extension-system-info @@ -1 +1 @@ -Subproject commit b0a4fd79b56c9187f103dbbc04b73f3dee8824f6 +Subproject commit 52cd26c766ef52060675b46ffbc7c004d5542c78 diff --git a/extensions-builtin/sd-webui-controlnet b/extensions-builtin/sd-webui-controlnet index c98dca501..7d28d00e2 160000 --- a/extensions-builtin/sd-webui-controlnet +++ b/extensions-builtin/sd-webui-controlnet @@ -1 +1 @@ -Subproject commit c98dca50143d60f42efc756128aa0ba088647716 +Subproject commit 7d28d00e299078454d20ca1a8b09a8aa4ea76ee7 diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index f960b709f..38ff66ca5 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -53,9 +53,10 @@ def image_from_url_text(filedata): if type(filedata) == dict and filedata.get("is_file", False): filename = filedata["name"] is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename) - assert is_in_right_dir, 'trying to open image file outside of allowed directories' - - return Image.open(filename) + if is_in_right_dir: + return Image.open(filename) + else: + print(f'Attempted to open file outside of allowed directories: {filename}') if type(filedata) == list: if len(filedata) == 0: diff --git a/modules/postprocessing.py b/modules/postprocessing.py index 0e688a8e0..6fffd79c6 100644 --- a/modules/postprocessing.py +++ b/modules/postprocessing.py @@ -45,6 +45,8 @@ def run_postprocessing(extras_mode, image, image_folder, input_dir, output_dir, infotext = '' for image, name in zip(image_data, image_names): + if image is None: + continue shared.state.textinfo = name pp = scripts_postprocessing.PostprocessedImage(image.convert("RGB")) diff --git a/modules/scripts.py b/modules/scripts.py index ec716492b..8f7a37708 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -187,23 +187,38 @@ ScriptClassData = namedtuple("ScriptClassData", ["script_class", "path", "basedi def list_scripts(scriptdirname, extension): - scripts_list = [] + tmp_list = [] base = os.path.join(paths.script_path, scriptdirname) if os.path.exists(base): - priority = '50' - if os.path.isfile(os.path.join(base, "..", ".priority")): - with open(os.path.join(base, "..", ".priority"), "r", encoding="utf-8") as f: - priority = str(f.read().strip()) for filename in sorted(os.listdir(base)): - scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), priority)) + tmp_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), '50')) for ext in extensions.active(): - scripts_list += ext.list_files(scriptdirname, extension) + tmp_list += ext.list_files(scriptdirname, extension) - scripts_list = [x for x in scripts_list if os.path.splitext(x.path)[1].lower() == extension and os.path.isfile(x.path)] + scripts_list = [] + for script in tmp_list: + if os.path.splitext(script.path)[1].lower() == extension and os.path.isfile(script.path): + if script.basedir == paths.script_path: + priority = '0' + elif script.basedir.startswith(os.path.join(paths.script_path, 'scripts')): + priority = '1' + elif script.basedir.startswith(os.path.join(paths.script_path, 'extensions-builtin')): + priority = '2' + elif script.basedir.startswith(os.path.join(paths.script_path, 'extensions')): + priority = '3' + else: + priority = '9' + if os.path.isfile(os.path.join(base, "..", ".priority")): + with open(os.path.join(base, "..", ".priority"), "r", encoding="utf-8") as f: + priority = priority + str(f.read().strip()) + else: + priority = priority + script.priority + scripts_list.append(ScriptFile(script.basedir, script.filename, script.path, priority)) - return scripts_list + priority_sort = sorted(scripts_list, key=lambda item: item.priority + item.path.lower(), reverse=False) + return priority_sort def list_files_with_name(filename): @@ -242,8 +257,7 @@ def load_scripts(): elif issubclass(script_class, scripts_postprocessing.ScriptPostprocessing): postprocessing_scripts_data.append(ScriptClassData(script_class, scriptfile.path, scriptfile.basedir, module)) - priority_sort = sorted(scripts_list, key=lambda item: item.priority + item.path.lower(), reverse=False) - for scriptfile in priority_sort: + for scriptfile in scripts_list: try: if scriptfile.basedir != paths.script_path: sys.path = [scriptfile.basedir] + sys.path diff --git a/setup.py b/setup.py index 56ec39ef1..afa3420c5 100644 --- a/setup.py +++ b/setup.py @@ -109,6 +109,8 @@ def install(package, friendly: str = None, ignore: bool = False): # execute git command def git(arg: str, ignore: bool = False): + if args.skip_git: + return '' git_cmd = os.environ.get('GIT', "git") result = subprocess.run(f'"{git_cmd}" {arg}', check=False, shell=True, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE) txt = result.stdout.decode(encoding="utf8", errors="ignore") @@ -347,6 +349,8 @@ def check_extensions(): newest = 0 extension_dir = os.path.join(extensions_dir, ext) for f in os.listdir(extension_dir): + if '.json' in f or '.csv' in f: + continue ts = os.path.getmtime(os.path.join(extension_dir, f)) newest = max(newest, ts) newest_all = max(newest_all, newest) @@ -397,6 +401,8 @@ def check_version(): def check_timestamp(): if not quick_allowed or not os.path.isfile('setup.log'): return False + if args.skip_git: + return True ok = True setup_time = -1 with open('setup.log', 'r', encoding='utf8') as f: @@ -434,6 +440,7 @@ def parse_args(): parser.add_argument('--noupdate', default = False, action='store_true', help = "Skip update of extensions and submodules, default: %(default)s") parser.add_argument('--skip-requirements', default = False, action='store_true', help = "Skips checking and installing requirements, default: %(default)s") parser.add_argument('--skip-extensions', default = False, action='store_true', help = "Skips running individual extension installers, default: %(default)s") + parser.add_argument('--skip-git', default = False, action='store_true', help = "Skips running all GIT operations, default: %(default)s") global args # pylint: disable=global-statement args = parser.parse_args() @@ -455,6 +462,8 @@ def run_setup(): check_python() if args.reset: git_reset() + if args.skip_git: + log.info('Skipping GIT operations') if check_timestamp(): log.info('No changes detected: quick launch active') return