-
Notifications
You must be signed in to change notification settings - Fork 533
changes in Interfaces base (closes #2320) #2387
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
Changes from all commits
6d65cbb
955b3ad
40a0804
3549566
1794004
cc4c418
36ffda1
ab8ae1a
252a745
11212a4
c1ab001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -119,20 +119,6 @@ def _xor_warn(self, obj, name, old, new): | |||||
'which is already set') % (name, trait_name) | ||||||
raise IOError(msg) | ||||||
|
||||||
def _requires_warn(self, obj, name, old, new): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This used to be called from nipype/nipype/interfaces/base.py Lines 389 to 390 in 5495816
I was unable to quickly find the PR it was removed in, so it's hard to tell whether its removal was intentional or a mistake. As an unused private methods, I'm okay with getting rid of it, but @satra, if this should still be in |
||||||
"""Part of the xor behavior | ||||||
""" | ||||||
if isdefined(new): | ||||||
trait_spec = self.traits()[name] | ||||||
msg = None | ||||||
for trait_name in trait_spec.requires: | ||||||
if not isdefined(getattr(self, trait_name)): | ||||||
if not msg: | ||||||
msg = 'Input %s requires inputs: %s' \ | ||||||
% (name, ', '.join(trait_spec.requires)) | ||||||
if msg: # only one requires warning at a time. | ||||||
warn(msg) | ||||||
|
||||||
def _deprecated_warn(self, obj, name, old, new): | ||||||
"""Checks if a user assigns a value to a deprecated trait | ||||||
""" | ||||||
|
@@ -165,29 +151,6 @@ def _deprecated_warn(self, obj, name, old, new): | |||||
'%s' % trait_spec.new_name: new | ||||||
}) | ||||||
|
||||||
def _hash_infile(self, adict, key): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused private method. Good to remove, as far as I'm concerned. Again, @satra, feel free to override if this looks like a mistake. |
||||||
""" Inject file hashes into adict[key]""" | ||||||
stuff = adict[key] | ||||||
if not is_container(stuff): | ||||||
stuff = [stuff] | ||||||
file_list = [] | ||||||
for afile in stuff: | ||||||
if is_container(afile): | ||||||
hashlist = self._hash_infile({'infiles': afile}, 'infiles') | ||||||
hash = [val[1] for val in hashlist] | ||||||
else: | ||||||
if config.get('execution', | ||||||
'hash_method').lower() == 'timestamp': | ||||||
hash = hash_timestamp(afile) | ||||||
elif config.get('execution', | ||||||
'hash_method').lower() == 'content': | ||||||
hash = hash_infile(afile) | ||||||
else: | ||||||
raise Exception("Unknown hash method: %s" % config.get( | ||||||
'execution', 'hash_method')) | ||||||
file_list.append((afile, hash)) | ||||||
return file_list | ||||||
|
||||||
def get(self, **kwargs): | ||||||
""" Returns traited class as a dict | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,10 +168,8 @@ def _get_bunch_hash(self): | |
sorted_dict = to_str(sorted(dict_nofilename.items())) | ||
return dict_withhash, md5(sorted_dict.encode()).hexdigest() | ||
|
||
def __pretty__(self, p, cycle): | ||
"""Support for the pretty module | ||
|
||
pretty is included in ipython.externals for ipython > 0.10""" | ||
def _repr_pretty_(self, p, cycle): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with this, but we should verify that we can pretty print Bunches in IPython with this change. I don't know if the API changed beyond what method it looks for in your objects. if it doesn't work quickly, I'd say remove the function altogether and create an issue to fix and re-add, rather than waste time on this today. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just checked that Let me know if this was design to work with different library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like what it does is prevents an infinite loop during formating. Could you test with a bunch that contains itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, you're right, for a bunch that contains itself it makes a difference! But only with the new name |
||
"""Support for the pretty module from ipython.externals""" | ||
if cycle: | ||
p.text('Bunch(...)') | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ class Str(Unicode): | |
traits.DictStrStr = DictStrStr | ||
|
||
|
||
class BaseFile(BaseUnicode): | ||
class File(BaseUnicode): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unclear on the original justification for this separation, but dropping |
||
""" Defines a trait whose value must be the name of a file. | ||
""" | ||
|
||
|
@@ -96,14 +96,11 @@ def __init__(self, | |
if exists: | ||
self.info_text = 'an existing file name' | ||
|
||
super(BaseFile, self).__init__(value, **metadata) | ||
super(File, self).__init__(value, **metadata) | ||
|
||
def validate(self, object, name, value): | ||
""" Validates that a specified value is valid for this trait. | ||
|
||
Note: The 'fast validator' version performs this check in C. | ||
""" | ||
validated_value = super(BaseFile, self).validate(object, name, value) | ||
""" Validates that a specified value is valid for this trait.""" | ||
validated_value = super(File, self).validate(object, name, value) | ||
if not self.exists: | ||
return validated_value | ||
elif os.path.isfile(value): | ||
|
@@ -117,53 +114,12 @@ def validate(self, object, name, value): | |
self.error(object, name, value) | ||
|
||
|
||
class File(BaseFile): | ||
""" | ||
Defines a trait whose value must be the name of a file. | ||
Disables the default C-level fast validator. | ||
""" | ||
|
||
def __init__(self, | ||
value='', | ||
filter=None, | ||
auto_set=False, | ||
entries=0, | ||
exists=False, | ||
**metadata): | ||
""" Creates a File trait. | ||
|
||
Parameters | ||
---------- | ||
value : string | ||
The default value for the trait | ||
filter : string | ||
A wildcard string to filter filenames in the file dialog box used by | ||
the attribute trait editor. | ||
auto_set : boolean | ||
Indicates whether the file editor updates the trait value after | ||
every key stroke. | ||
exists : boolean | ||
Indicates whether the trait value must be an existing file or | ||
not. | ||
|
||
Default Value | ||
------------- | ||
*value* or '' | ||
""" | ||
# if not exists: | ||
# # Define the C-level fast validator to use: | ||
# fast_validate = (11, str) | ||
|
||
super(File, self).__init__(value, filter, auto_set, entries, exists, | ||
**metadata) | ||
|
||
|
||
# ------------------------------------------------------------------------------- | ||
# 'BaseDirectory' and 'Directory' traits: | ||
# 'Directory' trait | ||
# ------------------------------------------------------------------------------- | ||
|
||
|
||
class BaseDirectory(BaseUnicode): | ||
class Directory(BaseUnicode): | ||
""" | ||
Defines a trait whose value must be the name of a directory. | ||
""" | ||
|
@@ -177,7 +133,7 @@ def __init__(self, | |
entries=0, | ||
exists=False, | ||
**metadata): | ||
""" Creates a BaseDirectory trait. | ||
""" Creates a Directory trait. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -201,13 +157,10 @@ def __init__(self, | |
if exists: | ||
self.info_text = 'an existing directory name' | ||
|
||
super(BaseDirectory, self).__init__(value, **metadata) | ||
super(Directory, self).__init__(value, **metadata) | ||
|
||
def validate(self, object, name, value): | ||
""" Validates that a specified value is valid for this trait. | ||
|
||
Note: The 'fast validator' version performs this check in C. | ||
""" | ||
""" Validates that a specified value is valid for this trait.""" | ||
if isinstance(value, (str, bytes)): | ||
if not self.exists: | ||
return value | ||
|
@@ -222,44 +175,6 @@ def validate(self, object, name, value): | |
self.error(object, name, value) | ||
|
||
|
||
class Directory(BaseDirectory): | ||
""" | ||
Defines a trait whose value must be the name of a directory. | ||
Disables the default C-level fast validator. | ||
""" | ||
|
||
def __init__(self, | ||
value='', | ||
auto_set=False, | ||
entries=0, | ||
exists=False, | ||
**metadata): | ||
""" Creates a Directory trait. | ||
|
||
Parameters | ||
---------- | ||
value : string | ||
The default value for the trait | ||
auto_set : boolean | ||
Indicates whether the directory editor updates the trait value | ||
after every key stroke. | ||
exists : boolean | ||
Indicates whether the trait value must be an existing directory or | ||
not. | ||
|
||
Default Value | ||
------------- | ||
*value* or '' | ||
""" | ||
# Define the C-level fast validator to use if the directory existence | ||
# test is not required: | ||
# if not exists: | ||
# self.fast_validate = (11, str) | ||
|
||
super(Directory, self).__init__(value, auto_set, entries, exists, | ||
**metadata) | ||
|
||
|
||
# lists of tuples | ||
# each element consists of : | ||
# - uncompressed (tuple[0]) extension | ||
|
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 not sure I see a semantic difference in 955b3ad. I see:
Which becomes:
Am I missing something?
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.
answered lower in the discussion