Skip to content

Commit

Permalink
don't open files when loading project
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonOstrez committed Dec 29, 2023
1 parent d8f484c commit 3b084e5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def save_file(self, data):
path = data['path'] if 'path' in data else name

path, full_path = self.get_full_file_path(path, name)
update_file(full_path, data['content'])
update_file(full_path, data['content'], project=self)
if full_path not in self.files:
self.files.append(full_path)

Expand Down Expand Up @@ -410,7 +410,7 @@ def restore_files(self, development_step_id):

clear_directory(self.root_path, IGNORE_FOLDERS + self.files)
for file_snapshot in file_snapshots:
update_file(file_snapshot.file.full_path, file_snapshot.content)
update_file(file_snapshot.file.full_path, file_snapshot.content, project=self)
if file_snapshot.file.full_path not in self.files:
self.files.append(file_snapshot.file.full_path)

Expand Down
6 changes: 4 additions & 2 deletions pilot/helpers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from utils.style import color_green


def update_file(path: str, new_content: Union[str, bytes]):
def update_file(path: str, new_content: Union[str, bytes], project=None):
"""
Update file with the new content.
:param path: Full path to the file
:param new_content: New content to write to the file
:param project: Optional; a Project object related to the file update. Default is None.
Any intermediate directories will be created if they don't exist.
If file is text, it will be written using UTF-8 encoding.
Expand All @@ -28,7 +29,8 @@ def update_file(path: str, new_content: Union[str, bytes]):

with open(path, file_mode, encoding=encoding) as file:
file.write(new_content)
print({"path": path, "line": None}, type="openFile")
if project is not None and not project.skip_steps:
print({"path": path, "line": None}, type='openFile')
print(color_green(f"Updated file {path}"))


Expand Down
2 changes: 1 addition & 1 deletion pilot/helpers/test_Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def test_save_file(self, mock_file_insert, mock_update_file, test_data):

# Then assert that update_file with the correct path
expected_saved_to = str(Path(test_data['saved_to']))
mock_update_file.assert_called_once_with(expected_saved_to, 'Hello World!')
mock_update_file.assert_called_once_with(expected_saved_to, 'Hello World!', project=project)

# Also assert that File.insert was called with the expected arguments
# expected_file_data = {'app': project.app, 'path': test_data['path'], 'name': test_data['name'],
Expand Down

0 comments on commit 3b084e5

Please sign in to comment.