Commit graph

2367 commits

Author SHA1 Message Date
Paul Gauthier
927b97bea1 Added test1.py and test2.py files, dropped *2.py files, and checked if test1.py file is in the abs_fnames list. 2023-07-05 21:41:31 -07:00
Paul Gauthier
7f76559e6c aider: Added a test for the cmd_drop method with glob patterns in the TestCommands class.
# Context:
USER: add a test for that
ASSISTANT: To add a test for the `cmd_drop` method with glob patterns, we need to modify the `tests/test_commands.py` file.

Here's the step-by-step process:

1. Add a new test method `test_cmd_drop_with_glob_patterns` in the `TestCommands` class.
2. In this method, initialize the `Commands` and `InputOutput` objects.
3. Add some files to the chat session.
4. Call the `cmd_drop` method with a glob pattern.
5. Check if the correct files have been removed from the chat session.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
=======
    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)

    def test_cmd_drop_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Add some files to the chat session
        commands.cmd_add("*.py")

        # Call the cmd_drop method with a glob pattern
        commands.cmd_drop("*.py")

        # Check if the Python files have been removed from the chat session
        self.assertNotIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertNotIn(os.path.abspath("test2.py"), coder.abs_fnames)
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:40:01 -07:00
Paul Gauthier
ad5cdc463a aider: Refactored cmd_drop to use glob for matching files against the given word.
# Context:
USER: have `cmd_drop` also glob against the `files`
ASSISTANT: To implement this change, we need to modify the `aider/commands.py` file.

Here's the step-by-step process:

1. In the `cmd_drop` method, use the `glob.glob` function to match the word against the `files`.
2. If no files match, print an error message.
3. If files match, remove them from the chat session.

Here's the code change:

```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_drop(self, args):
        "Remove matching files from the chat session"

        if not args.strip():
            self.io.tool_output("Dropping all files from the chat session.")
            self.coder.abs_fnames = set()

        for word in args.split():
            matched_files = [
                file
                for file in self.coder.abs_fnames
                if word.lower() in os.path.relpath(file, self.coder.root).lower()
            ]
            if not matched_files:
                self.io.tool_error(f"No files matched '{word}'")

            for matched_file in matched_files:
                relative_fname = os.path.relpath(matched_file, self.coder.root)
                self.coder.abs_fnames.remove(matched_file)
                self.io.tool_output(f"Removed {relative_fname} from the chat")
=======
    def cmd_drop(self, args):
        "Remove matching files from the chat session"

        if not args.strip():
            self.io.tool_output("Dropping all files from the chat session.")
            self.coder.abs_fnames = set()

        for word in args.split():
            matched_files = [
                file
                for file in self.coder.abs_fnames
                if any(glob.fnmatch.fnmatch(os.path.relpath(file, self.coder.root), word) for file in self.coder.abs_fnames)
            ]
            if not matched_files:
                self.io.tool_error(f"No files matched '{word}'")

            for matched_file in matched_files:
                relative_fname = os.path.relpath(matched_file, self.coder.root)
                self.coder.abs_fnames.remove(matched_file)
                self.io.tool_output(f"Removed {relative_fname} from the chat")
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:38:44 -07:00
Paul Gauthier
5cd7d9d743 aider: aider: Modified cmd_add to skip file creation if word contains glob characters.
# Context:
USER: if word doesn't match anything, don't ask to add it if it contains glob characters
ASSISTANT: To implement this change, we need to modify the `aider/commands.py` file.

Here's the step-by-step process:

1. In the `cmd_add` method, before asking to create a file, check if the word contains any glob characters (`*`, `?`, `[`, `]`).
2. If it does, skip the creation process and print an error message.

Here's the code change:

```python
aider/commands.py
<<<<<<< ORIGINAL
            if not matched_files:
                if self.coder.repo is not None:
                    create_file = self.io.confirm_ask(
                        (
                            f"No files matched '{word}'. Do you want to create the file and add it"
                            " to git?"
                        ),
                    )
                else:
                    create_file = self.io.confirm_ask(
                        f"No files matched '{word}'. Do you want to create the file?"
                    )

                if create_file:
                    with open(os.path.join(self.coder.root, word), "w"):
                        pass
                    matched_files = [word]
                    if self.coder.repo is not None:
                        self.coder.repo.git.add(os.path.join(self.coder.root, word))
                        commit_message = f"aider: Created and added {word} to git."
                        self.coder.repo.git.commit("-m", commit_message, "--no-verify")
                else:
                    self.io.tool_error(f"No files matched '{word}'")
