Skip to content

Commit bde4802

Browse files
authored
Merge pull request #3508 from hjmjohnson/fix-write_text-encoding
ENH: Explicitly specify write_text encoding format
2 parents a897847 + e549684 commit bde4802

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

nipype/interfaces/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def _mock_get_ssh_client(self):
709709

710710
def test_ExportFile(tmp_path):
711711
testin = tmp_path / "in.txt"
712-
testin.write_text("test string")
712+
testin.write_text("test string", encoding='utf-8')
713713
i = nio.ExportFile()
714714
i.inputs.in_file = str(testin)
715715
i.inputs.out_file = str(tmp_path / "out.tsv")

nipype/pipeline/engine/tests/test_nodes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ def test_NodeExecutionError(tmp_path, monkeypatch):
352352
exebin = tmp_path / 'bin'
353353
exebin.mkdir()
354354
exe = exebin / 'nipype-node-execution-fail'
355-
exe.write_text('#!/bin/bash\necho "Running"\necho "This should fail" >&2\nexit 1')
355+
exe.write_text(
356+
'#!/bin/bash\necho "Running"\necho "This should fail" >&2\nexit 1',
357+
encoding='utf-8',
358+
)
356359
exe.chmod(exe.stat().st_mode | stat.S_IEXEC)
357360
monkeypatch.setenv("PATH", str(exe.parent.absolute()), prepend=os.pathsep)
358361

nipype/pipeline/engine/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def write_node_report(node, result=None, is_mapnode=False):
125125

126126
if result is None:
127127
logger.debug('[Node] Writing pre-exec report to "%s"', report_file)
128-
report_file.write_text("\n".join(lines))
128+
report_file.write_text("\n".join(lines), encoding='utf-8')
129129
return
130130

131131
logger.debug('[Node] Writing post-exec report to "%s"', report_file)
@@ -138,7 +138,7 @@ def write_node_report(node, result=None, is_mapnode=False):
138138
outputs = result.outputs
139139
if outputs is None:
140140
lines += ["None"]
141-
report_file.write_text("\n".join(lines))
141+
report_file.write_text("\n".join(lines), encoding='utf-8')
142142
return
143143

144144
if isinstance(outputs, Bunch):
@@ -163,7 +163,7 @@ def write_node_report(node, result=None, is_mapnode=False):
163163
subnode_report_files.append("subnode %d : %s" % (i, subnode_file))
164164

165165
lines.append(write_rst_list(subnode_report_files))
166-
report_file.write_text("\n".join(lines))
166+
report_file.write_text("\n".join(lines), encoding='utf-8')
167167
return
168168

169169
lines.append(write_rst_header("Runtime info", level=1))
@@ -205,7 +205,7 @@ def write_node_report(node, result=None, is_mapnode=False):
205205
write_rst_dict(result.runtime.environ),
206206
]
207207

208-
report_file.write_text("\n".join(lines))
208+
report_file.write_text("\n".join(lines), encoding='utf-8')
209209

210210

211211
def write_report(node, report_type=None, is_mapnode=False):

nipype/utils/subprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def run_command(runtime, output=None, timeout=0.01, write_cmdline=False):
102102
stderr = open(errfile, "wb")
103103

104104
if write_cmdline:
105-
(Path(runtime.cwd) / "command.txt").write_text(cmdline)
105+
(Path(runtime.cwd) / "command.txt").write_text(cmdline, encoding='utf-8')
106106

107107
proc = Popen(
108108
cmdline,

tools/update_requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515

1616
# Write requirements
1717
lines[1:-1] = requirements
18-
reqs.write_text("\n".join(lines))
18+
reqs.write_text("\n".join(lines), encoding='utf-8')

tools/update_zenodo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ def decommify(name):
6969

7070
zenodo["creators"] = creators
7171

72-
zenodo_file.write_text("%s\n" % json.dumps(zenodo, indent=2, ensure_ascii=False))
72+
zenodo_file.write_text(
73+
"%s\n" % json.dumps(zenodo, indent=2, ensure_ascii=False), encoding='utf-8'
74+
)

0 commit comments

Comments
 (0)