-
Notifications
You must be signed in to change notification settings - Fork 25
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
Allow plugins sharing the same name to be overwritten #158
Conversation
This allows someone to load the default plugins and overwrite those that they wish to by specifying an `overwrite=True` parameter to `reguster_plugin`.
The DatasetInfoPlugin plugin will end up with two different names when it is registered with its two "default" methods: by entrypoint and by creating a DatasetInfoPlugin() object with no arguments. Having these two fields equal helps downstream users who want to override the default plugins. Without this, the users will have to know what the entrypoint name is for discovered plugins so they can override the correct plugin. By standardizing on the name of the plugin, it can be inferred.
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.
That looks pretty good to me. There are a few documentation things, but I've spun those out into their own issues.
Let me know when you are happy with it and I'll land it.
'info = xpublish.plugins.included.dataset_info:DatasetInfoPlugin', | ||
'dataset_info = xpublish.plugins.included.dataset_info:DatasetInfoPlugin', |
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.
Thanks for catching and fixing that mismatch.
# Registering a duplicate plugin name will fail | ||
same_name = DatasetInfoPlugin(name='dataset_info', dataset_router_prefix='/newinfo') | ||
with pytest.raises(ValueError): | ||
rest.register_plugin(same_name) |
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.
Should we have a separate test to catch the error with the existing functionality?
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.
Up to you, I can break this test down into smaller tests if you would like!
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 think this works for now.
""" | ||
Register a plugin with the xpublish system | ||
|
||
Args: | ||
plugin (Plugin): Instantiated Plugin object | ||
plugin_name (str, optional): Plugin name | ||
overwrite (bool, optional): If a plugin of the same name exist, | ||
setting this to True will remove the existing plugin before | ||
registering the new plugin. Defaults to False. | ||
|
||
Raises: | ||
AttributeError: Plugin can not be registered | ||
ValueError: Plugin already registered, try setting overwrite to True | ||
""" | ||
plugin_name = plugin_name or plugin.name |
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.
Thanks Kyle! |
When configuring an
xpublish
server, I found it useful to be able to load the default entrypoint plugins and override a subset of them. For example, I didn't want thezarr
plugin in the root namespace, I'd like it at/zarr
. This allows plugins to be overwritten by name while still allowingxpublish
to do its thing and discover entrypoint plugins.While testing this I realized that
DatasetInfoPlugin.name = 'dataset_info'
but it was being added inentrypoints
with the nameinfo
. There is no problem with this, except when a user like me wants to override the settings of a plugin by name 😆 and depending on how it was loaded, the default name changes. I changed the entrypoint todataset_info
... not going to die on this hill but it would be nice if the entrypoint name and the default plugin name were equal!