=======
            if not matched_files:
                if any(char in word for char in "*?[]"):
                    self.io.tool_error(f"No files matched '{word}' and it contains glob characters")
                else:
                    if self.coder.repo is not None:
                        create_file = self.io.confirm_ask(
                            (
                                f"No files matched '{word}'. Do you want to create the file and add it"
                                " to git?"
                            ),
                        )
                    else:
                        create_file = self.io.confirm_ask(
                            f"No files matched '{word}'. Do you want to create the file?"
                        )

                    if create_file:
                        with open(os.path.join(self.coder.root, word), "w"):
                            pass
                        matched_files = [word]
                        if self.coder.repo is not None:
                            self.coder.repo.git.add(os.path.join(self.coder.root, word))
                            commit_message = f"aider: Created and added {word} to git."
                            self.coder.repo.git.commit("-m", commit_message, "--no-verify")
                    else:
                        self.io.tool_error(f"No files matched '{word}'")
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:37:22 -07:00
Paul Gauthier
2b07e2de30 aider: Add a test for cmd_add where nothing matches.
# Context:
USER: add a test for cmd_add where nothing matches
ASSISTANT: To add a test for the `cmd_add` method where nothing matches, we need to modify the `tests/test_commands.py` file.

Here's the step-by-step process:

1. Add a new test method `test_cmd_add_no_match` in the `TestCommands` class.
2. In this method, initialize the `Commands` and `InputOutput` objects.
3. Call the `cmd_add` method with a non-existent file pattern.
4. Check if no files have been added to the chat session.

