-
Notifications
You must be signed in to change notification settings - Fork 189
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
Fix tcodexporter #761
Fix tcodexporter #761
Conversation
… plain functions (without store=True), therefore, they return a dict with results only.
aiida/utils/calculation.py
Outdated
@@ -39,3 +39,7 @@ def add_source_info(node, func): | |||
node._set_attr("source_file", source) | |||
except (IOError, OSError): | |||
pass | |||
try: | |||
node._set_attr("namespace", func.func_globals["__name__"]) | |||
except: |
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's not good to have a generic 'except' (this e.g. will catch also a CTRL+C...).
Do you know who might rise an exception? can func.func_globals do it?
In the "worst" case, at least do except Exception
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.
Actually, I don't know what exception might be risen here. The idea behind generic 'except' was a general fallback to silently skip setting this attribute should anything unexpected happen. I can replace it with except Exception
.
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.
See my comments
code_string = calc.get_attr('source_file').encode('utf-8') | ||
if calc.get_attr('namespace', '__main__').startswith('aiida.'): | ||
code_string = "from {} import {}".format(calc.get_attr('namespace', '__main__'), | ||
calc.get_attr('function_name','f')) | ||
return """#!/usr/bin/env runaiida |
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 means that in the general case it will write from __main__ import f
? Is this the expected behaviour?
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 should not: in general case the condition is False
("__main__".startswith('aiida.') == False
), therefore nothing is written. I added "__main__"
just to ignore missing namespace
attribute.
Many thanks! |
Minor fix for TcodExporter. Please note that I have introduced 'namespace' attribute for inlinecalculations, as I need to know whether the inline code is taken from AiiDA module (in that case I will not add the code of function to the generated inline script, as the code is already in AiiDA) or not.