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
Introduce Client.register_plugin()
#8169
Introduce Client.register_plugin()
#8169
Conversation
Co-authored-by: crusaderky <crusaderky@gmail.com>
Co-authored-by: crusaderky <crusaderky@gmail.com>
Unit Test ResultsSee test report for an extended history of previous test failures. This is useful for diagnosing flaky tests. 21 files + 19 21 suites +19 10h 39m 18s ⏱️ + 10h 26m 24s For more details on these failures, see this check. Results for commit 696ab82. ± Comparison against base commit b5729b0. This pull request removes 4 and adds 1977 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
@@ -7483,17 +7491,24 @@ def stop_task_metadata(self, name: str | None = None) -> dict: | |||
self.remove_plugin(name=plugin.name) | |||
return {"metadata": plugin.metadata, "state": plugin.state} | |||
|
|||
async def register_worker_plugin(self, comm, plugin, name=None): |
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.
Can the comm
keyword be removed safely?
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.
no, it can't #8189
self._register_worker_plugin, plugin=plugin, name=name, nanny=nanny | ||
) | ||
method: Callable | ||
if isinstance(plugin, WorkerPlugin): |
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.
As opposed to #8150, this PR changes the precedence between the nanny keyword and typing.
UserWarning, | ||
stacklevel=2, | ||
) | ||
elif isinstance(plugin, SchedulerPlugin): # type: ignore[unreachable] |
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.
It also takes the decision to override registration in case a scheduler plugin is used.
""" | ||
Registers a lifecycle worker plugin for all current and future workers. | ||
|
||
.. deprecated:: 2023.9.2 |
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.
I'm assuming we do another release in September.
Note that this PR will likely fail if someone uses multiple inheritance, e.g. to subclass both |
pass | ||
|
||
n_existing_plugins = len(a.plugins) | ||
assert not hasattr(a, "foo") | ||
with pytest.warns(DeprecationWarning, match="duck-typed.*NannyPlugin"): |
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.
for the future, there is a specialized API in pytest for deprecated stuff, https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-deprecated-call
SchedulerUploadFile(filename, load=load), name=name | ||
), | ||
self.register_worker_plugin(UploadFile(filename, load=load), name=name), | ||
# FIXME: Make scheduler plugin responsible for (de)registering worker plugin |
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.
ticket would be nice
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.
changes look good. I could see use cases for multiple inheritance but what I can come up with is a "server plugin". Maybe thi is something to add later. |
Co-authored-by: Florian Jetter <fjetter@users.noreply.github.com>
+1 on a |
This PR introduces
Client.register_plugin()
as the new method to use for registering plugins. Following #8150, it does not allow duck-typed plugins but dispatches based on the inherited plugin class.It also deprecates
Client.register_scheduler_plugin()
andClient.register_worker_plugin()
in favor ofClient.register_plugin()
. WithinClient.register_worker_plugin()
, it also adjusts the dispatching logic. With this PR, typing takes precedence, which means that the plugin will get registered based on its inherited plugin class, regardless of thenanny
keyword and - most notably - if aSchedulerPlugin
is used, it will be registered as a scheduler plugin. This fixes the migration problem for #8142.pre-commit run --all-files