Skip to content

Commit

Permalink
plugins.handlers: use stdlib for EntryPointPlugin.get_version()
Browse files Browse the repository at this point in the history
`importlib.metadata` officially starts existing in Python 3.8, and we
are removing support for Python 3.7 before Sopel 8's stable release.
That means we can use the stdlib approach here to get the version string
for an entry-point plugin, and drop another `import importlib_metadata`.

I can't wait for Python 3.9's EOL... We can remove `importlib_metadata`
completely then.
  • Loading branch information
dgw committed Aug 3, 2023
1 parent 3269e95 commit b2ea7ae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
import sys
from typing import Optional, TYPE_CHECKING, TypedDict

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

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

Expand Down Expand Up @@ -614,9 +611,13 @@ def get_version(self) -> Optional[str]:
"""
version: Optional[str] = super().get_version()

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

0 comments on commit b2ea7ae

Please sign in to comment.