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

fix: logging error if % in node cmd #2364

merged 2 commits into from
Jan 19, 2018

Conversation

mgxd
Copy link
Member

@mgxd mgxd commented Jan 10, 2018

Fixes #2325 (comment).

Changes proposed in this pull request

  • move some logging to .format substitution

Eventually, we should be thorough and replace most % substitutions

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 👍

@@ -577,7 +577,9 @@ def _run_command(self, execute, copyfiles=True):
self._originputs = deepcopy(self._interface.inputs)
self._copyfiles_to_wd(execute=execute)

message = '[Node] Running "{}" ("{}.{}")'
message = '[Node] Running "{}" ("{}.{}")'.format(
Copy link
Contributor

@oesteban oesteban Jan 10, 2018

Choose a reason for hiding this comment

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

None of these variables should contain percent characters. Why not letting the logging module do the work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Better to do the substitution first (before cmd is added), since a rouge % or {} will lead to a logging error

@mgxd mgxd merged commit ce6f37c into nipy:master Jan 19, 2018
@effigies effigies added this to the 1.0 milestone Jan 19, 2018
@mgxd mgxd deleted the fix/nodelog branch January 24, 2018 16:08
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.

3 participants