Skip to content
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

[FIX] Compression in DataSinks #1095

Merged
merged 4 commits into from
May 2, 2018
Merged

Conversation

oesteban
Copy link
Member

@oesteban oesteban commented May 2, 2018

This PR tries to fix #1075 for good.

This PR tries to fix nipreps#1075 for good.
src_open = gzip.open if src_isgz else open
dst_open = gzip.open if dst_isgz else open
with src_open(src, 'rb') as f_in:
with dst_open(dst, 'wb') as f_out:
copyfileobj(f_in, f_out)
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's a use for True (and some case in which we might return False), I would just use return with no argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add one output for debugging: return False if no compress/uncompress was performed, True otherwise. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Maybe we should go ahead and add a unit test for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I recognize that I'm using "we" somewhat disingenuously. I can't stop.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it a real "we". @mgxd would you like to add that unit test?

(actually, we probably may want to see this interface in nipype proper, WDYT? cc/ @satra)

@effigies
Copy link
Member

effigies commented May 2, 2018

I think BIDSDataSink is probably going to want a refactor with some of the new pybids functionality before it gets upstreamed...

@@ -170,6 +170,9 @@ class DerivativesDataSinkInputSpec(BaseInterfaceInputSpec):

class DerivativesDataSinkOutputSpec(TraitedSpec):
out_file = OutputMultiPath(File(exists=True, desc='written file path'))
compression = traits.List(
traits.Bool, desc='whether ``in_file`` was compressed/uncompressed '
'or `it was copied directly.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use OutputMultiPath, here. There's no good reason to make it a list when out_file isn't.

@oesteban oesteban changed the title [FIX] Compression on DataSinks [FIX] Compression in DataSinks May 2, 2018
@@ -256,6 +256,9 @@ def _run_interface(self, runtime):
self._results['out_file'].append(out_file)
self._results['compression'].append(_copy_any(fname, out_file))

if len(self._results['compression']) == 1:
self._results['compression'] = self._results['compression'][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputMultiPath automatically does this.

@oesteban oesteban merged commit 710e37b into nipreps:master May 2, 2018
@oesteban oesteban deleted the fix/datasinks branch May 2, 2018 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[URGENT] Degenerate derivatives
2 participants