diff --git a/utils/file_manager.py b/utils/file_manager.py index 781e9af5..6f206068 100644 --- a/utils/file_manager.py +++ b/utils/file_manager.py @@ -44,6 +44,8 @@ def apply_patch(original_text: str, diff_text: str) -> str: print("Patch applied successfully.") with open(file=original_file_name, mode="r", encoding="utf-8") as modified_file: + # Check that this file is computable -> get extention and run proper run + # Use GPT to fix the file and compute again modified_text: str = modified_file.read() print(f"{modified_text=}\n") @@ -51,7 +53,9 @@ def apply_patch(original_text: str, diff_text: str) -> str: print("Failed to apply patch.") print(f"stdout: {e.stdout}") print(f"stderr: {e.stderr}\n") - logging.error(msg=f"apply_patch stderr: {e.stderr}") # pylint: disable=no-member + logging.error( + msg=f"apply_patch stderr: {e.stderr}" + ) # pylint: disable=no-member print(f"Command: {' '.join(e.cmd)}") print(f"Exit status: {e.returncode}") return "" @@ -88,7 +92,8 @@ def correct_hunk_headers(diff_text: str) -> str: lines: list[str] = diff_text.splitlines() updated_lines: list[str] = [] hunk_pattern: re.Pattern[str] = re.compile( - pattern=r'^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@') + pattern=r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@" + ) i = 0 while i < len(lines): @@ -108,19 +113,19 @@ def correct_hunk_headers(diff_text: str) -> str: # Count actual number of lines changed start_index: int = i - while i < len(lines) and not lines[i].startswith('@@'): - if lines[i].startswith('+'): + while i < len(lines) and not lines[i].startswith("@@"): + if lines[i].startswith("+"): s2_actual += 1 - if lines[i].startswith('-'): + if lines[i].startswith("-"): s1_actual += 1 i += 1 # Update the hunk header with actual numbers - updated_hunk_header: str = f'@@ -{l1},{s1_actual} +{l2},{s2_actual} @@' + updated_hunk_header: str = f"@@ -{l1},{s1_actual} +{l2},{s2_actual} @@" updated_lines.append(updated_hunk_header) updated_lines.extend(lines[start_index:i]) - return '\n'.join(updated_lines) + return "\n".join(updated_lines) def extract_file_name(diff_text: str) -> str: