Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permissive plugin loading #1086

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aries_cloudagent/core/plugin_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def register_plugin(self, module_name: str) -> ModuleType:
LOGGER.error(f"Module doesn't exist: {module_name}")
return None

# Any plugin with a setup method is considered valid.
if hasattr(mod, "setup"):
self._plugins[module_name] = mod
return mod

# Make an exception for non-protocol modules
# that contain admin routes and for old-style protocol
# modules without version support
Expand Down
22 changes: 19 additions & 3 deletions aries_cloudagent/core/tests/test_plugin_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ async def test_register_plugin_no_definition(self):
ClassLoader, "load_module", async_mock.MagicMock()
) as load_module:
load_module.side_effect = [
async_mock.MagicMock(), # module
{}, # module
None, # routes
None, # message types
None, # definition
Expand All @@ -442,19 +442,35 @@ async def test_register_plugin_no_versions(self):
ClassLoader, "load_module", async_mock.MagicMock()
) as load_module:
load_module.side_effect = [
async_mock.MagicMock(), # module
{}, # module
None, # routes
None, # message types
"str-has-no-versions-attr", # definition without versions attr
]
assert self.registry.register_plugin("dummy") is None

async def test_register_plugin_has_setup(self):
class MODULE:
setup = "present"

obj = MODULE()
with async_mock.patch.object(
ClassLoader, "load_module", async_mock.MagicMock()
) as load_module:
load_module.side_effect = [
obj, # module
None, # routes
None, # message types
None, # definition without versions attr
]
assert self.registry.register_plugin("dummy") == obj

async def test_register_definitions_malformed(self):
with async_mock.patch.object(
ClassLoader, "load_module", async_mock.MagicMock()
) as load_module:
load_module.side_effect = [
async_mock.MagicMock(), # module
{}, # module
None, # routes
None, # message types
async_mock.MagicMock(versions="not-a-list"),
Expand Down