From 3ac193eed2967739f496b0e592fd230c1dfa6ac5 Mon Sep 17 00:00:00 2001 From: Wang Yi <53533850+marigoold@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:20:40 +0800 Subject: [PATCH] webui fix bug of AttrError shared.opt.onediff_compiler_cache_path (#989) --- onediff_sd_webui_extensions/onediff_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/onediff_sd_webui_extensions/onediff_utils.py b/onediff_sd_webui_extensions/onediff_utils.py index 29b029bf1..4e5172dcf 100644 --- a/onediff_sd_webui_extensions/onediff_utils.py +++ b/onediff_sd_webui_extensions/onediff_utils.py @@ -49,6 +49,11 @@ def all_compiler_caches_path(): import modules.shared as shared + # for webui <= 1.8, the function will be called before ui initialized + # At that time, shared opts doesn't have attribute `onediff_compiler_caches_path` + if not hasattr(shared.opts, "onediff_compiler_caches_path"): + return None + caches_path = Path(shared.opts.onediff_compiler_caches_path) if not caches_path.exists(): caches_path.mkdir(parents=True) @@ -65,6 +70,9 @@ def get_all_compiler_caches(): def refresh_all_compiler_caches(path: Path = None): global all_compiler_caches path = path or all_compiler_caches_path() + if path is None: + return + all_compiler_caches = [f.stem for f in Path(path).iterdir() if f.is_file()]