Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract linting process from file_selector #1146

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -453,7 +453,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
Loading