Repository: Pythagora-io/gpt-pilot
File: pilot/helpers/Project.py (Python)

Code before:

        Args:
            data: { name: 'hello.py', path: 'path/to/hello.py', content: 'print("Hello!")' }
        """

        name = data['name'] if 'name' in data and data['name'] != '' else os.path.basename(data['path'])
        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'], project=self)
        if full_path not in self.files:
            self.files.append(full_path)

        (File.insert(app=self.app, path=path, name=name, full_path=full_path)
         .on_conflict(
            conflict_target=[File.app, File.name, File.path],
            preserve=[],
            update={'name': name, 'path': path, 'full_path': full_path})
         .execute())

        if not self.skip_steps:
            inputs_required = self.find_input_required_lines(data['content'])
            for line_number, line_content in inputs_required:
                user_input = None
                print(color_yellow_bold(f'Input required on line {line_number}:\n{line_content}') + '\n')
                while user_input is None or user_input.lower() not in AFFIRMATIVE_ANSWERS + ['continue']:
                    print({'path': full_path, 'line': line_number}, type='openFile')
                    print('continue', type='buttons-only')
                    user_input = ask_user(
                        self,
                        f'Please open the file {data["path"]} on the line {line_number} and add the required input. Once you\'re done, type "y" to continue.',
                        require_some_input=False,
                        ignore_user_input_count=True
                    )

    def get_full_file_path(self, file_path: str, file_name: str) -> Tuple[str, str]:
        """
        Combine file path and name into a full file path.

        :param file_path: File path.
        :param file_name: File name.
        :return: (file_path, absolute_path) pair.

        Tries to combine the two in a way that makes most sense, even if the given path
        have some shared components.
        """

        def normalize_path(path: str) -> Tuple[str, str]:
            """
            Normalizes a path (see rules in comments) and returns (directory, basename) pair.


Review comment (suggestion):
instead of having extra print you can just do ` print(color_yellow_bold(f'Input required on line {line_number}:\n{line_content}') + '\n', type='verbose', category='human-intervention')`

Code after:

        Args:
            data: { name: 'hello.py', path: 'path/to/hello.py', content: 'print("Hello!")' }
        """

        name = data['name'] if 'name' in data and data['name'] != '' else os.path.basename(data['path'])
        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'], project=self)
        if full_path not in self.files:
            self.files.append(full_path)

        (File.insert(app=self.app, path=path, name=name, full_path=full_path)
         .on_conflict(
            conflict_target=[File.app, File.name, File.path],
            preserve=[],
            update={'name': name, 'path': path, 'full_path': full_path})
         .execute())

        if not self.skip_steps:
            inputs_required = self.find_input_required_lines(data['content'])
            for line_number, line_content in inputs_required:
                user_input = None
                print('', type='verbose', category='human-intervention')
                print(color_yellow_bold(f'Input required on line {line_number}:\n{line_content}') + '\n')
                while user_input is None or user_input.lower() not in AFFIRMATIVE_ANSWERS + ['continue']:
                    print({'path': full_path, 'line': line_number}, type='openFile')
                    print('continue', type='buttons-only')
                    user_input = ask_user(
                        self,
                        f'Please open the file {data["path"]} on the line {line_number} and add the required input. Once you\'re done, type "y" to continue.',
                        require_some_input=False,
                        ignore_user_input_count=True
                    )

    def get_full_file_path(self, file_path: str, file_name: str) -> Tuple[str, str]:
        """
        Combine file path and name into a full file path.

        :param file_path: File path.
        :param file_name: File name.
        :return: (file_path, absolute_path) pair.

        Tries to combine the two in a way that makes most sense, even if the given path
        have some shared components.
        """

        def normalize_path(path: str) -> Tuple[str, str]:
            """
            Normalizes a path (see rules in comments) and returns (directory, basename) pair.