Skip to content

Commit

Permalink
Merge pull request #1146 from gpt-engineer-org/refactor-linting-to-fi…
Browse files Browse the repository at this point in the history
…lestore

extract linting process from file_selector
  • Loading branch information
viborc authored Jun 6, 2024
2 parents 1e292f4 + 48b64b8 commit ff690ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
19 changes: 6 additions & 13 deletions gpt_engineer/applications/cli/file_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import toml

from gpt_engineer.core.default.disk_memory import DiskMemory
from gpt_engineer.core.default.file_store import FileStore
from gpt_engineer.core.default.paths import metadata_path
from gpt_engineer.core.files_dict import FilesDict
from gpt_engineer.core.git import filter_by_gitignore, is_git_repo
Expand Down Expand Up @@ -62,7 +61,7 @@ class FileSelector:
"cost additional tokens and potentially overflow token limit.\n\n"
)
LINTING_STRING = '[linting]\n# "linting" = "off"\n\n'
isLinting = True
is_linting = True

def __init__(self, project_path: Union[str, Path]):
"""
Expand All @@ -77,7 +76,7 @@ def __init__(self, project_path: Union[str, Path]):
self.metadata_db = DiskMemory(metadata_path(self.project_path))
self.toml_path = self.metadata_db.path / self.FILE_LIST_NAME

def ask_for_files(self) -> FilesDict:
def ask_for_files(self) -> tuple[FilesDict, bool]:
"""
Prompts the user to select files for context improvement.
Expand Down Expand Up @@ -118,13 +117,7 @@ def ask_for_files(self) -> FilesDict:
except UnicodeDecodeError:
print(f"Warning: File not UTF-8 encoded {file_path}, skipping")

if self.isLinting:
file_store = FileStore()
files = FilesDict(content_dict)
linted_files = file_store.linting(files)
return linted_files

return FilesDict(content_dict)
return FilesDict(content_dict), self.is_linting

def editor_file_selector(
self, input_path: Union[str, Path], init: bool = True
Expand Down Expand Up @@ -181,7 +174,7 @@ def editor_file_selector(
"linting" in linting_status
and linting_status["linting"].get("linting", "").lower() == "off"
):
self.isLinting = False
self.is_linting = False
self.LINTING_STRING = '[linting]\n"linting" = "off"\n\n'
print("\nLinting is disabled")

Expand Down Expand Up @@ -305,10 +298,10 @@ def get_files_from_toml(
"linting" in edited_tree
and edited_tree["linting"].get("linting", "").lower() == "off"
):
self.isLinting = False
self.is_linting = False
print("\nLinting is disabled")
else:
self.isLinting = True
self.is_linting = True

# Iterate through the files in the .toml and append selected files to the list
for file, _ in edited_tree["files"].items():
Expand Down
7 changes: 6 additions & 1 deletion gpt_engineer/applications/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,12 @@ def main(
files = FileStore(project_path)
if not no_execution:
if improve_mode:
files_dict_before = FileSelector(project_path).ask_for_files()
files_dict_before, is_linting = FileSelector(project_path).ask_for_files()

# lint the code
if is_linting:
files_dict_before = files.linting(files_dict_before)

files_dict = handle_improve_mode(prompt, agent, memory, files_dict_before)
if not files_dict or files_dict_before == files_dict:
print(
Expand Down

0 comments on commit ff690ee

Please sign in to comment.