Skip to content

Commit

Permalink
🐛 Fix registering and loading of modules
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Nov 12, 2024
1 parent 8e08ca1 commit 836f8d6
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions acapy_agent/core/plugin_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ async def register_admin_routes(self, app) -> None:
"Error loading admin routes from %s: %s", version_path, e
)
continue

if mod and hasattr(mod, "register"):
LOGGER.trace("Registering routes for: %s", plugin_name)
await mod.register(app)
else:
# Load plugin routes that aren't in a versioned package.
routes_path = f"{plugin_name}.routes"
Expand All @@ -354,9 +358,9 @@ async def register_admin_routes(self, app) -> None:
LOGGER.error("Error loading admin routes from %s: %s", routes_path, e)
continue

if mod and hasattr(mod, "register"):
LOGGER.trace("Registering routes for: %s", plugin_name)
await mod.register(app)
if mod and hasattr(mod, "register"):
LOGGER.trace("Registering routes for: %s", plugin_name)
await mod.register(app)

def register_protocol_events(self, context: InjectionContext) -> None:
"""Call route register_events methods on the current context."""
Expand All @@ -383,6 +387,10 @@ def register_protocol_events(self, context: InjectionContext) -> None:
except ModuleLoadError as e:
LOGGER.error("Error loading events from %s: %s", version_path, e)
continue

if mod and hasattr(mod, "register_events"):
LOGGER.trace("Registering events from: %s", version_path)
mod.register_events(event_bus)
else:
# Load plugin routes that aren't in a versioned package.
routes_path = f"{plugin_name}.routes"
Expand All @@ -393,9 +401,9 @@ def register_protocol_events(self, context: InjectionContext) -> None:
LOGGER.error("Error loading events from %s: %s", routes_path, e)
continue

if mod and hasattr(mod, "register_events"):
LOGGER.trace("Registering events from: %s", version_path)
mod.register_events(event_bus)
if mod and hasattr(mod, "register_events"):
LOGGER.trace("Registering events from: %s", version_path)
mod.register_events(event_bus)

def post_process_routes(self, app) -> None:
"""Call route binary file response OpenAPI fixups if applicable."""
Expand All @@ -417,6 +425,10 @@ def post_process_routes(self, app) -> None:
except ModuleLoadError as e:
LOGGER.error("Error loading routes from %s: %s", version_path, e)
continue

if mod and hasattr(mod, "post_process_routes"):
LOGGER.trace("Post-processing routes for %s", plugin_name)
mod.post_process_routes(app)
else:
# Set binary file responses for routes not in a versioned package.
routes_path = f"{plugin_name}.routes"
Expand All @@ -427,9 +439,9 @@ def post_process_routes(self, app) -> None:
LOGGER.error("Error loading routes from %s: %s", routes_path, e)
continue

if mod and hasattr(mod, "post_process_routes"):
LOGGER.trace("Post-processing routes for %s", plugin_name)
mod.post_process_routes(app)
if mod and hasattr(mod, "post_process_routes"):
LOGGER.trace("Post-processing routes for %s", plugin_name)
mod.post_process_routes(app)

def __repr__(self) -> str:
"""Return a string representation for this class."""
Expand Down

0 comments on commit 836f8d6

Please sign in to comment.