Skip to content

Commit ff690ee

Browse files
authored
Merge pull request #1146 from gpt-engineer-org/refactor-linting-to-filestore
extract linting process from file_selector
2 parents 1e292f4 + 48b64b8 commit ff690ee

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

gpt_engineer/applications/cli/file_selector.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import toml
2828

2929
from gpt_engineer.core.default.disk_memory import DiskMemory
30-
from gpt_engineer.core.default.file_store import FileStore
3130
from gpt_engineer.core.default.paths import metadata_path
3231
from gpt_engineer.core.files_dict import FilesDict
3332
from gpt_engineer.core.git import filter_by_gitignore, is_git_repo
@@ -62,7 +61,7 @@ class FileSelector:
6261
"cost additional tokens and potentially overflow token limit.\n\n"
6362
)
6463
LINTING_STRING = '[linting]\n# "linting" = "off"\n\n'
65-
isLinting = True
64+
is_linting = True
6665

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

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

121-
if self.isLinting:
122-
file_store = FileStore()
123-
files = FilesDict(content_dict)
124-
linted_files = file_store.linting(files)
125-
return linted_files
126-
127-
return FilesDict(content_dict)
120+
return FilesDict(content_dict), self.is_linting
128121

129122
def editor_file_selector(
130123
self, input_path: Union[str, Path], init: bool = True
@@ -181,7 +174,7 @@ def editor_file_selector(
181174
"linting" in linting_status
182175
and linting_status["linting"].get("linting", "").lower() == "off"
183176
):
184-
self.isLinting = False
177+
self.is_linting = False
185178
self.LINTING_STRING = '[linting]\n"linting" = "off"\n\n'
186179
print("\nLinting is disabled")
187180

@@ -305,10 +298,10 @@ def get_files_from_toml(
305298
"linting" in edited_tree
306299
and edited_tree["linting"].get("linting", "").lower() == "off"
307300
):
308-
self.isLinting = False
301+
self.is_linting = False
309302
print("\nLinting is disabled")
310303
else:
311-
self.isLinting = True
304+
self.is_linting = True
312305

313306
# Iterate through the files in the .toml and append selected files to the list
314307
for file, _ in edited_tree["files"].items():

gpt_engineer/applications/cli/main.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,12 @@ def main(
455455
files = FileStore(project_path)
456456
if not no_execution:
457457
if improve_mode:
458-
files_dict_before = FileSelector(project_path).ask_for_files()
458+
files_dict_before, is_linting = FileSelector(project_path).ask_for_files()
459+
460+
# lint the code
461+
if is_linting:
462+
files_dict_before = files.linting(files_dict_before)
463+
459464
files_dict = handle_improve_mode(prompt, agent, memory, files_dict_before)
460465
if not files_dict or files_dict_before == files_dict:
461466
print(

0 commit comments

Comments
 (0)