Skip to content

run.command(): Refine text decoding #2191

@Lestropie

Description

@Lestropie

Following from #2190. Even if Python2 support is dropped, this could still do with a little tweaking to account for the fact that it's possible for a command to be placing non-text data (not just e.g. accented characters, but even binary data) on stdout in particular, and such data should ideally not be decoded until the point at which an attempt to display it as text is made.

  • When using -info or -debug, stderr is currently split between terminal output that is decoded, and return value that is not; this should remain as-is.

  • For stdout in this case, as well as both stdout / stderr when neither -info nor -debug is used, text decoding should not occur.

  • stdout and stderr data are accessible through two means: the CommandReturn namedtuple and the MRtrixCmdError exception. Each of these would need to provide access to both the raw undecoded binary data, and decoded data in string form:

    • For CommandReturn, any alteration to the .stdout and .stderr members would result in backward-incompatibility. One option to avoid this would be to keep those members as providing the decoded data, and have separate members of the namedtuple providing the undecoded data. But this may result in divergence with the behaviour of MRtrixCmdError depending on what is done there...

    • For MRtrixCmdError, I'd need to check how may locations read from the individual .stdout / .stderr contents, but if such usages are rare, the .__str__() member could perform decoding there instead of expecting those two members to be already decoded. That would also be consistent with how binary data vs. string data is intended to be handled in Python3 (as far as I can tell).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions