Skip to content

fix: logging error if % in node cmd #2364

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 2 commits into from
Jan 19, 2018
Merged
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,25 +577,25 @@ def _run_command(self, execute, copyfiles=True):
self._originputs = deepcopy(self._interface.inputs)
self._copyfiles_to_wd(execute=execute)

message = '[Node] Running "%s" ("%s.%s")'
message = '[Node] Running "{}" ("{}.{}")'
if issubclass(self._interface.__class__, CommandLine):
try:
cmd = self._interface.cmdline
except Exception as msg:
result.runtime.stderr = '%s\n\n%s' % (
result.runtime.stderr = '{}\n\n{}'.format(
getattr(result.runtime, 'stderr', ''), msg)
_save_resultfile(result, outdir, self.name)
raise
cmdfile = op.join(outdir, 'command.txt')
with open(cmdfile, 'wt') as fd:
print(cmd + "\n", file=fd)
message += ', a CommandLine Interface with command:\n%s' % cmd
logger.info(message, self.name, self._interface.__module__,
self._interface.__class__.__name__)
message += ', a CommandLine Interface with command:\n{}'.format(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not cmd.replace('%', '%%')?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this problem now will happen the same if the command has braces...

Copy link
Member Author

Choose a reason for hiding this comment

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

good call - I would prefer to not alter the cmd if possible, what about substitution first?

Copy link
Contributor

Choose a reason for hiding this comment

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

cmd.replace('%', '%%') is not an in-place operation, why not just do it here?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, we can replace to cover against substitution (%%) / escape characters (\", \\, etc), but isn't .format cleaner?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is just to use python's logging standards, but I'm not particularly attached to one solution or another 👍

logger.info(message.format(self.name, self._interface.__module__,
self._interface.__class__.__name__))
try:
result = self._interface.run()
except Exception as msg:
result.runtime.stderr = '%s\n\n%s' % (
result.runtime.stderr = '%s\n\n%s'.format(
getattr(result.runtime, 'stderr', ''), msg)
_save_resultfile(result, outdir, self.name)
raise
Expand Down