-
Notifications
You must be signed in to change notification settings - Fork 153
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
Adds custom list of plugins to be passed on load #2481
Conversation
71dbd09
to
b34978e
Compare
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.
This is looking good so far, but think we need to tweak the logic related to requiring plugins - see below. API-wise I think the keyword argument to load_plugins
should probably just be called names
so that it would look like:
load_plugins(names=['glue.core.something'])
rather than
load_plugins(plugins_to_load=['glue.core.something'])
which is a bit repetitive. Internally we could still use plugins_to_load
though.
glue/main.py
Outdated
@@ -45,17 +49,26 @@ def load_plugins(splash=None, require_qt_plugins=False): | |||
config = PluginConfig.load() | |||
|
|||
n_plugins = len(list(iter_plugin_entry_points())) |
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 it might be best to actually define n_plugins
as len(plugins_to_use)
once plugins_to_use
has been defined.
glue/main.py
Outdated
if require_qt_plugins: | ||
plugins_to_use = [*REQUIRED_PLUGINS, *REQUIRED_PLUGINS_QT] | ||
else: | ||
plugins_to_use = REQUIRED_PLUGINS |
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 don't think plugins_to_use
should be based on the REQUIRED_*
variables - these are just used to raise exceptions below if they are not present. I think we actually need two different variables inside this function - plugins_to_load
(perhaps a better name than plugins_to_use
) and plugins_to_require
. I think the logic should be:
- If
plugins_to_load
is not defined by the user, thenplugins_to_load
defaults to all entry points (iter_plugin_entry_points
) andplugins_to_require
defaults to eitherREQUIRED_PLUGINS
or the combination ofREQUIRED_PLUGINS
andREQUIRED_PLUGINS_QT
- If
plugins_to_load
is defined by the user, thenplugins_to_require
should just be set toplugins_to_load
because if the user is explicitly asking for them we should error if they can't be loaded
@@ -90,7 +103,7 @@ def load_plugins(splash=None, require_qt_plugins=False): | |||
_loaded_plugins.add(item.module) |
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 can't easily comment on lines above but based on my previous comment,
if item.module in REQUIRED_PLUGINS:
raise
elif item.module in REQUIRED_PLUGINS_QT and require_qt_plugins:
raise
should then become:
if item.module in plugins_to_require:
raise
fae7760
to
0a975cf
Compare
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.
Looks good, thanks! In a follow-up PR, could you tweak the API of load_plugins
so that the kwarg is called names
instead of plugins_to_load
? (see above comment about this).
Adds customisable list of plugins on load
Adds an argument to load_plugins in main that allows a custom list to be passed.
On empty, defaults to required plugins which have been added to
_plugin_helpers