From d8294cab449456dd95780c36c02e3e4ef42d5021 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 24 Jun 2023 14:57:40 -0700 Subject: [PATCH] simpler --- aider/coders/wholefile_coder.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/aider/coders/wholefile_coder.py b/aider/coders/wholefile_coder.py index caf591307..75df481cd 100644 --- a/aider/coders/wholefile_coder.py +++ b/aider/coders/wholefile_coder.py @@ -1,4 +1,3 @@ -import os from pathlib import Path from aider import diffs @@ -38,11 +37,10 @@ class WholeFileCoder(Coder): if line.startswith("```"): if fname: # ending an existing block - full_path = os.path.abspath(os.path.join(self.root, fname)) + full_path = (Path(self.root) / fname).absolute() - if mode == "diff": - with open(full_path, "r") as f: - orig_lines = f.readlines() + if mode == "diff" and full_path.exists(): + orig_lines = full_path.readlines() show_diff = diffs.diff_partial_update( orig_lines, @@ -55,7 +53,7 @@ class WholeFileCoder(Coder): edited.add(fname) if not self.dry_run: new_lines = "".join(new_lines) - Path(full_path).write_text(new_lines) + full_path.write_text(new_lines) fname = None new_lines = [] @@ -78,11 +76,10 @@ class WholeFileCoder(Coder): if mode == "diff": if fname: # ending an existing block - full_path = os.path.abspath(os.path.join(self.root, fname)) + full_path = (Path(self.root) / fname).absolute() - if mode == "diff": - with open(full_path, "r") as f: - orig_lines = f.readlines() + if mode == "diff" and full_path.exists(): + orig_lines = full_path.readlines() show_diff = diffs.diff_partial_update( orig_lines,