-
Notifications
You must be signed in to change notification settings - Fork 532
ENH: Add tab completion for node and interface inputs properties #2735
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
Could you add a test for I'm guessing the reason for including this in But if the test passes for both static and dynamic specs, I'm okay with this, as it's pretty simple. |
Also, is this targeting 1.x or 2.0? |
work still needed for dynamic traits
Codecov Report
@@ Coverage Diff @@
## master #2735 +/- ##
==========================================
- Coverage 67.44% 63.99% -3.46%
==========================================
Files 340 338 -2
Lines 43170 43121 -49
Branches 5353 5350 -3
==========================================
- Hits 29117 27596 -1521
- Misses 13355 14454 +1099
- Partials 698 1071 +373
Continue to review full report at Codecov.
|
Thanks. Your pointers helped me a lot. It does indeed work better by modifying BaseTraitedSpec. I've added tests for my desired behavior. I'm still struggling to implement the functionality for DynamicTraitedSpec. I'm not sure where to modify it. Do you have any thoughts? |
Perhaps override |
This is almost working. I would expect the following test to pass but the second assert doesn't:
This doesn't pass on the commits prior to mine though. |
1.x. 2.0 will have to incorporate it following a pending pyhydra refactor. |
I think the problem may be that |
good. to know. i'll change that. It doesn't fix this problem though |
assert(sorted(list_extract.outputs.__all__) == expected_output) | ||
|
||
# Add trait and retest | ||
list_extract.outputs.add_trait("added_out_trait","val") |
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.
The problem is that the output spec is actually instantiated in IOBase._outputs()
, which calls Function._add_output_traits
, which only will add things in self._output_names
. So to do what you want here, you would need to do:
list_extract._interface._output_names.append('added_out_trait')
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.
indeed. Thank you. I don't think I would have got that.
due to an error in understanding of dynamic trait instantiation: output spec is actually instantiated in IOBase._outputs(), which calls Function._add_output_traits, which only will add things in self._output_names
nipype/interfaces/base/specs.py
Outdated
@@ -83,9 +83,11 @@ def __repr__(self): | |||
""" Return a well-formatted representation of the traits """ | |||
outstr = [] | |||
for name, value in sorted(self.trait_get().items()): | |||
outstr.append('%s = %s' % (name, value)) | |||
if not name == '__all__': | |||
outstr.append('%s = %s' % (name, value)) |
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.
Is this still necessary, with __all__
becoming a property?
nipype/interfaces/base/specs.py
Outdated
return '\n{}\n'.format('\n'.join(outstr)) | ||
|
||
|
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.
We should remove this line.
def __all__(self): | ||
return [k for k,v in self.items() if not k == "__all__"] | ||
|
||
|
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.
Too many blank lines.
nipype/interfaces/base/specs.py
Outdated
@@ -309,6 +311,11 @@ def _get_sorteddict(self, | |||
out = objekt | |||
return out | |||
|
|||
@property | |||
def __all__(self): | |||
return [k for k,v in self.items() if not k == "__all__"] |
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.
Given that items()
provides a dict keyed by self.copyable_trait_names()
, and you only need keys, I think you can just make this:
@property
def __all__(self):
return self.copyable_trait_names()
You'll need to change the BET tests to either sort or check set equality, but this should work.
Thanks. I made all those changes |
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.
LGTM, thanks.
|
||
# Add trait and retest | ||
list_extract._interface._output_names.append('added_out_trait') | ||
expected_output = sorted(['added_out_trait',*expected_output]) |
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.
Python 2.7, 3.4 don't like the [*x]
syntax. How about making expected_output
a set above, moving to set comparisons, and changing this to:
expected_output.add('added_out_trait')
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.
nice. Thanks for the tip. done
Summary
Improves ease of use by giving more convenient tab completion for constructing graphs.
Fixes # .
List of changes proposed in this PR (pull-request)
Acknowledgment