From 0f82948e4f46ca27acbf3ffb817cabec402c6438 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Mon, 15 Apr 2024 22:14:19 -0400 Subject: [PATCH 1/2] Fix cls.__module__ --- .../hypertile/scripts/hypertile_xyz.py | 2 +- modules/script_loading.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/extensions-builtin/hypertile/scripts/hypertile_xyz.py b/extensions-builtin/hypertile/scripts/hypertile_xyz.py index 9e96ae3c527..386c6b2d669 100644 --- a/extensions-builtin/hypertile/scripts/hypertile_xyz.py +++ b/extensions-builtin/hypertile/scripts/hypertile_xyz.py @@ -1,7 +1,7 @@ from modules import scripts from modules.shared import opts -xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "xyz_grid.py"][0].module +xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "scripts.xyz_grid"][0].module def int_applier(value_name:str, min_range:int = -1, max_range:int = -1): """ diff --git a/modules/script_loading.py b/modules/script_loading.py index 17f658b1544..c505c0b84ad 100644 --- a/modules/script_loading.py +++ b/modules/script_loading.py @@ -9,15 +9,13 @@ def load_module(path): - module_spec = importlib.util.spec_from_file_location(os.path.basename(path), path) + module_name, _ = os.path.splitext(os.path.basename(path)) + full_module_name = "scripts." + module_name + module_spec = importlib.util.spec_from_file_location(full_module_name, path) module = importlib.util.module_from_spec(module_spec) module_spec.loader.exec_module(module) - - loaded_scripts[path] = module - - module_name, _ = os.path.splitext(os.path.basename(path)) - sys.modules["scripts." + module_name] = module - + loaded_scripts[full_module_name] = module + sys.modules[full_module_name] = module return module From a95326bec434da5d0a2aeb943d35cfded75e3afa Mon Sep 17 00:00:00 2001 From: huchenlei Date: Mon, 15 Apr 2024 22:34:01 -0400 Subject: [PATCH 2/2] nit --- modules/script_loading.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/script_loading.py b/modules/script_loading.py index c505c0b84ad..20c7998acec 100644 --- a/modules/script_loading.py +++ b/modules/script_loading.py @@ -14,7 +14,7 @@ def load_module(path): module_spec = importlib.util.spec_from_file_location(full_module_name, path) module = importlib.util.module_from_spec(module_spec) module_spec.loader.exec_module(module) - loaded_scripts[full_module_name] = module + loaded_scripts[path] = module sys.modules[full_module_name] = module return module