-
Notifications
You must be signed in to change notification settings - Fork 533
FIX: Node __repr__ and detailed graph expansion #2669
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
Conversation
@oesteban - yesterday with @satra we were fixing the graph plotting, but Travis is failing for |
Codecov Report
@@ Coverage Diff @@
## master #2669 +/- ##
=========================================
- Coverage 67.62% 64.13% -3.5%
=========================================
Files 340 338 -2
Lines 43056 43026 -30
Branches 5329 5330 +1
=========================================
- Hits 29116 27593 -1523
- Misses 13238 14376 +1138
- Partials 702 1057 +355
Continue to review full report at Codecov.
|
I'm trying to write tests for dot files, so reading the |
I think the detailed graph has never made a distinction wrt simple_form that I've been aware of, so it seems fine to leave it as is unless it was supposed to. I don't have strong opinions about the graphs. |
Is this ready for review? |
yes |
@@ -36,11 +36,11 @@ def __init__(self, name=None, base_dir=None): | |||
|
|||
""" | |||
self._hierarchy = None | |||
self._name = None | |||
self.name = name |
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.
Doesn't this break the property definition below? (line 46)
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.
why? Before we had two lines: the first one self._name = None
and 3 lines later self.name = name
. I thought that one was left there forgotten.
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 change looks reasonable to me. There's no instance variable used by name.setter
that is set between lines 39 and 43, and nothing in these lines uses self._name
in any way, so it's hard to see where this would cause a problem.
I'm not sure what @oesteban means by "break[ing] the property definition". Perhaps you could clarify?
@@ -9,7 +9,7 @@ | |||
from builtins import open | |||
from copy import deepcopy | |||
from glob import glob | |||
import os | |||
import os, pdb |
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.
You don't seem to use pdb
.
nipype/pipeline/engine/utils.py
Outdated
@@ -507,7 +507,7 @@ def _write_detailed_dot(graph, dotfilename): | |||
# write nodes | |||
edges = [] | |||
for n in nx.topological_sort(graph): | |||
nodename = str(n) | |||
nodename = str(n.itername) |
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.
itername
is a str
, so this could just be nodename = n.itername
.
@@ -36,11 +36,11 @@ def __init__(self, name=None, base_dir=None): | |||
|
|||
""" | |||
self._hierarchy = None | |||
self._name = None | |||
self.name = name |
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 change looks reasonable to me. There's no instance variable used by name.setter
that is set between lines 39 and 43, and nothing in these lines uses self._name
in any way, so it's hard to see where this would cause a problem.
I'm not sure what @oesteban means by "break[ing] the property definition". Perhaps you could clarify?
graph_str = f.read() | ||
|
||
if simple: | ||
for str in eval("dotfile_{}".format(graph_type)): |
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.
Could we avoid eval
s unless absolutely necessary? We could do this with a dict
:
dotfiles = {
'hierarchical': dotfile_hierarchical,
...
}
...
for contents in dotfiles[graph_type]:
...
Also, please do not use str
as a variable name, as it is a built-in class. (I know we don't follow this rule in the entire code base, but I'd rather not introduce more cases of this.)
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.
sure, will remove str
. Can you comment why you think I should not use eval
here? Or in general you're against of using eval
anywhere?
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'm against the use of eval
at all, unless there is no other way to do what needs doing (and there is almost always another way).
eval
makes it more difficult to reason about programs, including static analysis like flake8
or pylint
, because the code to be executed cannot in principle be known prior to execution. By design, it is a function that permits arbitrary code execution via string manipulation, which is also a security risk, even if it is not clear at the time how it could be exploited.
A decent StackOverflow thread: Why is using 'eval' a bad practice?
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.
ok, will change
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.
thanks for comments
@oesteban Any remaining concerns? Was your earlier concern addressed? |
Summary
fixing the detailed graph and printing
workflow.run().nodes()
for workflows with iterables, the issue was due to the changes in the node__str__
/__repr__
Fixes #2668
Acknowledgment