Various fixes

* fix Windows file path escaping in file modifications
* be explicit about the log code page (also helps for Windows)
* improve file overwrite message
This commit is contained in:
Senko Rasic
2023-12-10 12:15:12 +01:00
parent 6340fe2228
commit cac34297d6
3 changed files with 9 additions and 6 deletions

View File

@@ -212,14 +212,13 @@ class AgentConvo:
return s
def replace_file_content(self, message, file_path, new_content):
escaped_file_path = re.escape(file_path)
pattern = rf'\*\*{escaped_file_path}\*\*:\n```\n(.*?)\n```'
pattern = rf'\*\*{re.escape(file_path)}\*\*:\n```\n(.*?)\n```'
# Escape special characters in new_content for the sake of regex replacement
new_content_escaped = self.escape_specials(new_content)
file_path_escaped = self.escape_specials(file_path)
new_section_content = f'**{file_path}**\n```\n{new_content_escaped}\n```'
new_section_content = f'**{file_path_escaped}**\n```\n{new_content_escaped}\n```'
updated_message, num_replacements = re.subn(pattern, new_section_content, message, flags=re.DOTALL)

View File

@@ -121,7 +121,7 @@ class Project:
print('yes/no', type='button')
should_overwrite_files = styled_text(
self,
f'Do you want to overwrite the dev step {self.args["skip_until_dev_step"]} code with system changes? Type y/n',
"Can I overwrite any changes that you might have made to the project since last running GPT Pilot (y/n)?",
ignore_user_input_count=True
)

View File

@@ -8,7 +8,11 @@ def setup_logger():
log_format = "%(asctime)s [%(filename)s:%(lineno)s - %(funcName)20s() ] %(levelname)s: %(message)s"
# Create a log handler for file output
file_handler = logging.FileHandler(filename=os.path.join(os.path.dirname(__file__), 'debug.log'), mode='w')
file_handler = logging.FileHandler(
filename=os.path.join(os.path.dirname(__file__), 'debug.log'),
mode='w',
encoding='utf-8',
)
# Apply the custom format to the handler
formatter = logging.Formatter(log_format)