Skip to content
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

ENH: Explicitly specify write_text encoding format #3508

Merged
merged 1 commit into from
Sep 20, 2022

Conversation

hjmjohnson
Copy link
Contributor

@hjmjohnson hjmjohnson commented Sep 19, 2022

When writing reports from nipype the write_text
function could default to using 'ascii' coding
for writing the report. This would fail if any
part of the report tried to generate a unicode
character.

The issue was encountered when the OS environmental variable "PS1" had a non-ascii character in the
environmental variable.

The result was a failure of the nipype pipeline
from running due to an exception being thrown
while trying to write the debugging information.

Summary

Fixes #2942.

List of changes proposed in this PR (pull-request)

Explicitly request writing files with utf-8 encoding. This is particularly important for writing reports that capture information from the environment when the environment could contain unicode characters.

UnicodeEncodeError: 'ascii' codec can't encode character '\u279c' in position 8882: ordinal not in range(128)

NOTE: The 8882'nd character is encountered while trying to print the PS1 environmental variable : ➜

Forcing

report_file = Path('blah/blah/blah/report/report.rst')
report_file.write_text("\n".join(lines), encoding='utf-8')

resolves the failed problem. I have no idea why the io.open() is defaulting to encoding='ascii'.

When writing reports from nipype the write_text
function could default to using 'ascii' coding
for writing the report.  This would fail if any
part of the report tried to generate a unicode
character.

The issue was encountered when the OS environmental
variable "PS1" had a non-ascii character in the
environmental variable.

The result was a failure of the nipype pipeline
from running due to an exception being thrown
while trying to write the debugging information.
@codecov
Copy link

codecov bot commented Sep 19, 2022

Codecov Report

Base: 65.26% // Head: 65.26% // No change to project coverage 👍

Coverage data is based on head (e549684) compared to base (8f405f6).
Patch coverage: 80.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3508   +/-   ##
=======================================
  Coverage   65.26%   65.26%           
=======================================
  Files         309      309           
  Lines       40870    40870           
  Branches     5380     5380           
=======================================
  Hits        26672    26672           
  Misses      13124    13124           
  Partials     1074     1074           
Flag Coverage Δ
unittests 65.04% <80.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
nipype/pipeline/engine/utils.py 75.20% <75.00%> (ø)
nipype/utils/subprocess.py 86.66% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Looks good.

@effigies effigies merged commit bde4802 into nipy:master Sep 20, 2022
@hjmjohnson
Copy link
Contributor Author

@effigies Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nipype raising UnicodeEncodeError; fixed when writing files with encoding='utf-8'
2 participants