Skip to content

Commit cba09b2

Browse files
committed
Apply @effigies suggestions
1 parent abe83dd commit cba09b2

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

nipype/interfaces/io.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
from .. import config, logging
3434
from ..utils.filemanip import (
3535
copyfile, simplify_list, ensure_list,
36-
get_related_files)
36+
get_related_files, split_filename)
3737
from ..utils.misc import human_order_sorted, str2bool
3838
from .base import (
3939
TraitedSpec, traits, Str, File, Directory, BaseInterface, InputMultiPath,
4040
isdefined, OutputMultiPath, DynamicTraitedSpec, Undefined, BaseInterfaceInputSpec,
41-
LibraryBaseInterface)
41+
LibraryBaseInterface, SimpleInterface)
4242

4343
iflogger = logging.getLogger('nipype.interface')
4444

@@ -2869,28 +2869,26 @@ def _add_output_traits(self, base):
28692869
class ExportFileInputSpec(BaseInterfaceInputSpec):
28702870
in_file = File(exists=True, mandatory=True, desc='Input file name')
28712871
out_file = File(mandatory=True, desc='Output file name')
2872-
check_extension = traits.Bool(False, desc='Ensure that the input and output file extensions match')
2872+
check_extension = traits.Bool(True, desc='Ensure that the input and output file extensions match')
28732873
clobber = traits.Bool(desc='Permit overwriting existing files')
28742874

28752875

28762876
class ExportFileOutputSpec(TraitedSpec):
28772877
out_file = File(exists=True, desc='Output file name')
28782878

28792879

2880-
class ExportFile(BaseInterface):
2880+
class ExportFile(SimpleInterface):
28812881
input_spec = ExportFileInputSpec
28822882
output_spec = ExportFileOutputSpec
28832883

28842884
def _run_interface(self, runtime):
28852885
if not self.inputs.clobber and op.exists(self.inputs.out_file):
28862886
raise FileExistsError(errno.EEXIST, 'File %s exists' % self.inputs.out_file)
2887+
if not op.isabs(self.inputs.out_file):
2888+
raise ValueError('Out_file must be an absolute path.')
28872889
if (self.inputs.check_extension and
2888-
op.splitext(self.inputs.in_file)[1] != op.splitext(self.inputs.out_file)[1]):
2889-
raise RuntimeError(f'{self.inputs.in_file} and {self.inputs.out_file} have different extensions')
2890+
split_filename(self.inputs.in_file)[2] != split_filename(self.inputs.out_file)[2]):
2891+
raise RuntimeError('%s and %s have different extensions' % (self.inputs.in_file, self.inputs.out_file))
28902892
shutil.copy(str(self.inputs.in_file), str(self.inputs.out_file))
2893+
self._results['out_file'] = self.inputs.out_file
28912894
return runtime
2892-
2893-
def _list_outputs(self):
2894-
outputs = self.output_spec().get()
2895-
outputs['out_file'] = self.inputs.out_file
2896-
return outputs

0 commit comments

Comments
 (0)