-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
base: master
Are you sure you want to change the base?
Fix version check for entrypoint plugins with unequal project/package names #2594
Conversation
I dug into the original issue just a bit (literally, this time) and found that we probably could differentiate the This PR works as a quick fix for the exact issue you ran into, but I do think the real solution should be actually handling entry points correctly (i.e. not just as "spicy modules" like the current impl). For checking the version in particular, an |
Do not use bare `except`
Do not patch __package__ too early
Bonked on the underlying issue here with my newest plugin project, which bundles multiple related plugins into a single package as My patch below is not tested thoroughly, but if you want to come back to this branch it already has a test ready and you probably have Tox set up locally to run said test suite across all supported Python versions. 😸 GitHub still has that annoying limitation on how far away from the actual change you can start a line note, so unfortunately I can't make this into a one-click suggestion: # inside `EntryPointPlugin.get_version()`; you already know where,
# since this PR already touches the same area 😉
if (
version is None
and hasattr(self.entry_point, "dist")
and hasattr(self.entry_point.dist, "name")
):
try:
version = importlib.metadata.version(self.entry_point.dist.name)
except Exception:
# fine, just give up
pass |
I was looking for that solution, and yes, this is exactly the right solution here, as demonstrated by this snippet of code (running with Python 3.10):
Once you have an Alternatively, I don't mind if we separate the plugin version from the package version, i.e. allow a Plugin author to use |
I think the intent is already there in the code, by checking whether the version is |
After discussing on IRC, what's left here is for me to integrate @dgw's suggested tweak, and also to see about adding a logger instance here to strike a balance between more broadly catching exceptions and falling back on the |
sopel/plugins/handlers.py
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been talking about this one on IRC this evening, and I believe @SnoopJ and I have found a good middle ground:
If logging works here (we haven't tested how logging interacts with the CLI interfaces like sopel-plugins
), it would be good to catch ValueError
and PackageNotFoundError
which the importlib.metadata.version()
call might raise, and just give up. Maybe log a warning, but that's it. As a fallback, catch Exception
and log the full exception traceback for investigation. We'd like to know about other failure cases if they exist, but they shouldn't crash the CLI or the .version
command called from IRC.
I had a partial implementation of what's discussed in #2594 (comment) and committed it on top of this branch to clean out uncommitted changes in my Gitpod workspace (they are apparently discontinuing their turnkey cloud IDE product, which sucks). CI failures appear unrelated; the error is in
Must have been an update somewhere since the last type-checking cleanup in #2614. |
Description
Fixes #2593.
This changeset swallows all exceptions when trying to determine the version of an
EntryPointPlugin
, as there are more failure cases than what catchingValueError
specifically covers, and allowing those exceptions to propagate breaks plugin reloading.Checklist
make qa
(runsmake lint
andmake test
)1388 passed, 8 xfailed, 1 warning in 45.44s