Skip to content

Commit 6007ec2

Browse files
committed
idk
1 parent bb27bed commit 6007ec2

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

sopel/modules/version.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ def version(bot, trigger):
4949
return
5050

5151
meta = bot.get_plugin_meta(plugin)
52-
if meta["source"].startswith("sopel."):
53-
version = "v" + release + " (built in)"
54-
elif meta["version"] is None:
55-
version = "(version unknown)"
52+
if meta["version"] is None:
53+
version = "(unknown)"
5654
else:
57-
version = "v" + meta["version"]
55+
version = "v" + str(meta["version"])
56+
57+
if meta["source"].startswith("sopel."):
58+
version += " (built in)"
5859

59-
bot.say(plugin + " " + version)
60+
bot.say(plugin + " " + str(version))
6061
return
6162

6263
# Sopel version

sopel/plugins/handlers.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@
4949
import inspect
5050
import itertools
5151
import os
52+
from typing import Optional
5253

53-
from sopel import loader
54+
from sopel import __version__ as release, loader
5455
from . import exceptions
5556

5657
try:
@@ -121,6 +122,15 @@ def get_meta_description(self) -> dict:
121122
"""
122123
# TODO: change return type to a TypedDict when dropping py3.7
123124

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+
124134
@abc.abstractmethod
125135
def is_loaded(self) -> bool:
126136
"""Tell if the plugin is loaded or not.
@@ -292,9 +302,20 @@ def get_meta_description(self):
292302
'type': self.PLUGIN_TYPE,
293303
'name': self.name,
294304
'source': self.module_name,
295-
'version': getattr(self._module, "__version__", None),
305+
'version': self.get_version(),
296306
}
297307

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+
298319
def load(self):
299320
"""Load the plugin's module using :func:`importlib.import_module`.
300321

0 commit comments

Comments
 (0)