Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor metadata to be a property.
  • Loading branch information
kinyoklion committed Jun 23, 2025
commit 531bfd9715d66218fb75cb0cd202c019bb22563c
4 changes: 2 additions & 2 deletions ldclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ def __get_plugin_hooks(self, environment_metadata: EnvironmentMetadata) -> List[
try:
hooks.extend(plugin.get_hooks(environment_metadata))
except Exception as e:
log.error(f"Error getting hooks from plugin {plugin.get_metadata().name}: {e}")
log.error(f"Error getting hooks from plugin {plugin.metadata.name}: {e}")
return hooks

def __register_plugins(self, environment_metadata: EnvironmentMetadata):
for plugin in self._config.plugins:
try:
plugin.register(self, environment_metadata)
except Exception as e:
log.error(f"Error registering plugin {plugin.get_metadata().name}: {e}")
log.error(f"Error registering plugin {plugin.metadata.name}: {e}")

def _set_event_processor(self, config):
if config.offline or not config.send_events:
Expand Down
3 changes: 2 additions & 1 deletion ldclient/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ class Plugin:

__metaclass__ = ABCMeta

@property
@abstractmethod
def get_metadata(self) -> PluginMetadata:
def metadata(self) -> PluginMetadata:
"""
Get metadata about the plugin implementation.

Expand Down
3 changes: 2 additions & 1 deletion ldclient/testing/test_ldclient_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def __init__(self,
self.hooks_called = False
self.hooks_metadata = None

def get_metadata(self) -> PluginMetadata:
@property
def metadata(self) -> PluginMetadata:
return PluginMetadata(name=self._name)

def register(self, client: Any, metadata: EnvironmentMetadata) -> None:
Expand Down
7 changes: 4 additions & 3 deletions ldclient/testing/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def __init__(self, name: str = "Example Plugin"):
self._client = None
self._environment_metadata = None

def get_metadata(self) -> PluginMetadata:
@property
def metadata(self) -> PluginMetadata:
"""Get metadata about the plugin implementation."""
return PluginMetadata(name=self._name)

Expand All @@ -64,7 +65,7 @@ def register(self, client: Any, metadata: EnvironmentMetadata) -> None:
# Example: Log some information about the environment
print(f"Example Plugin registered with SDK {metadata.sdk.name} version {metadata.sdk.version}")
if metadata.application:
print(f"Application: {metadata.application.name} version {metadata.application.version}")
print(f"Application: {metadata.application.id} version {metadata.application.version}")

def get_hooks(self, metadata: EnvironmentMetadata) -> List[Hook]:
"""
Expand Down Expand Up @@ -107,7 +108,7 @@ def test_example_plugin(self):
plugin = ExamplePlugin("Test Example Plugin")

# Test metadata
metadata = plugin.get_metadata()
metadata = plugin.metadata
self.assertEqual(metadata.name, "Test Example Plugin")

# Test hooks
Expand Down