From 4366ebc4353259147528fc5e269a78d5b7d5a676 Mon Sep 17 00:00:00 2001 From: cobycloud <25079070+cobycloud@users.noreply.github.com> Date: Sat, 4 Jan 2025 05:12:16 -0600 Subject: [PATCH] mono - remove special lazy handlers --- pkgs/swarmauri/swarmauri/importer.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/pkgs/swarmauri/swarmauri/importer.py b/pkgs/swarmauri/swarmauri/importer.py index ac286726..746e1e18 100644 --- a/pkgs/swarmauri/swarmauri/importer.py +++ b/pkgs/swarmauri/swarmauri/importer.py @@ -41,14 +41,12 @@ def find_spec(self, fullname, path=None, target=None): logger.debug(f"Found external module mapping: {fullname} -> {external_module_path}") return ModuleSpec(fullname, self) - # Attempt to register the plugin without loading - if fullname in PluginCitizenshipRegistry.total_registry(): - resource_path = fullname - type_info = get_plugin_type_info(resource_path) - if type_info: - # Do not load the module yet; registration already handled - logger.debug(f"Plugin '{fullname}' is registered for lazy loading.") - return ModuleSpec(fullname, self) + # If lazy, then we need to add LazyLoader + external_module_path = PluginCitizenshipRegistry.get_external_module_path(fullname) + if external_module_path: + # If we detect lazy strategy, then we utilize LazyLoader + logger.debug(f"Found external module mapping: {fullname} -> {external_module_path}") + return ModuleSpec(fullname, importlib.util.LazyLoader(self)) logger.debug(f"Module '{fullname}' not found. Returning None.") return None @@ -77,14 +75,6 @@ def create_module(self, spec): sys.modules[spec.name] = module return module - # Handle lazy-loaded plugins - if spec.name in PluginCitizenshipRegistry.total_registry(): - module_path = PluginCitizenshipRegistry.total_registry()[spec.name] - logger.debug(f"Lazy loading module '{spec.name}' from '{module_path}'") - module = importlib.import_module(module_path) - sys.modules[spec.name] = module - return module - logger.error(f"Cannot create module '{spec.name}'. Raising ImportError.") raise ImportError(f"Cannot create module {spec.name}")