Skip to content
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

Merged
merged 4 commits into from
Feb 23, 2018

Conversation

waychal
Copy link
Contributor

@waychal waychal commented Feb 22, 2018

Issue #1110

Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments for the required (minor) changes, thanks a lot!

@@ -125,6 +125,48 @@ def get_plugin(category, name):

return plugin

def load_plugin_safe(base_class, plugins_module, plugin_type):
"""
It is a copy of load_plugin function to return closely related node class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not say it is a copy, I would say it is a 'wrapper' and mention that it does not raise exceptions

def load_plugin_safe(base_class, plugins_module, plugin_type):
"""
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this sentence "We are duplicating load_plugin function to not break its default behaviour." (as above, it's not a copy).

elif subNodeType == "work":
PluginClass = load_plugin(base_class, plugins_module, 'calculation.work.WorkCalculation')
else:
PluginClass = load_plugin(base_class, plugins_module, 'calculation.Calculation')
Copy link
Member

Choose a reason for hiding this comment

The 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).
Instead, put an else, and return Node with a warning as above:

aiidalogger.error("Unable to find plugin for type '{}' (node= {}), "
                                "will use base Node class".format(self.type, self.pk))
              PluginClass = Node

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).

@@ -162,7 +162,7 @@ def get_aiida_class(self):
"not valid: '{}'".format(self.pk, self.type))

try:
PluginClass = load_plugin(Node, 'aiida.orm', pluginclassname)
PluginClass = load_plugin_safe(Node, 'aiida.orm', pluginclassname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove it from the try/except, as the _safe version does not raise anymore

@waychal
Copy link
Contributor Author

waychal commented Feb 23, 2018

I have made the changes.

@@ -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):
Copy link
Member

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).

@waychal
Copy link
Contributor Author

waychal commented Feb 23, 2018

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants