From 96a37c8eaf998bdd4e9dfe5e0fe8dd2f2dcae704 Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Fri, 29 Dec 2023 20:30:06 +0000 Subject: [PATCH] remove 'Updated file...' and 'Saving file...' from extension --- pilot/helpers/Project.py | 12 ++++++++---- pilot/helpers/agents/Developer.py | 12 ++++++------ pilot/helpers/files.py | 8 +++++--- pilot/utils/questionary.py | 8 ++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/pilot/helpers/Project.py b/pilot/helpers/Project.py index 1ccddd9f45..2a7fd0078c 100644 --- a/pilot/helpers/Project.py +++ b/pilot/helpers/Project.py @@ -386,7 +386,8 @@ class Project: development_step, created = DevelopmentSteps.get_or_create(id=development_step_id) for file in files: - print(color_cyan(f'Saving file {file["full_path"]}')) + if not self.check_ipc(): + print(color_cyan(f'Saving file {file["full_path"]}')) # TODO this can be optimized so we don't go to the db each time file_in_db, created = File.get_or_create( app=self.app, @@ -447,15 +448,18 @@ class Project: raise e def log(self, text, message_type): - if self.ipc_client_instance is None or self.ipc_client_instance.client is None: - print(text) - else: + if self.check_ipc(): self.ipc_client_instance.send({ 'type': MESSAGE_TYPE[message_type], 'content': str(text), }) if message_type == MESSAGE_TYPE['user_input_request']: return self.ipc_client_instance.listen() + else: + print(text) + + def check_ipc(self): + return self.ipc_client_instance is not None and self.ipc_client_instance.client is not None def finish_loading(self): print('', type='loadingFinished') diff --git a/pilot/helpers/agents/Developer.py b/pilot/helpers/agents/Developer.py index fc67ed9d5d..1657933c56 100644 --- a/pilot/helpers/agents/Developer.py +++ b/pilot/helpers/agents/Developer.py @@ -223,10 +223,10 @@ class Developer(Agent): self.get_run_command(convo) if self.run_command: - if (self.project.ipc_client_instance is None or self.project.ipc_client_instance.client is None): - human_intervention_description += color_yellow_bold('\n\nIf you want to run the app, just type "r" and press ENTER and that will run `' + self.run_command + '`') - else: + if self.project.check_ipc(): print(self.run_command, type='run_command') + else: + human_intervention_description += color_yellow_bold('\n\nIf you want to run the app, just type "r" and press ENTER and that will run `' + self.run_command + '`') response = self.project.ask_for_human_intervention('I need human intervention:', human_intervention_description, @@ -465,11 +465,11 @@ class Developer(Agent): user_description = 'Can you check if the app works please? ' + user_description if self.run_command: - if self.project.ipc_client_instance is None or self.project.ipc_client_instance.client is None: + if self.project.check_ipc(): + print(self.run_command, type='run_command') + else: user_description += color_yellow_bold( '\n\nIf you want to run the app, just type "r" and press ENTER and that will run `' + self.run_command + '`') - else: - print(self.run_command, type='run_command') # continue_description = '' # TODO: Wait for a specific string in the output or timeout? diff --git a/pilot/helpers/files.py b/pilot/helpers/files.py index be07b457bc..50b4fe61e1 100644 --- a/pilot/helpers/files.py +++ b/pilot/helpers/files.py @@ -29,9 +29,11 @@ def update_file(path: str, new_content: Union[str, bytes], project=None): with open(path, file_mode, encoding=encoding) as file: file.write(new_content) - if project is not None and not project.skip_steps: - print({"path": path, "line": None}, type='openFile') - print(color_green(f"Updated file {path}")) + if project is not None: # project can be None only in tests + if not project.skip_steps: + print({"path": path, "line": None}, type='openFile') + if not project.check_ipc(): + print(color_green(f"Updated file {path}")) def get_file_contents( diff --git a/pilot/utils/questionary.py b/pilot/utils/questionary.py index 05c808f1b0..8a0a82ac05 100644 --- a/pilot/utils/questionary.py +++ b/pilot/utils/questionary.py @@ -28,14 +28,14 @@ def styled_text(project, question, ignore_user_input_count=False, style=None, hi print(color_yellow_bold(f'{user_input.user_input}')) return user_input.user_input - if project.ipc_client_instance is None or project.ipc_client_instance.client is None: + if project.check_ipc(): + response = print(question, type='user_input_request') + print(response) + else: used_style = style if style is not None else style_config.get_style() question = remove_ansi_codes(question) # Colorama and questionary are not compatible and styling doesn't work flush_input() response = questionary.text(question, style=used_style).unsafe_ask() # .ask() is included here - else: - response = print(question, type='user_input_request') - print(response) if not ignore_user_input_count: save_user_input(project, question, response, hint)