From 42ea6a3fc03cb88aebf89215c2c5167b1e1f54d5 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 7 Apr 2023 12:20:57 -0300 Subject: [PATCH] Change the timing for setup() calls --- modules/extensions.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/extensions.py b/modules/extensions.py index fca68188..eded405c 100644 --- a/modules/extensions.py +++ b/modules/extensions.py @@ -11,29 +11,31 @@ setup_called = set() def load_extensions(): - global state + global state, setup_called for i, name in enumerate(shared.args.extensions): if name in available_extensions: print(f'Loading the extension "{name}"... ', end='') try: exec(f"import extensions.{name}.script") + extension = eval(f"extensions.{name}.script") + if extension not in setup_called and hasattr(extension, "setup"): + setup_called.add(extension) + extension.setup() state[name] = [True, i] print('Ok.') except: print('Fail.') traceback.print_exc() + # This iterator returns the extensions in the order specified in the command-line - - def iterator(): for name in sorted(state, key=lambda x: state[x][1]): if state[name][0]: yield eval(f"extensions.{name}.script"), name + # Extension functions that map string -> string - - def apply_extensions(text, typ): for extension, _ in iterator(): if typ == "input" and hasattr(extension, "input_modifier"): @@ -57,14 +59,9 @@ def create_extensions_block(): extension.params[param] = shared.settings[_id] should_display_ui = False - - # Running setup function for extension, name in iterator(): if hasattr(extension, "ui"): should_display_ui = True - if extension not in setup_called and hasattr(extension, "setup"): - setup_called.add(extension) - extension.setup() # Creating the extension ui elements if should_display_ui: