|
49 | 49 | import inspect |
50 | 50 | import itertools |
51 | 51 | import os |
| 52 | +from typing import Optional |
52 | 53 |
|
53 | | -from sopel import loader |
| 54 | +from sopel import __version__ as release, loader |
54 | 55 | from . import exceptions |
55 | 56 |
|
56 | 57 | try: |
@@ -121,6 +122,15 @@ def get_meta_description(self) -> dict: |
121 | 122 | """ |
122 | 123 | # TODO: change return type to a TypedDict when dropping py3.7 |
123 | 124 |
|
| 125 | + @abc.abstractmethod |
| 126 | + def get_version(self): |
| 127 | + """Retrieve the plugin's version. |
| 128 | +
|
| 129 | + :return: the plugin's version string |
| 130 | + :rtype: str |
| 131 | + """ |
| 132 | + raise NotImplementedError |
| 133 | + |
124 | 134 | @abc.abstractmethod |
125 | 135 | def is_loaded(self) -> bool: |
126 | 136 | """Tell if the plugin is loaded or not. |
@@ -292,9 +302,20 @@ def get_meta_description(self): |
292 | 302 | 'type': self.PLUGIN_TYPE, |
293 | 303 | 'name': self.name, |
294 | 304 | 'source': self.module_name, |
295 | | - 'version': getattr(self._module, "__version__", None), |
| 305 | + 'version': self.get_version(), |
296 | 306 | } |
297 | 307 |
|
| 308 | + def get_version(self) -> Optional[str]: |
| 309 | + """Retrieve the plugin's version. |
| 310 | +
|
| 311 | + :return: the plugin's version string |
| 312 | + :rtype: Optional[str] |
| 313 | + """ |
| 314 | + if hasattr(self._module, "__version__"): |
| 315 | + return str(self._module.__version__) |
| 316 | + if self.module_name.startswith("sopel."): |
| 317 | + return release |
| 318 | + |
298 | 319 | def load(self): |
299 | 320 | """Load the plugin's module using :func:`importlib.import_module`. |
300 | 321 |
|
|
0 commit comments