-
Notifications
You must be signed in to change notification settings - Fork 214
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
Added load_plugin_safe method to return calc node if plugin is not available #1185
Changes from 2 commits
382efda
09cf0ff
3d9fb35
2d096b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,15 +125,19 @@ def get_plugin(category, name): | |
|
||
return plugin | ||
|
||
def load_plugin_safe(base_class, plugins_module, plugin_type): | ||
def load_plugin_safe(base_class, plugins_module, plugin_type, nodeType, nodePk): | ||
""" | ||
It is a copy of load_plugin function to return closely related node class | ||
if plugin is not available. We are duplicating load_plugin function to not break | ||
its default behaviour. | ||
It is a wrapper of load_plugin function to return closely related node class | ||
if plugin is not available. By default it returns base Node class and does not | ||
raise exception. | ||
|
||
params: Look at the docstring of aiida.common.old_pluginloader.load_plugin for more Info + | ||
:param: nodeType: type of the node | ||
:param nodePk: node pk | ||
|
||
params: Look at the docstring of aiida.common.old_pluginloader.load_plugin for more Info | ||
:return: The plugin class | ||
""" | ||
from aiida.common import aiidalogger | ||
|
||
try: | ||
PluginClass = load_plugin(base_class, plugins_module, plugin_type) | ||
|
@@ -165,6 +169,16 @@ def load_plugin_safe(base_class, plugins_module, plugin_type): | |
else: | ||
PluginClass = load_plugin(base_class, plugins_module, 'calculation.Calculation') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing else (for baseNodeType). If there is a node of a different baseNodeType, this will crash as PluginClass is not defined. This e.g. will happen for Node (that starts with node.Node. I think).
Maybe add also the case where the baseNodeType is 'node' so you don't get a warning in that case. Can you add a test for Node as well (just to see that it returns Node and does not crash). |
||
|
||
## for base node | ||
elif baseNodeType == "node": | ||
PluginClass = base_class | ||
|
||
## default case | ||
else: | ||
aiidalogger.error("Unable to find plugin for type '{}' (node= {}), " | ||
"will use base Node class".format(nodeType, nodePk)) | ||
PluginClass = base_class | ||
|
||
return PluginClass | ||
|
||
|
||
|
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.
all good, but I just realised that you should use names_with_underscores for variables instead of camelCase, or we risk that people get confused when specifying the variable names of a function (the same inside the functions).