Skip to content

Commit 9f8e976

Browse files
author
Cariad Eccleston
authored
Log plugin version (#7)
1 parent 7ad15fd commit 9f8e976

8 files changed

Lines changed: 44 additions & 15 deletions

File tree

wev/mock_plugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime, timedelta
22
from logging import Logger
3-
from typing import List, Optional, Tuple
3+
from typing import Any, Dict, List, Optional, Tuple
44

55
from wev.sdk import PluginBase, Resolution, ResolutionSupport
66
from wev.sdk.exceptions import CannotResolveError
@@ -21,7 +21,7 @@ class MockPlugin(PluginBase):
2121

2222
def __init__(
2323
self,
24-
values: dict,
24+
values: Dict[Any, Any],
2525
raises_cannot_resolve_error: Optional[bool] = False,
2626
return_value: Optional[Tuple[str, ...]] = None,
2727
return_expires_at: Optional[bool] = False,
@@ -43,3 +43,7 @@ def resolve(self, support: ResolutionSupport) -> Resolution:
4343
value=self.return_value,
4444
expires_at=self.return_expires_at,
4545
)
46+
47+
@property
48+
def version(self) -> str:
49+
return "1.2.3"

wev/plugins.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def get_plugin(config: PluginConfiguration) -> PluginBase:
2525
if len(plugins) > 1:
2626
raise MultiplePluginsError(plugin_id=config.id, count=len(plugins))
2727

28-
get_logger().debug("Instantiating plugin with: %s", config)
28+
logger = get_logger()
2929

30-
return cast(PluginBase, plugins[0].load().Plugin(config))
30+
logger.debug("Instantiating plugin with: %s", config)
31+
plugin = cast(PluginBase, plugins[0].load().Plugin(config))
32+
33+
logger.debug("Instantiated plugin: %s", plugin)
34+
return plugin

wev/sdk/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class MissingConfigurationError(Exception):
1414
scenarios.
1515
"""
1616

17-
def __init__(self, config: dict, key: str, explanation: Optional[str] = None):
18-
message = f"The {key} key is required in {config}"
17+
def __init__(self, key: str, explanation: Optional[str] = None):
18+
message = f"The {key} key is required in this plugin's configuration"
1919
message = f"{message}: {explanation}" if explanation else f"{message}."
2020
super().__init__(message)
2121

wev/sdk/plugin_base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from abc import ABC, abstractmethod
22
from logging import Logger
3-
from typing import List
3+
from typing import Any, Dict, List
44

55
from wev.sdk import Resolution, ResolutionSupport
66

77

8-
class PluginBase(ABC, dict):
8+
class PluginBase(ABC, Dict[Any, Any]):
9+
def __str__(self) -> str:
10+
return f"version {self.version}"
11+
912
@abstractmethod
1013
def explain(self, logger: Logger) -> List[str]:
1114
"""
@@ -23,3 +26,9 @@ def resolve(self, support: ResolutionSupport) -> Resolution:
2326
Resolves the environment variable.
2427
"""
2528
pass
29+
30+
@property
31+
@abstractmethod
32+
def version(self) -> str:
33+
""" Gets the plugin's version. """
34+
pass

wev/sdk/test_exceptions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
"ex, expect",
88
[
99
(
10-
MissingConfigurationError(config={"fooo": "bar"}, key="foo"),
11-
"The foo key is required in {'fooo': 'bar'}.",
10+
MissingConfigurationError(key="foo"),
11+
"The foo key is required in this plugin's configuration.",
1212
),
1313
(
1414
MissingConfigurationError(
15-
config={"fooo": "bar"},
1615
key="foo",
1716
explanation="bar",
1817
),
19-
"The foo key is required in {'fooo': 'bar'}: bar",
18+
"The foo key is required in this plugin's configuration: bar",
2019
),
2120
],
2221
)

wev/test_plugins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
def test_get_plugin() -> None:
10-
assert get_plugin(PluginConfiguration({"id": "wev-echo"}))
10+
plugin = get_plugin(PluginConfiguration({"id": "wev-echo"}))
11+
assert plugin.version == "1.0.0"
1112

1213

1314
def test_get_plugin__no_match() -> None:

wev/wev_echo/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def value(self) -> str:
4747
return str(self["value"])
4848
except KeyError as ex:
4949
raise MissingConfigurationError(
50-
config=self,
5150
explanation="This is the value that will be echoed.",
5251
key=str(ex),
5352
)
53+
54+
@property
55+
def version(self) -> str:
56+
""" Gets the plugin's version. """
57+
return "1.0.0"

wev/wev_echo/test_plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def test_resolve__missing_config(resolution_support: ResolutionSupport) -> None:
2222
with raises(MissingConfigurationError) as ex:
2323
Plugin({"foo": "bar"}).resolve(support=resolution_support)
2424
assert str(ex.value) == (
25-
"The 'value' key is required in {'foo': 'bar'}: "
25+
"The 'value' key is required in this plugin's configuration: "
2626
"This is the value that will be echoed."
2727
)
28+
29+
30+
def test_version() -> None:
31+
assert Plugin({}).version == "1.0.0"
32+
33+
34+
def test_str() -> None:
35+
assert str(Plugin({})) == "version 1.0.0"

0 commit comments

Comments
 (0)