Skip to content

Commit c61b680

Browse files
authored
chore: Add back argument "name" to BasePlugin for compatibility (#2814)
1 parent 14c867c commit c61b680

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

samtranslator/plugins/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from abc import ABC
33

44
from enum import Enum
5+
from typing import Optional
56

67
LOG = logging.getLogger(__name__)
78

@@ -21,13 +22,27 @@ class BasePlugin(ABC):
2122
Base class for a NoOp plugin that implements all available hooks
2223
"""
2324

25+
_custom_name: Optional[str]
26+
27+
def __init__(self, name: Optional[str] = None) -> None:
28+
"""
29+
Initialize the plugin with optional given name.
30+
31+
The optional name argument is for compatibility purpose.
32+
In SAM-T codebase all plugins use the default name (class name).
33+
:param name: Custom name of this plugin.
34+
"""
35+
self._custom_name = name
36+
2437
@classmethod
25-
def _name(cls) -> str:
38+
def _class_name(cls) -> str:
2639
return cls.__name__
2740

2841
@property
2942
def name(self) -> str:
30-
return self._name()
43+
if self._custom_name:
44+
return self._custom_name
45+
return self._class_name()
3146

3247
def on_before_transform_resource(self, logical_id, resource_type, resource_properties): # type: ignore[no-untyped-def]
3348
"""

tests/test_plugins.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ def test_initialization_should_set_name(self):
296296
plugin = Yoyoyo()
297297
self.assertEqual("Yoyoyo", plugin.name)
298298

299+
def test_initialization_should_set_custom_name(self):
300+
301+
plugin = Yoyoyo("custom-name")
302+
self.assertEqual("custom-name", plugin.name)
303+
299304
def test_on_methods_must_not_do_anything(self):
300305
data_mock = Mock()
301306

0 commit comments

Comments
 (0)