diff --git a/nipype/interfaces/tests/test_io.py b/nipype/interfaces/tests/test_io.py index 9816a44a4d..45bd53e32c 100644 --- a/nipype/interfaces/tests/test_io.py +++ b/nipype/interfaces/tests/test_io.py @@ -709,7 +709,7 @@ def _mock_get_ssh_client(self): def test_ExportFile(tmp_path): testin = tmp_path / "in.txt" - testin.write_text("test string") + testin.write_text("test string", encoding='utf-8') i = nio.ExportFile() i.inputs.in_file = str(testin) i.inputs.out_file = str(tmp_path / "out.tsv") diff --git a/nipype/pipeline/engine/tests/test_nodes.py b/nipype/pipeline/engine/tests/test_nodes.py index 44da004620..e0f55f096a 100644 --- a/nipype/pipeline/engine/tests/test_nodes.py +++ b/nipype/pipeline/engine/tests/test_nodes.py @@ -352,7 +352,10 @@ def test_NodeExecutionError(tmp_path, monkeypatch): exebin = tmp_path / 'bin' exebin.mkdir() exe = exebin / 'nipype-node-execution-fail' - exe.write_text('#!/bin/bash\necho "Running"\necho "This should fail" >&2\nexit 1') + exe.write_text( + '#!/bin/bash\necho "Running"\necho "This should fail" >&2\nexit 1', + encoding='utf-8', + ) exe.chmod(exe.stat().st_mode | stat.S_IEXEC) monkeypatch.setenv("PATH", str(exe.parent.absolute()), prepend=os.pathsep) diff --git a/nipype/pipeline/engine/utils.py b/nipype/pipeline/engine/utils.py index b744849c57..a7a3f6f8c3 100644 --- a/nipype/pipeline/engine/utils.py +++ b/nipype/pipeline/engine/utils.py @@ -125,7 +125,7 @@ def write_node_report(node, result=None, is_mapnode=False): if result is None: logger.debug('[Node] Writing pre-exec report to "%s"', report_file) - report_file.write_text("\n".join(lines)) + report_file.write_text("\n".join(lines), encoding='utf-8') return 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): outputs = result.outputs if outputs is None: lines += ["None"] - report_file.write_text("\n".join(lines)) + report_file.write_text("\n".join(lines), encoding='utf-8') return if isinstance(outputs, Bunch): @@ -163,7 +163,7 @@ def write_node_report(node, result=None, is_mapnode=False): subnode_report_files.append("subnode %d : %s" % (i, subnode_file)) lines.append(write_rst_list(subnode_report_files)) - report_file.write_text("\n".join(lines)) + report_file.write_text("\n".join(lines), encoding='utf-8') return lines.append(write_rst_header("Runtime info", level=1)) @@ -205,7 +205,7 @@ def write_node_report(node, result=None, is_mapnode=False): write_rst_dict(result.runtime.environ), ] - report_file.write_text("\n".join(lines)) + report_file.write_text("\n".join(lines), encoding='utf-8') def write_report(node, report_type=None, is_mapnode=False): diff --git a/nipype/utils/subprocess.py b/nipype/utils/subprocess.py index 5611cccc2b..ec00c8b198 100644 --- a/nipype/utils/subprocess.py +++ b/nipype/utils/subprocess.py @@ -102,7 +102,7 @@ def run_command(runtime, output=None, timeout=0.01, write_cmdline=False): stderr = open(errfile, "wb") if write_cmdline: - (Path(runtime.cwd) / "command.txt").write_text(cmdline) + (Path(runtime.cwd) / "command.txt").write_text(cmdline, encoding='utf-8') proc = Popen( cmdline, diff --git a/tools/update_requirements.py b/tools/update_requirements.py index 4dd14a37d7..b7a8a6cf8e 100755 --- a/tools/update_requirements.py +++ b/tools/update_requirements.py @@ -15,4 +15,4 @@ # Write requirements lines[1:-1] = requirements -reqs.write_text("\n".join(lines)) +reqs.write_text("\n".join(lines), encoding='utf-8') diff --git a/tools/update_zenodo.py b/tools/update_zenodo.py index 64eb617644..4560b4fc79 100755 --- a/tools/update_zenodo.py +++ b/tools/update_zenodo.py @@ -69,4 +69,6 @@ def decommify(name): zenodo["creators"] = creators - zenodo_file.write_text("%s\n" % json.dumps(zenodo, indent=2, ensure_ascii=False)) + zenodo_file.write_text( + "%s\n" % json.dumps(zenodo, indent=2, ensure_ascii=False), encoding='utf-8' + )