Skip to content

RF: Use runtime.cwd in Rename #2688

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 1 commit into from
Aug 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions nipype/interfaces/utility/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from ..base import (traits, TraitedSpec, DynamicTraitedSpec, File, Undefined,
isdefined, OutputMultiPath, InputMultiPath, BaseInterface,
BaseInterfaceInputSpec, Str)
BaseInterfaceInputSpec, Str, SimpleInterface)
from ..io import IOBase, add_traits
from ...utils.filemanip import ensure_list, copyfile, split_filename

Expand Down Expand Up @@ -204,7 +204,6 @@ def _list_outputs(self):


class RenameInputSpec(DynamicTraitedSpec):

in_file = File(exists=True, mandatory=True, desc="file to rename")
keep_ext = traits.Bool(
desc=("Keep in_file extension, replace "
Expand All @@ -218,12 +217,11 @@ class RenameInputSpec(DynamicTraitedSpec):


class RenameOutputSpec(TraitedSpec):

out_file = traits.File(
exists=True, desc="softlink to original file with new name")


class Rename(IOBase):
class Rename(SimpleInterface, IOBase):
"""Change the name of a file based on a mapped format string.

To use additional inputs that will be defined at run-time, the class
Expand Down Expand Up @@ -303,15 +301,11 @@ def _rename(self):

def _run_interface(self, runtime):
runtime.returncode = 0
_ = copyfile(self.inputs.in_file,
os.path.join(os.getcwd(), self._rename()))
out_file = os.path.join(runtime.cwd, self._rename())
_ = copyfile(self.inputs.in_file, out_file)
self._results['out_file'] = out_file
Copy link
Contributor

@oesteban oesteban Aug 29, 2018

Choose a reason for hiding this comment

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

Now that the constructor of SimpleInterface is not called, then self._results should be initialized in __init__ as an empty dict, shouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Scratch that, I see that you are actually adding the SimpleInterface. For some reason I read the diff in the opposite way.

return runtime

def _list_outputs(self):
outputs = self._outputs().get()
outputs["out_file"] = os.path.join(os.getcwd(), self._rename())
return outputs


class SplitInputSpec(BaseInterfaceInputSpec):
inlist = traits.List(
Expand Down