Skip to content

Commit 42744b6

Browse files
committed
add deprecation support to PluginDescription and Plugin classes
1 parent cdcc3f3 commit 42744b6

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

cmem_plugin_base/dataintegration/description.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class PluginDescription:
186186
:param parameters: Available plugin parameters
187187
:param icon: An optional custom plugin icon.
188188
:param actions: Custom plugin actions.
189+
:param deprecation: Optional deprecation message.
190+
If set, the plugin will be marked as deprecated in the UI.
189191
"""
190192

191193
def __init__( # noqa: PLR0913
@@ -199,6 +201,7 @@ def __init__( # noqa: PLR0913
199201
parameters: list[PluginParameter] | None = None,
200202
icon: Icon | None = None,
201203
actions: list[PluginAction] | None = None,
204+
deprecation: str | None = None,
202205
) -> None:
203206
# Set the type of the plugin. Same as the class name of the plugin
204207
# base class, e.g., 'WorkflowPlugin'.
@@ -238,6 +241,7 @@ def __init__( # noqa: PLR0913
238241
self.actions = []
239242
else:
240243
self.actions = actions
244+
self.deprecation = deprecation
241245
for action in self.actions:
242246
action.validate(plugin_class)
243247

@@ -321,6 +325,8 @@ class Plugin:
321325
:param parameters: Available plugin parameters.
322326
:param icon: Optional custom plugin icon.
323327
:param actions: Custom plugin actions
328+
:param deprecation: Optional deprecation message.
329+
If set, the plugin will be marked as deprecated in the UI.
324330
"""
325331

326332
plugins: ClassVar[list[PluginDescription]] = []
@@ -335,13 +341,15 @@ def __init__( # noqa: PLR0913
335341
parameters: list[PluginParameter] | None = None,
336342
icon: Icon | None = None,
337343
actions: list[PluginAction] | None = None,
344+
deprecation: str | None = None,
338345
):
339346
self.label = label
340347
self.description = description
341348
self.documentation = documentation
342349
self.plugin_id = plugin_id
343350
self.icon = icon
344351
self.actions = actions
352+
self.deprecation = deprecation
345353
if categories is None:
346354
self.categories = []
347355
else:
@@ -363,6 +371,7 @@ def __call__(self, func: type):
363371
parameters=self.retrieve_parameters(func),
364372
icon=self.icon,
365373
actions=self.actions,
374+
deprecation=self.deprecation,
366375
)
367376
Plugin.plugins.append(plugin_desc)
368377
return func

tests/test_description.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ def get_project(self, context: PluginContext) -> str:
115115
assert action1.execute(plugin_instance, TestPluginContext()) == "My Name"
116116
assert action2.execute(plugin_instance, TestPluginContext(project_id="movies")) == "movies"
117117

118+
def test__deprecation(self) -> None:
119+
"""Test plugin deprecation message."""
120+
Plugin.plugins = [] # Remove all previous plugins
121+
122+
@Plugin(label="My Plugin")
123+
class MyPlugin(TransformPlugin):
124+
"""Test transform plugin without deprecation message."""
125+
126+
def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
127+
return []
128+
129+
@Plugin(label="My Deprecated Plugin", deprecation="Use new plugin instead.")
130+
class MyDeprecatedPlugin(TransformPlugin):
131+
"""Test transform plugin with deprecation message."""
132+
133+
def transform(self, inputs: Sequence[Sequence[str]]) -> Sequence[str]:
134+
return []
135+
136+
plugin = Plugin.plugins[0]
137+
deprecated_plugin = Plugin.plugins[1]
138+
assert plugin.deprecation is None
139+
assert deprecated_plugin.deprecation == "Use new plugin instead."
140+
118141

119142
if __name__ == "__main__":
120143
unittest.main()

0 commit comments

Comments
 (0)