-
Notifications
You must be signed in to change notification settings - Fork 532
ENH: Add resolve/rebase BasePath
traits methods & tests
#2970
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
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.
My biggest concern is with monkey-patching traits. I think providing replacements in the nipype namespace is fine.
A couple potential corner cases for tests:
rebase_path_traits
:cwd
not a prefix ofvalue
resolve_path_traits
:value
already absolute
Codecov Report
@@ Coverage Diff @@
## master #2970 +/- ##
==========================================
- Coverage 67.61% 64.29% -3.32%
==========================================
Files 344 342 -2
Lines 43798 43822 +24
Branches 5471 5498 +27
==========================================
- Hits 29612 28174 -1438
- Misses 13475 14558 +1083
- Partials 711 1090 +379
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #2970 +/- ##
==========================================
- Coverage 67.12% 64.28% -2.85%
==========================================
Files 344 342 -2
Lines 43785 43776 -9
Branches 5469 5483 +14
==========================================
- Hits 29391 28140 -1251
- Misses 13648 14547 +899
- Partials 746 1089 +343
Continue to review full report at Codecov.
|
- [x] Removed traits.api patches - [x] Deduplicated code with a _recurse_on_path_traits proxy (nipy#2970 (comment)) - [x] Added the two proposed test cases - [x] Optimized loop (see nipy#2970 (comment))
Sorry for taking so long to get back to this one. I'm a little torn on the Does it not make more sense to have an accessor function that doesn't require either monkey-patching or replacing? This way we're not breaking downstream tools that define their own interface. If not, then I think monkey-patching the pre-existing traits will be necessary. |
Correct, the original Tuple and Either won't work.
I tried, but accessing traits without their prescribed methods has a huge boilerplate. I finally opted for this solution of least changes. We should consider streaming them up to traits - at least for the
That was my initial solution, but after reading your position about |
Well, with File and Directory, we're creating them and throwing them into that namespace, which feels strange. Especially because we haven't done it before, so everybody who has been using them has been importing them from nipype. While I would rather just create an accessor method to contain the boilerplate to one place, e.g.: def get_inner_traits(trait_type):
try:
return trait_type.inner_traits
except:
pass
# Tuple hack
# Either hack
# Other hacks? If that's out of the question, and we're producing traits that are otherwise identical to the ones we're replacing, I think monkey-patching is a cleaner solution than forcing all downstream projects to change their import targets. |
https://github.com/enthought/traits/blob/master/traits/trait_types.py#L1659 I don't see the difference with Either and Tuple.
I disagree - f1f4cf2 |
Huh. I didn't realize there already were So I don't know. It's annoying to push these changes downstream, but we haven't been monkey-patching |
I would bring monkeypatching back, it is very likely that people have their interfaces defined using |
That seems reasonable, but I feel like I want to get @satra's opinion on monkeypatching before I ask you to do anything big again... |
@oesteban and @effigies - the current change that we are making is to change the behavior of
all places where we use the functionality of the new this way we are not monkeypatching traits, and the introduced functionality is within the nipype context and people are not confused. |
The problem I see @satra is that people having interfaces not contributed to nipype are potentially using One thing you did not mention is what we do with the new Tuple/Either traits (so that they return their inner trait types). |
That said, I would not revert back all those |
|
cfdb14c
to
a1eae5a
Compare
- [x] Removed traits.api patches - [x] Deduplicated code with a _recurse_on_path_traits proxy (nipy#2970 (comment)) - [x] Added the two proposed test cases - [x] Optimized loop (see nipy#2970 (comment))
a1eae5a
to
b2adade
Compare
- [x] Removed traits.api patches - [x] Deduplicated code with a _recurse_on_path_traits proxy (nipy#2970 (comment)) - [x] Added the two proposed test cases - [x] Optimized loop (see nipy#2970 (comment))
@oesteban I think you rebased on an out-of-date master. |
b2adade
to
1a67e63
Compare
- [x] Removed traits.api patches - [x] Deduplicated code with a _recurse_on_path_traits proxy (nipy#2970 (comment)) - [x] Added the two proposed test cases - [x] Optimized loop (see nipy#2970 (comment))
Sorry, can you remove the commits with @josephmje? I don't think we want them and they add a |
1896f8b
to
e3a6fd3
Compare
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.
Assuming tests pass, this looks reasonable. One minor suggestion, and one quick question about the tests.
@@ -100,7 +100,7 @@ def convert_to_traits_type(dipy_type, is_file=False): | |||
elif "string" in dipy_type and not is_file: | |||
return traits.Str, is_mandatory |
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.
While we're switching from traits.File
:
return traits.Str, is_mandatory | |
return Str, is_mandatory |
This will need an import.
@skoudoro Could you verify that this is fine and that you didn't explicitly intend to use traits.Str
over nipype.interfaces.base.Str
for some reason?
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 just check it and everything is fine.
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.
@oesteban Did we not want to change this?
Three questions remain open (only 1 is relevant to this PR):
cc @satra |
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. 🤞 for the tests.
Two new methods ``resolve_path_traits`` and ``rebase_path_traits`` are being included. They take trait instances from a spec (selected via ``spec.trait('traitname')``, the value and a base path. These two functions will be usefull to progress towards nipy#2944.
Co-Authored-By: Chris Markiewicz <effigies@gmail.com>
Co-Authored-By: Chris Markiewicz <effigies@gmail.com>
- [x] Removed traits.api patches - [x] Deduplicated code with a _recurse_on_path_traits proxy (nipy#2970 (comment)) - [x] Added the two proposed test cases - [x] Optimized loop (see nipy#2970 (comment))
a1d6301
to
699b6cf
Compare
699b6cf
to
b0c80d7
Compare
Ready to go :) |
List of changes proposed in this PR (pull-request)
Two new methods
resolve_path_traits
andrebase_path_traits
are being included.They take trait instances from a spec (selected via
spec.trait('traitname')
), the value and a base path. Returns the modified value (if necessary).Summary
These two functions will be useful to progress towards #2944.
Acknowledgment