text
stringlengths 1
93.6k
|
|---|
return text
|
def parse_edit_response(edit_response: str):
|
"""
|
Parses a string containing code diff blocks and extracts the diff content.
|
Takes an edit response string containing code diffs formatted in markdown and extracts
|
the content between ```diff and ``` tags.
|
Args:
|
edit_response (str): A string containing one or more markdown code diff blocks
|
Returns:
|
list[str]: A list of strings containing the extracted diff content, with leading/trailing whitespace removed
|
"""
|
pattern = r"```diff(.*?)```"
|
matches = re.findall(pattern, edit_response, re.DOTALL)
|
diffs = [m.strip() for m in matches]
|
return diffs
|
def apply_diff_changes(diffs: list[str], decomplied_path) -> bool:
|
"""
|
Applies the changes specified in a list of diff blocks.
|
Args:
|
diffs (list[str]): A list of strings containing diff blocks
|
Returns:
|
array(bool, string):
|
bool: True if the changes were successfully applied, False otherwise
|
string: The message.
|
Example Diff:
|
diff --git a/test.txt b/test.txt
|
--- a/test.txt
|
+++ b/test.txt
|
-strawberry
|
+apple
|
@@ -2,5 +2,5 @@
|
"""
|
for diff in diffs:
|
lines = diff.split("\n")
|
# Ignore the first line.
|
# The second and third lines contain the file paths.
|
original_file = None
|
modified_file = None
|
for line in lines:
|
#####################
|
logger(f"Handling pointing line: {line}")
|
if line.startswith("---"):
|
logger(f"Found original file path: {line}")
|
original_file = line.split("---")[-1].strip()
|
original_file = original_file.replace(original_file.split("/")[0], decomplied_path, 1)
|
elif line.startswith("+++"):
|
logger(f"Found modified file path: {line}")
|
modified_file = line.split("+++")[-1].strip()
|
modified_file = modified_file.replace( modified_file.split("/")[0] , decomplied_path, 1)
|
if original_file is None or modified_file is None:
|
return (False, f"One of your diffs is missing the file paths. (eg. --- a/test.txt and +++ b/test.txt).\nThe error diff content: {diff}")
|
# The remaining lines contain the diff.
|
diff_lines = lines[3:]
|
diff_codes = "\n".join(diff_lines)
|
# Apply diff with diff.py
|
with open(original_file, "r") as file:
|
original_content = file.read()
|
# try:
|
# result = apply_patch(original_content, diff_codes)
|
# except:
|
# return (False, f"One of your diffs has a syntax error. Please check and fix your diff.\nThe error diff content: {diff}")
|
result = apply_patch(original_content, diff_codes)
|
with open(modified_file, "w") as file:
|
file.write(result)
|
return (True, "")
|
if __name__ == "__main__":
|
print("This script is not meant to be run directly. Please run console.py instead.")
|
# <FILESEP>
|
"""Developer task automation."""
|
import os
|
import nox
|
nox.options.sessions = [
|
"check_code_formatting",
|
"check_types",
|
"run_tests",
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.