Repository navigation
fix(plugins): instantiate entry-point toolkits and raise on a broken plugin - #121
Conversation
gopaljigaur
left a comment
There was a problem hiding this comment.
Loading, the errors and the docs work as described. I installed the WeatherToolkit and MathToolkit examples from both pages as real packages and ran their tools through MCPServer. The new tests use real entry points and all six fail on main. pytest (also run twice in reversed order), pre-commit, mypy and CI pass. Raising by default matches pluggy and Flask, and load_plugins=False with register() remains the way to skip a plugin.
One finding: a second distribution with the same entry point name silently replaces the first toolkit (inline on plugins.py).
94e615b to
e676308
Compare
gopaljigaur
left a comment
There was a problem hiding this comment.
The duplicate name check works, and the docs, tests and checks are fine apart from one gap. Two real .dist-info dirs that share an entry-point name now raise ValueError: Toolkit plugin name 'm' is used by d1, d2 before anything loads. The two new tests fail on the previous commit. On the tree merged with main: pytest, pre-commit and mypy pass, and CI is green.
One finding: the register docs do not mention the new ValueError (inline on docs/guide/plugins.md).
…plugin load_plugins registered the class an entry point names without calling it, so get_tools() failed on the unbound method and the warning-only handling dropped every tool. It now calls the loaded class or factory, checks the result is a Toolkit, and raises RuntimeError naming the entry point when loading fails, as pluggy and pytest do for broken plugins. register_tools no longer swallows get_tools() errors.
The example called _make_tools.__func__(None) on a function that takes no arguments and raised TypeError. Decorated functions in the class body are already Tool attributes, so the example now uses @tool directly. The notes now say load_plugins instantiates the class or factory and raises on a broken plugin.
The second toolkit replaced the first in plugins without a trace. load_plugins now raises ValueError naming both distributions before loading anything, and register raises on a name already in use, as pluggy does.
e676308 to
09a2481
Compare
What changed
PluginManager.load_pluginscalls what eachcyclops.toolkitsentry point names (aToolkitsubclass or a factory returning one) and registers the instance. Before, it registered the class itself,get_tools()failed on the unbound method, and the warning-only handling dropped every tool.RuntimeErrornaming the entry point ('weather' (pkg.plugin:WeatherToolkit)) with the original error as the cause. A result that is not aToolkitraisesTypeError. This follows pluggy and pytest, which raise on a broken plugin: a missing toolkit should not be silent. Stevedore'sinvoke_on_loadis the model for calling the loaded object, so classes and factories both work.ValueErrornaming both, before any plugin loads; before, the second silently replaced the first.registerraisesPlugin name already registeredon a name in use, as pluggy does.load_pluginsusesentry_points(group=...)directly and drops the outer catch-all.register_toolsno longer swallowsget_tools()errors; duplicate tool names are still skipped with a warning, as before.MathToolkitexample raisedTypeError(_make_tools.__func__(None)). It now uses@toolon functions in the class body, which are alreadyToolattributes. The guide, website page and API reference now describe whatload_pluginsdoes, so "instantiateWeatherToolkitautomatically" is true. The website page gains the same@toolsection.Tests
tests/test_plugins.pywrites a module and a.dist-infowithentry_points.txtinto a tmp dir onsys.path, so loading goes through realimportlib.metadataentry points: a class, a factory, tool execution, a plugin that fails to import, a factory returning a non-Toolkit, two plugins sharing a tool name, and two distributions sharing a plugin name. A further test covers a duplicate name passed toregister.The guide's and website's
WeatherToolkitandMathToolkitblocks were also run as installed entry-point plugins.uv run pytest(478 passed),uv run pre-commit run --all-filesanduv run mypy cyclopspass.Closes #116