-
Notifications
You must be signed in to change notification settings - Fork 536
ENH: Allow chained name_source #938
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7f9186
[engine] Allow chained name_source
oesteban 2b1d259
revert outdated changes to master
oesteban 06c2298
use six.string_types
oesteban 18973cd
Merge branch 'master' into enh/ChainedNameSource
oesteban 5b6066c
add regression test for chained namesource
oesteban ebb46cd
update CHANGES
oesteban c9e7b09
added new tests, updated documentation
oesteban 5f991fb
fixed regression tests
oesteban b43941c
Merge branch 'master' into enh/ChainedNameSource
oesteban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1469,6 +1469,7 @@ def _format_arg(self, name, trait_spec, value): | |
def _filename_from_source(self, name): | ||
trait_spec = self.inputs.trait(name) | ||
retval = getattr(self.inputs, name) | ||
|
||
if not isdefined(retval) or "%s" in retval: | ||
if not trait_spec.name_source: | ||
return retval | ||
|
@@ -1478,26 +1479,37 @@ def _filename_from_source(self, name): | |
name_template = trait_spec.name_template | ||
if not name_template: | ||
name_template = "%s_generated" | ||
if isinstance(trait_spec.name_source, list): | ||
for ns in trait_spec.name_source: | ||
if isdefined(getattr(self.inputs, ns)): | ||
name_source = ns | ||
break | ||
|
||
ns = trait_spec.name_source | ||
while isinstance(ns, list): | ||
if len(ns) > 1: | ||
iflogger.warn('Only one name_source per trait is allowed') | ||
ns = ns[0] | ||
|
||
if not isinstance(ns, basestring): | ||
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. replace with six.string_types |
||
raise ValueError(('name_source of \'%s\' trait sould be an ' | ||
'input trait name') % name) | ||
|
||
if isdefined(getattr(self.inputs, ns)): | ||
name_source = ns | ||
source = getattr(self.inputs, name_source) | ||
while isinstance(source, list): | ||
source = source[0] | ||
|
||
# special treatment for files | ||
try: | ||
_, base, _ = split_filename(source) | ||
except AttributeError: | ||
base = source | ||
else: | ||
name_source = trait_spec.name_source | ||
source = getattr(self.inputs, name_source) | ||
while isinstance(source, list): | ||
source = source[0] | ||
#special treatment for files | ||
try: | ||
_, base, _ = split_filename(source) | ||
except AttributeError: | ||
base = source | ||
base = self._filename_from_source(ns) | ||
|
||
retval = name_template % base | ||
_, _, ext = split_filename(retval) | ||
if trait_spec.keep_extension and ext: | ||
return retval | ||
return self._overload_extension(retval, name) | ||
|
||
return retval | ||
|
||
def _gen_filename(self, name): | ||
|
@@ -1513,7 +1525,7 @@ def _list_outputs(self): | |
outputs = self.output_spec().get() | ||
for name, trait_spec in traits.iteritems(): | ||
out_name = name | ||
if trait_spec.output_name != None: | ||
if trait_spec.output_name is not None: | ||
out_name = trait_spec.output_name | ||
outputs[out_name] = \ | ||
os.path.abspath(self._filename_from_source(name)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is only one allowed?
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.
well, we have a somewhat difficult decision here.
Former implementation iterated the name_source list until it found the first defined name_source.
Current implementation may accept undefined name_sources, but they must have a name_source as well.
In both implementations only one name_source is actually used, right?.