Here's the code change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)
=======
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)

    def test_cmd_add_no_match(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with a non-existent file pattern
        commands.cmd_add("*.nonexistent")

        # Check if no files have been added to the chat session
        self.assertEqual(len(coder.abs_fnames), 0)
>>>>>>> UPDATED
```
Please let me know if you need any further changes.
2023-07-05 21:35:09 -07:00
Paul Gauthier
09605788d5 cleanup 2023-07-05 21:33:59 -07:00
Paul Gauthier
d97bf17e19 aider: Moved the import statement for the glob module to the top of the aider/commands.py file.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.2.0
rootdir: /Users/gauthier/Projects/aider
configfile: pytest.ini
collected 1 item

tests/test_commands.py F                                                 [100%]

=================================== FAILURES ===================================
_________________ TestCommands.test_cmd_add_with_glob_patterns _________________

self = <tests.test_commands.TestCommands testMethod=test_cmd_add_with_glob_patterns>

    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
>       commands.cmd_add("*.py")

tests/test_commands.py:38:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <aider.commands.Commands object at 0x1113b2250>, args = '*.py'

    def cmd_add(self, args):
        "Add matching files to the chat session using glob patterns"

        added_fnames = []
        for pattern in args.split():
>           matched_files = glob.glob(pattern, recursive=True)
E           NameError: name 'glob' is not defined

aider/commands.py:226: NameError
----------------------------- Captured stdout call -----------------------------
Model: gpt-3.5-turbo
Git repo: none
Repo-map: disabled
=========================== short test summary info ============================
FAILED tests/test_commands.py::TestCommands::test_cmd_add_with_glob_patterns
============================== 1 failed in 0.92s ===============================

ASSISTANT: The error message indicates that the `glob` module is not defined in the `cmd_add` method of the `Commands` class in the `aider/commands.py` file. This is because the `glob` module is imported inside the `Commands` class, but it should be imported at the top of the file.

Here are the changes you need to make:

```python
aider/commands.py
<<<<<<< ORIGINAL
import json
import os
import shlex
import subprocess
import sys

import git
import tiktoken
from prompt_toolkit.completion import Completion

from aider import prompts, utils

class Commands:
    import glob
=======
import json
import os
import shlex
import subprocess
import sys
import glob

import git
import tiktoken
from prompt_toolkit.completion import Completion

from aider import prompts, utils

class Commands:
>>>>>>> UPDATED
```

This change moves the `import glob` statement from inside the `Commands` class to the top of the file, which is the standard place for import statements in Python. This will make the `glob` module available to all methods in the `Commands` class.
2023-07-05 21:30:57 -07:00
Paul Gauthier
7b4088c507 aider: Added a new test method test_cmd_add_with_glob_patterns to the TestCommands class in tests/test_commands.py to test the /add command with glob patterns.
# Context:
USER: add some tests
ASSISTANT: To add tests for the new functionality, we need to modify the `tests/test_commands.py` file.

We will add a new test method `test_cmd_add_with_glob_patterns` to the `TestCommands` class. This method will test the `/add` command with glob patterns.

Here is the proposed change:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string
        commands.cmd_add("foo.txt bar.txt")

        # Check if both files have been created in the temporary directory
        self.assertTrue(os.path.exists("foo.txt"))
        self.assertTrue(os.path.exists("bar.txt"))
=======
    def test_cmd_add_with_glob_patterns(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create some test files
        with open("test1.py", "w") as f:
            f.write("print('test1')")
        with open("test2.py", "w") as f:
            f.write("print('test2')")
        with open("test.txt", "w") as f:
            f.write("test")

        # Call the cmd_add method with a glob pattern
        commands.cmd_add("*.py")

        # Check if the Python files have been added to the chat session
        self.assertIn(os.path.abspath("test1.py"), coder.abs_fnames)
        self.assertIn(os.path.abspath("test2.py"), coder.abs_fnames)

        # Check if the text file has not been added to the chat session
        self.assertNotIn(os.path.abspath("test.txt"), coder.abs_fnames)
>>>>>>> UPDATED
```

This test creates three files: `test1.py`, `test2.py`, and `test.txt`. It then calls the `/add` command with the glob pattern `*.py`. The test checks that the Python files have been added to the chat session and that the text file has not been added.
2023-07-05 21:29:53 -07:00
Paul Gauthier
874b5f8c7a aider: The cmd_add method in the Commands class has been modified to allow the /add command to accept glob patterns.
# Context:
USER: Feature Description
Currently, the /add function accepts directory paths to add the entire directory or spefic file paths to the program's context. A useful enhancement would be to support the use of regex or glob expressions with the /add function. This would give users more flexibility and control to specify exactly which files to include.

Proposed Solution
Allow the /add function to interpret glob or regex patterns. For example, a user could use /add src/*.py to include only Python files from the src directory or /add src/[A-C]* to add only files that start with A, B, or C.

Expected Behavior
When a user runs /add with a regex or glob pattern, the program should add to the context only the files that match the pattern. The program should handle non-matching files or non-existent paths gracefully, preferably by ignoring them and printing a warning message.

Alternatives Considered
An alternative could be providing an additional function, say /addPattern, that accepts regex/glob patterns. This approach would leave the existing /add functionality unchanged for users who don't need the enhanced functionality.

Additional Context
Adding this feature would boost the flexibility of the /add function, making the program more convenient to use for a variety of tasks. Users could, for instance, exclude certain types of files or select a subset of files based on their naming conventions.
ASSISTANT: To implement this feature, we need to modify the `cmd_add` method in the `Commands` class in the `aider/commands.py` file.

The changes will involve:
1. Interpreting the input argument as a glob pattern.
2. Using the `glob` module to find all files that match the pattern.
3. Adding the matched files to the chat session.

Here is the proposed change:

```python
aider/commands.py
<<<<<<< ORIGINAL
    def cmd_add(self, args):
        "Add matching files to the chat session"

        added_fnames = []
        files = self.coder.get_all_relative_files()
        for word in args.split():
            matched_files = [file for file in files if word in file]
=======
    import glob

    def cmd_add(self, args):
        "Add matching files to the chat session using glob patterns"

        added_fnames = []
        for pattern in args.split():
            matched_files = glob.glob(pattern, recursive=True)
>>>>>>> UPDATED
```

This change will allow the `/add` command to accept glob patterns. For example, `/add src/*.py` will add all Python files in the `src` directory to the chat session.
2023-07-05 21:28:53 -07:00
Paul Gauthier
391088fd14 add self.dry_run 2023-07-05 21:22:12 -07:00
Paul Gauthier
85c3bb8f12 rely on io.dry_run 2023-07-05 21:21:37 -07:00
Paul Gauthier
4ee5c49a04 have io.write_text handle dry_run 2023-07-05 21:20:22 -07:00
Paul Gauthier
b46dffbb20 refactor to use io.write_text 2023-07-05 21:18:19 -07:00
Paul Gauthier
0ea52b412f cleanup 2023-07-05 21:11:46 -07:00
Paul Gauthier
1808c47d96 aider: Added write_text function to InputOutput class in aider/io.py.
# Context:
USER: add a write_text func
ASSISTANT: To add a `write_text` function to the `InputOutput` class in the `aider/io.py` file, we need to modify the `aider/io.py` file.

Here is the change:

```python
aider/io.py
<<<<<<< ORIGINAL

    def read_text(self, filename):
        try:
            with open(filename, "r", encoding=self.encoding) as f:
                return f.read()
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(f"{filename}: {e}")
            return
=======

    def read_text(self, filename):
        try:
            with open(filename, "r", encoding=self.encoding) as f:
                return f.read()
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(f"{filename}: {e}")
            return

    def write_text(self, filename, content):
        try:
            with open(filename, "w", encoding=self.encoding) as f:
                f.write(content)
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(f"{filename}: {e}")
            return
>>>>>>> UPDATED
```

This `write_text` function takes a filename and content as arguments, opens the file in write mode, and writes the content to the file. If there is a `FileNotFoundError` or `UnicodeError`, it calls the `tool_error` method with the error message.
2023-07-05 21:11:30 -07:00
Paul Gauthier
de02038a7e remove ref to quoted_file 2023-07-05 21:08:49 -07:00
Paul Gauthier
4126875425 added test_cmd_tokens 2023-07-05 21:08:12 -07:00
Paul Gauthier
7c56dcb16f noop 2023-07-05 21:02:40 -07:00
Paul Gauthier
3897d0a665 removed recheck_abs_fnames 2023-07-05 21:01:26 -07:00
Paul Gauthier
c2c80bbd3c do not /add files that fail to decode 2023-07-05 21:00:10 -07:00
Paul Gauthier
c6e71b443b move import 2023-07-05 20:57:59 -07:00
Paul Gauthier
388f603ef9 aider: Created a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
# Context:
USER: do the todo
ASSISTANT: To complete the TODO, we need to create a file named 'foo.bad' with a non-utf8 encoding. We can use the Python 'codecs' module to create a file with a specific encoding. In this case, we'll use 'iso-8859-15' which is a common encoding that includes characters not present in utf-8.

Here's how to modify the 'test_cmd_add_bad_encoding' method in the 'tests/test_commands.py' file:

```python
tests/test_commands.py
<<<<<<< ORIGINAL
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # TODO: make a new file foo.bad which will fail to decode as utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
=======
    import codecs
    def test_cmd_add_bad_encoding(self):
        # Initialize the Commands and InputOutput objects
        io = InputOutput(pretty=False, yes=True)
        from aider.coders import Coder

        coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef")
        commands = Commands(io, coder)

        # Create a new file foo.bad which will fail to decode as utf-8
        with codecs.open('foo.bad', 'w', encoding='iso-8859-15') as f:
            f.write('ÆØÅ')  # Characters not present in utf-8

        commands.cmd_add("foo.bad")

        self.assertEqual(coder.abs_fnames, set())
>>>>>>> UPDATED
```

This will create a file 'foo.bad' with non-utf8 characters before calling the 'cmd_add' method.
2023-07-05 20:57:21 -07:00
Paul Gauthier
ca45db2898 use utf-8 2023-07-05 20:51:35 -07:00
Paul Gauthier
7542449629 refactor to use io.read_text 2023-07-05 20:49:04 -07:00
Paul Gauthier
d30fb94c72 refactor to use io.read_text 2023-07-05 20:48:09 -07:00
Paul Gauthier
60619f263c refactor to use io.read_text 2023-07-05 20:47:44 -07:00
Paul Gauthier
c8fb1ddaa7 refactor to use io.read_text 2023-07-05 20:46:15 -07:00
Paul Gauthier
413ddb84df refactor to use io.read_text 2023-07-05 20:33:46 -07:00
Paul Gauthier
4c220ff63f refactor to use io.read_text 2023-07-05 20:31:22 -07:00
Paul Gauthier
9cab570f87 refactor to use io.read_text 2023-07-05 20:21:32 -07:00
Paul Gauthier
5f9947a727 aider: Add read_text function to InputOutput class and --encoding command-line switch.
# Context:
USER: Add a read_text function to the InputOutput class. It takes the file name as argument, and returns the text for that file. Internally, if we get a Unicode error or a FileNotFound error, it prints ToolErrorOutput to notify the user, and then returns None. Add a command-line switch, and dash-dash encoding, which defaults to UTF-8. That's the encoding which will be used by the read_text function.

ASSISTANT: To implement the requested changes, we need to modify the following files:

1. `aider/io.py`: To add the `read_text` function to the `InputOutput` class.
2. `aider/main.py`: To add the `--encoding` command-line switch.

Let's start with the changes to `aider/io.py`:

```python
aider/io.py
<<<<<<< ORIGINAL
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
=======
class InputOutput:
    num_error_outputs = 0
    num_user_asks = 0

    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
        encoding="utf-8",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None

        self.input = input
        self.output = output

        self.pretty = pretty
        if self.output:
            self.pretty = False

        self.yes = yes

        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        self.encoding = encoding

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=False, no_color=True)

        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")

    def read_text(self, filename):
        try:
            with open(filename, "r", encoding=self.encoding) as f:
                return f.read()
        except (FileNotFoundError, UnicodeError) as e:
            self.tool_error(str(e))
            return None
>>>>>>> UPDATED
```

Now, let's add the `--encoding` command-line switch to `aider/main.py`:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--encoding",
        default="utf-8",
        help="Specify the encoding to use when reading files (default: utf-8)",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
>>>>>>> UPDATED
```

These changes should implement the requested functionality. Please review and let me know if any further changes are needed.
2023-07-05 19:33:59 -07:00
Paul Gauthier
d9f2c32aa9 Merge branch 'main' into encodings 2023-07-05 17:16:36 -07:00
Paul Gauthier
9915261097 link to benchmark 2023-07-05 17:15:36 -07:00
Paul Gauthier
5dba1624c7 fix broken test 2023-07-05 17:11:39 -07:00
Paul Gauthier
e996c56a51 more robust get_tracked_files with pathlib 2023-07-05 16:55:37 -07:00
Paul Gauthier
c6696e7245 Added a test case to fail if git posix paths are not turned into windows paths 2023-07-05 16:53:43 -07:00
Paul Gauthier
bc60e7fd1c use Path.touch() to create new files 2023-07-05 15:44:12 -07:00
Paul Gauthier
b3d624b7cd Run windows tests on push 2023-07-05 15:26:06 -07:00
Paul Gauthier
decc0a15ff initial 2023-07-05 15:25:36 -07:00
Paul Gauthier
de40f77a4f turn all windows tests back on 2023-07-05 15:20:37 -07:00
Paul Gauthier
f2a814d536 be more careful about ensuring self.root is an abspath 2023-07-05 15:16:57 -07:00
Paul Gauthier
a0774bf46a resolve cmd line files to abs path 2023-07-05 15:14:09 -07:00
Paul Gauthier
55b1634811 added debug output 2023-07-05 15:08:11 -07:00
Paul Gauthier
f3af05f3ee simpler, faster run just failing test 2023-07-05 14:57:35 -07:00
Paul Gauthier
e107819085 chdir inside test 2023-07-05 14:48:46 -07:00
Paul Gauthier
43103978b5 cleanup 2023-07-05 14:44:45 -07:00
Paul Gauthier
640a463a9c no pretty when output 2023-07-05 14:42:42 -07:00
Paul Gauthier
0ff4e5362b just 3.11 for windows for now 2023-07-05 14:39:21 -07:00
Paul Gauthier
e34078da04 force_terminal=False 2023-07-05 14:38:35 -07:00
Paul Gauthier
e1e8e8e10a Turn off fancy Console if self.output 2023-07-05 14:36:13 -07:00