From 8b3862d94de3770e3e09383f12ed6c108125b9aa Mon Sep 17 00:00:00 2001 From: Enzo Martin Date: Sun, 18 Jun 2023 10:34:35 +0200 Subject: [PATCH] Fix linting --- gpt_engineer/chat_to_files.py | 22 ++++++++++++---------- gpt_engineer/db.py | 5 +++-- gpt_engineer/main.py | 10 +++++----- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gpt_engineer/chat_to_files.py b/gpt_engineer/chat_to_files.py index 2175bb3..ec6b755 100644 --- a/gpt_engineer/chat_to_files.py +++ b/gpt_engineer/chat_to_files.py @@ -1,15 +1,17 @@ import re -def parse_chat(chat):# -> List[Tuple[str, str]]: - # Split the chat into sections by the '*CODEBLOCKSBELOW*' token - split_chat = chat.split('*CODEBLOCKSBELOW*') - # Check if the '*CODEBLOCKSBELOW*' token was found +def parse_chat(chat): # -> List[Tuple[str, str]]: + # Split the chat into sections by the "*CODEBLOCKSBELOW*" token + split_chat = chat.split("*CODEBLOCKSBELOW*") + + # Check if the "*CODEBLOCKSBELOW*" token was found is_token_found = len(split_chat) > 1 - # If the '*CODEBLOCKSBELOW*' token is found, use the first part as README and second part as code blocks. - # Otherwise, treat README as optional and proceed with empty README and the entire chat as code blocks - readme = split_chat[0].strip() if is_token_found else 'No readme' + # If the "*CODEBLOCKSBELOW*" token is found, use the first part as README + # and second part as code blocks. Otherwise, treat README as optional and + # proceed with empty README and the entire chat as code blocks + readme = split_chat[0].strip() if is_token_found else "No readme" code_blocks = split_chat[1] if is_token_found else chat # Get all ``` blocks and preceding filenames @@ -19,7 +21,7 @@ def parse_chat(chat):# -> List[Tuple[str, str]]: files = [] for match in matches: # Strip the filename of any non-allowed characters and convert / to \ - path = re.sub(r'[<>"|?*]', '', match.group(1)) + path = re.sub(r'[<>"|?*]', "", match.group(1)) # Get the code code = match.group(2) @@ -28,14 +30,14 @@ def parse_chat(chat):# -> List[Tuple[str, str]]: files.append((path, code)) # Add README to the list - files.append(('README.txt', readme)) + files.append(("README.txt", readme)) # Return the files return files def to_files(chat, workspace): - workspace['all_output.txt'] = chat + workspace["all_output.txt"] = chat files = parse_chat(chat) for file_name, file_content in files: diff --git a/gpt_engineer/db.py b/gpt_engineer/db.py index 6088226..b1e52ff 100644 --- a/gpt_engineer/db.py +++ b/gpt_engineer/db.py @@ -1,6 +1,7 @@ from dataclasses import dataclass from pathlib import Path + # This class represents a simple database that stores its data as files in a directory. # It supports both text and binary files, and can handle directory structures. class DB: @@ -18,7 +19,7 @@ class DB: # Check if the file exists before trying to open it. if full_path.is_file(): # Open the file in text mode and return its content. - with full_path.open('r') as f: + with full_path.open("r") as f: return f.read() else: # If the file doesn't exist, raise an error. @@ -49,4 +50,4 @@ class DBs: logs: DB identity: DB input: DB - workspace: DB \ No newline at end of file + workspace: DB diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index 1aeabc2..e0dff9c 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -1,14 +1,13 @@ -import os import json +import os import pathlib -import typer import shutil +import typer from gpt_engineer.ai import AI -from gpt_engineer.steps import STEPS from gpt_engineer.db import DB, DBs - +from gpt_engineer.steps import STEPS app = typer.Typer() @@ -30,7 +29,7 @@ def chat( memory_path = input_path / (run_prefix + "memory") workspace_path = input_path / (run_prefix + "workspace") - if delete_existing == 'true': + if delete_existing == "true": # Delete files and subdirectories in paths shutil.rmtree(memory_path, ignore_errors=True) shutil.rmtree(workspace_path, ignore_errors=True) @@ -52,5 +51,6 @@ def chat( messages = step(ai, dbs) dbs.logs[step.__name__] = json.dumps(messages) + if __name__ == "__main__": app()