Skip to content

Commit

Permalink
Merge pull request #2313 from sopel-irc/entrypoint-plugin-versions
Browse files Browse the repository at this point in the history
plugins.handlers: override get_version() for EntryPointPlugin
  • Loading branch information
dgw authored Jul 18, 2022
2 parents 55c78a4 + 89f4aea commit 68f12cc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
import os
from typing import Optional

# TODO: refactor along with usage in sopel.__init__ in py3.8+ world
import importlib_metadata

from sopel import __version__ as release, loader
from . import exceptions

Expand Down Expand Up @@ -582,6 +585,23 @@ def __init__(self, entry_point):
def load(self):
self._module = self.entry_point.load()

def get_version(self) -> Optional[str]:
"""Retrieve the plugin's version.
:return: the plugin's version string
:rtype: Optional[str]
"""
version: Optional[str] = super().get_version()

if version is None and hasattr(self._module, "__package__"):
try:
version = importlib_metadata.version(self._module.__package__)
except ValueError:
# package name is probably empty-string; just give up
pass

return version

def get_meta_description(self):
"""Retrieve a meta description for the plugin.
Expand Down

0 comments on commit 68f12cc

Please sign in to comment.