Skip to content

Commit

Permalink
mono - enhancing logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cobycloud committed Dec 27, 2024
1 parent 19c5be2 commit aeef7a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkgs/swarmauri/swarmauri/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ def _try_register_plugin(self, fullname):

# Fetch and filter entry points dynamically
grouped_entry_points = get_entry_points()
logger.info(f"Grouped entry points: '{grouped_entry_points}'")
logger.debug(f"Grouped entry points: '{grouped_entry_points}'")
entry_points = grouped_entry_points.get(local_namespace, [])
logger.info(f"Entry points: '{entry_points}'")
logger.debug(f"Entry points: '{entry_points}'")

for entry_point in entry_points:
if entry_point.name == plugin_name:
# Process the plugin via plugin manager
process_plugin(entry_point)
sys.modules[fullname] = entry_point.load()
logger.info(f"Successfully registered and loaded plugin '{fullname}'")
logger.debug(f"Successfully registered and loaded plugin '{fullname}'")
return True

except Exception as e:
Expand Down
18 changes: 10 additions & 8 deletions pkgs/swarmauri/swarmauri/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def get_entry_points(group_prefix="swarmauri."):
namespace = ep.group[len(group_prefix):]
grouped_entry_points.setdefault(namespace, []).append(ep)

logger.debug(f"Returning the following grouped_entry_points: {grouped_entry_points}")
return grouped_entry_points

except Exception as e:
Expand Down Expand Up @@ -100,6 +101,7 @@ def validate(self, name, plugin_class, resource_kind, resource_interface):
1. A subclass of the required resource interface.
2. Already pre-registered as a first-class plugin.
"""
logging.debug(F"Running First Class Validation on: {name}, {plugin_class}, {resource_kind}, {resource_interface}")
if not issubclass(plugin_class, resource_interface):
raise TypeError(
f"Plugin '{name}' must implement the '{resource_interface.__name__}' interface."
Expand All @@ -116,7 +118,7 @@ def register(self, name, plugin_class, resource_kind):
"""
Pass-through method for first-class plugins, as they are pre-registered.
"""
logger.info(
logger.debug(
f"Plugin '{name}' is already pre-registered as a first-class plugin. "
"No additional registration is required."
)
Expand All @@ -131,7 +133,7 @@ def validate(self, name, plugin_class, resource_kind, resource_interface):
"""
Validate that the plugin implements the required interface and does not conflict with first-class citizens.
"""

logging.debug(F"Running Second Class Validation on: {name}, {plugin_class}, {resource_kind}, {resource_interface}")
if not resource_kind == 'utils':
if not issubclass(plugin_class, resource_interface):
raise TypeError(
Expand Down Expand Up @@ -174,7 +176,7 @@ def register(self, entry_points):
self.validate(name, plugin_class, resource_kind, resource_interface)

create_entry("second", resource_path, plugin_class.__module__)
logger.info(f"Registered second-class plugin: {plugin_class.__module__} -> {resource_path}")
logger.debug(f"Registered second-class plugin: {plugin_class.__module__} -> {resource_path}")



Expand All @@ -186,7 +188,7 @@ def validate(self, name, plugin_class, resource_kind, resource_interface):
"""
No validation required for third-class plugins.
"""
pass
logging.debug(F"Passing through Third Class validation on: {name}, {plugin_class}, {resource_kind}, {resource_interface}")

def register(self, name, plugin_class, resource_kind):
"""
Expand All @@ -197,7 +199,7 @@ def register(self, name, plugin_class, resource_kind):
raise ValueError(f"Plugin '{name}' is already registered as a third-class citizen.")

create_entry("third", resource_path, plugin_class.__module__)
logger.info(f"Registered third-class citizen: {resource_path}")
logger.debug(f"Registered third-class citizen: {resource_path}")


def validate_and_register_plugin(entry_point, plugin_class, resource_interface):
Expand Down Expand Up @@ -257,7 +259,7 @@ def determine_plugin_manager(entry_point):
try:
# Third-Class Plugins: Group is exactly "swarmauri.plugins"
if entry_point.group == "swarmauri.plugins":
logger.info(f"Plugin '{entry_point.name}' recognized as a third-class plugin.")
logger.debug(f"Plugin '{entry_point.name}' recognized as a third-class plugin.")
return ThirdClassPluginManager()

# First-Class and Second-Class Plugins: Group starts with "swarmauri."
Expand All @@ -270,7 +272,7 @@ def determine_plugin_manager(entry_point):
manager = FirstClassPluginManager()
plugin_class = entry_point.load()
manager.validate(entry_point.name, plugin_class, resource_kind, resource_interface)
logger.info(f"Plugin '{entry_point.name}' recognized as a first-class plugin.")
logger.debug(f"Plugin '{entry_point.name}' recognized as a first-class plugin.")
return manager
except (TypeError, ValueError):
logger.debug(f"Plugin '{entry_point.name}' is not a first-class plugin. Trying second-class.")
Expand All @@ -280,7 +282,7 @@ def determine_plugin_manager(entry_point):
manager = SecondClassPluginManager()
plugin_class = entry_point.load()
manager.validate(entry_point.name, plugin_class, resource_kind, resource_interface)
logger.info(f"Plugin '{entry_point.name}' recognized as a second-class plugin.")
logger.debug(f"Plugin '{entry_point.name}' recognized as a second-class plugin.")
return manager
except (TypeError, ValueError):
logger.debug(f"Plugin '{entry_point.name}' is not a second-class plugin.")
Expand Down

0 comments on commit aeef7a9

Please sign in to comment.