Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version check for entrypoint plugins with unequal project/package names #2594

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,9 @@ def get_version(self) -> Optional[str]:
):
try:
version = importlib.metadata.version(self.module.__package__)
except ValueError:
# package name is probably empty-string; just give up
except Exception:
# Just give up
# Can be caused by empty package name, mismatch between package/project names
pass

return version
Expand Down
18 changes: 18 additions & 0 deletions test/plugins/test_plugins_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,21 @@ def test_get_label_entrypoint(plugin_tmpfile):
assert meta['label'] == 'plugin label'
assert meta['type'] == handlers.EntryPointPlugin.PLUGIN_TYPE
assert meta['source'] == 'test_plugin = file_mod'


def test_entrypoint_plugin_get_version(plugin_tmpfile):
# See gh-2593, an entrypoint plugin whose project/package names are not
# equal raises an exception other than ValueError
distrib_dir = os.path.dirname(plugin_tmpfile.strpath)
sys.path.append(distrib_dir)

# load the entry point
try:
entry_point = importlib.metadata.EntryPoint(
'test_plugin', 'file_mod', 'sopel.plugins')
plugin = handlers.EntryPointPlugin(entry_point)
plugin.load()
plugin.module.__package__ = "FAKEFAKEFAKE"
plugin.get_version()
finally:
sys.path.remove(distrib_dir)
Loading