From 47086657ab87e6d6e3017061fadede12bd01484f Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Mon, 24 Mar 2025 09:50:11 +0000 Subject: [PATCH 1/3] fixing the append file write mode --- src/PyodideWorker.js | 2 +- .../Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PyodideWorker.js b/src/PyodideWorker.js index 200c742b0..811467bb3 100644 --- a/src/PyodideWorker.js +++ b/src/PyodideWorker.js @@ -116,7 +116,7 @@ const PyodideWorker = () => { self.content += content if len(self.content) > MAX_FILE_SIZE: raise OSError(f"File '{self.filename}' exceeds maximum file size of {MAX_FILE_SIZE} bytes") - with _original_open(self.filename, "w") as f: + with _original_open(self.filename, mode) as f: f.write(self.content) basthon.kernel.write_file({ "filename": self.filename, "content": self.content, "mode": mode }) diff --git a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx index 50594e250..0d39afe80 100644 --- a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx +++ b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.jsx @@ -223,7 +223,7 @@ const PyodideRunner = ({ active, outputPanels = ["text", "visual"] }) => { updatedContent = content; } else if (mode === "a") { updatedContent = - (componentToUpdate ? componentToUpdate.content + "\n" : "") + content; + (componentToUpdate ? componentToUpdate.content : "") + content; } if (componentToUpdate) { From 78adb35b3f661b75e2d1ea3f561a56e90451cd12 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Mon, 24 Mar 2025 12:05:56 +0000 Subject: [PATCH 2/3] test fixing --- .../Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js index bea6c9264..fef816ebe 100644 --- a/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js +++ b/src/components/Editor/Runners/PythonRunner/PyodideRunner/PyodideRunner.test.js @@ -307,7 +307,7 @@ describe("When file write event is received", () => { worker.postMessageFromWorker({ method: "handleFileWrite", filename: "existing_file.txt", - content: "new content", + content: "\nnew content", mode: "a", }); expect(dispatchSpy).toHaveBeenCalledWith({ @@ -364,7 +364,7 @@ describe("When file write event is received", () => { worker.postMessageFromWorker({ method: "handleFileWrite", filename: "existing_file.txt", - content: "new content", + content: "\nnew content", mode: "a", }); expect(dispatchSpy).toHaveBeenCalledWith({ From ec67e7936fc213e880f20f273317480fc3d378fa Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Mon, 24 Mar 2025 12:07:29 +0000 Subject: [PATCH 3/3] updating changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5a14d0f..0e42619de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Bugs in append mode for writing to files in python (#1200) + ## [0.29.1] - 2025-02-21 ### Fixed