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

Fix tcodexporter #761

Merged
merged 6 commits into from
Oct 13, 2017
Merged

Conversation

merkys
Copy link
Member

@merkys merkys commented Oct 13, 2017

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.

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

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

Copy link
Member Author

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.

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 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
Copy link
Member

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?

Copy link
Member Author

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.

@giovannipizzi giovannipizzi self-assigned this Oct 13, 2017
@giovannipizzi giovannipizzi merged commit b5ae353 into aiidateam:release_v0.9.2 Oct 13, 2017
@merkys merkys deleted the fix_tcodexporter branch October 13, 2017 09:06
@merkys
Copy link
Member Author

merkys commented Oct 13, 2017

Many thanks!

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.

2 participants