Commit graph

10395 commits

Author SHA1 Message Date
Paul Gauthier
4bc4e6f611 aider: Updated Coder class in aider/coder.py to call the new get_input function with root parameter and rel_fnames instead of absolute file names.
# Context:
USER: update coder.py to call the new get_input
ASSISTANT: I will update the `Coder` class in the `aider/coder.py` file to call the new `get_input` function.

```python
aider/coder.py
<<<<<<< ORIGINAL
        inp = self.io.get_input(self.abs_fnames, self.commands)
=======
        rel_fnames = [os.path.relpath(fname, self.root) for fname in self.abs_fnames]
        inp = self.io.get_input(self.root, rel_fnames, self.commands)
>>>>>>> UPDATED
```

This change updates the `run_loop` method in the `Coder` class to call the new `get_input` function with the `root` parameter and the `rel_fnames` instead of the absolute file names.
2023-05-27 08:47:21 -07:00
Paul Gauthier
487040203e aider: Updated get_input to take a root param and receive rel_fnames not abs fnames, and updated FileContentCompleter to work with them.
# Context:
USER: change get_input to take a root param and receive rel_fnames not abs fnames. don't compute short_fnames, just use rel_fnames. also update FileContentCompleter to take root and rel_fnames and work with them.
ASSISTANT: To make the requested changes, I need you to provide me with *read-write* access to the following files:

1. `aider/io.py`
2. `aider/prompts.py`

Once you've granted me access to these files, I can provide you with the necessary code modifications.
USER: I added these *read-write* files: aider/io.py
ASSISTANT: Great! I will now make the changes to the `get_input` function and the `FileContentCompleter` class in the `aider/io.py` file.

```python
aider/io.py
<<<<<<< ORIGINAL
class FileContentCompleter(Completer):
    def __init__(self, fnames, commands):
        self.commands = commands

        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
=======
class FileContentCompleter(Completer):
    def __init__(self, root, rel_fnames, commands):
        self.commands = commands

        self.words = set()
        for rel_fname in rel_fnames:
            fname = os.path.join(root, rel_fname)
            with open(fname, "r") as f:
                content = f.read()
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
    def get_input(self, fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        fnames = list(fnames)
        if len(fnames) > 1:
            common_prefix = os.path.commonpath(fnames)
            if not common_prefix.endswith(os.path.sep):
                common_prefix += os.path.sep
            short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames]
        elif len(fnames):
            short_fnames = [os.path.basename(fnames[0])]
        else:
            short_fnames = []

        show = " ".join(short_fnames)
=======
    def get_input(self, root, rel_fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        rel_fnames = list(rel_fnames)
        show = " ".join(rel_fnames)
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
            completer_instance = FileContentCompleter(fnames, commands)
=======
            completer_instance = FileContentCompleter(root, rel_fnames, commands)
>>>>>>> UPDATED
```

These changes will update the `get_input` function to take a `root` parameter and receive `rel_fnames` instead of absolute file names. The `FileContentCompleter` class is also updated to take the `root` and `rel_fnames` parameters and work with them.
2023-05-27 08:46:06 -07:00
Paul Gauthier
e19df5804c updated add prompt 2023-05-27 08:42:03 -07:00
Paul Gauthier
4fd1bf7f21 Added test_check_for_ambiguous_filename_mentions_of_longer_paths 2023-05-27 08:39:18 -07:00
Paul Gauthier
08164034ff aider: Updated check_for_file_mentions to only add a filename match if it is unambiguous and no other addable_rel_fnames have a basename that also matches.
# Context:
USER: on check_for_file_mentions, only add a fname match if it is unambiguous and no other addable_rel_fnames have a basename that also matches
ASSISTANT: To update the `check_for_file_mentions` method to only add a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches, modify the method as follows:

```python
aider/coder.py
<<<<<<< ORIGINAL
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname in words or rel_fname in words:
                mentioned_rel_fnames.add(rel_fname)
=======
        fname_to_rel_fnames = {}
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname not in fname_to_rel_fnames:
                fname_to_rel_fnames[fname] = []
            fname_to_rel_fnames[fname].append(rel_fname)

        for fname, rel_fnames in fname_to_rel_fnames.items():
            if len(rel_fnames) == 1 and (fname in words or rel_fnames[0] in words):
                mentioned_rel_fnames.add(rel_fnames[0])
>>>>>>> UPDATED
```

This change will ensure that the method only adds a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches.
2023-05-27 08:34:20 -07:00
Paul Gauthier
3732f62a9c Use ./ paths for the test 2023-05-27 08:32:39 -07:00
Paul Gauthier
4dc2e6a5c8 aider: Enhanced check_for_file_mentions to match filenames without the path and add the correct fully pathed file to abs_fnames.
# Context:
USER: the test_check_for_filename_mentions_of_longer_paths is failing. because check_for_file_mentions only matches on the full path. enhance check_for_file_mentions so that if the filename is mentioned without the path, it still adds the correct fully pathed file to abs_fnames
ASSISTANT: To enhance the `check_for_file_mentions` method to match filenames without the path and add the correct fully pathed file to `abs_fnames`, update the method as follows:

```python
aider/coder.py
<<<<<<< ORIGINAL
        for word in words:
            if word in addable_rel_fnames:
                mentioned_rel_fnames.add(word)
=======
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname in words or rel_fname in words:
                mentioned_rel_fnames.add(rel_fname)
>>>>>>> UPDATED
```

This change will ensure that the method matches filenames without the path and adds the correct fully pathed file to `abs_fnames`.
2023-05-27 08:31:42 -07:00
Paul Gauthier
c8cf78b5cf Added a new test to check for filename mentions of longer paths. 2023-05-27 08:30:17 -07:00
Paul Gauthier
7e75cfb1fa added missing import 2023-05-27 08:29:05 -07:00
Paul Gauthier
bcf258f1c6 aider: Modified test to check if coder.abs_fnames contains both files.
# Context:
USER: don't compare the result string. check that coder.abs_fnames now contains both files
ASSISTANT: To update the test to check if `coder.abs_fnames` contains both files, modify the test as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Check if the result is as expected
        self.assertEqual(result, "Added files: file1.txt, file2.py")
=======
        # Check if coder.abs_fnames contains both files
        expected_files = {os.path.abspath("file1.txt"), os.path.abspath("file2.py")}
        self.assertEqual(coder.abs_fnames, expected_files)
>>>>>>> UPDATED
```

This change will ensure that the test checks if `coder.abs_fnames` contains both files instead of comparing the result string.
2023-05-27 08:28:31 -07:00
Paul Gauthier
4ac2143cc2 Initialized Coder object with mocked IO and mocked repo, and updated coder.repo instead of coder.root. 2023-05-27 08:27:45 -07:00
Paul Gauthier
0fc40df8e6 aider: Replaced manual setting of abs_fnames with a mocked git.Repo object that has its ls_files method return the desired file paths.
# Context:
USER: don't set the files in abs_fnames. patch self.repo.git.ls_files to return them
ASSISTANT: To patch `self.repo.git.ls_files` to return the files in `abs_fnames`, we will modify the `test_check_for_file_mentions` function in the `tests/test_coder.py` file.

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Initialize the Coder object with the mocked IO
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Add sample files to the Coder object
        coder.abs_fnames = {
            "/path/to/repo/file1.txt",
            "/path/to/repo/file2.py",
        }
        coder.root = "/path/to/repo"
=======
        # Mock the git repo
        mock_repo = MagicMock()
        mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py"

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder(io=mock_io, openai_api_key="fake_key", repo=mock_repo)
        coder.root = "/path/to/repo"
>>>>>>> UPDATED
```

This change replaces the manual setting of `abs_fnames` with a mocked `git.Repo` object that has its `ls_files` method return the desired file paths.
2023-05-27 08:26:16 -07:00
Paul Gauthier
475f85bcc3 aider: Added a test function for the check_for_file_mentions method in tests/test_coder.py.
# Context:
USER: write a test for check_for_file_mentions
ASSISTANT: To write a test for the `check_for_file_mentions` method, we will create a new test function in the `tests/test_coder.py` file. Here's the test function:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
=======
import unittest
from unittest.mock import MagicMock
from aider.coder import Coder

class TestCoder(unittest.TestCase):
    def test_check_for_file_mentions(self):
        # Mock the IO object
        mock_io = MagicMock()
        mock_io.get_input.return_value = "Please check file1.txt and file2.py"
        mock_io.confirm_ask.return_value = True

        # Initialize the Coder object with the mocked IO
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Add sample files to the Coder object
        coder.abs_fnames = {
            "/path/to/repo/file1.txt",
            "/path/to/repo/file2.py",
        }
        coder.root = "/path/to/repo"

        # Call the check_for_file_mentions method
        result = coder.check_for_file_mentions("Please check file1.txt and file2.py")

        # Check if the result is as expected
        self.assertEqual(result, "Added files: file1.txt, file2.py")

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This test function creates a `Coder` object with a mocked IO, adds sample files to the object, and then calls the `check_for_file_mentions` method with a sample input. It checks if the returned result is as expected.
2023-05-27 08:23:51 -07:00
Paul Gauthier
dd3bdfbe15 Added new files to the git repo: tests/test_coder.py 2023-05-27 08:22:37 -07:00
Paul Gauthier
dbb4870021 if the user mentions a file, add it to the chat 2023-05-27 08:11:41 -07:00
Paul Gauthier
090b46983c Explain /help on launch 2023-05-27 07:51:56 -07:00
Paul Gauthier
e0de81fea6 copy 2023-05-27 07:42:21 -07:00
Paul Gauthier
976c5c8e74 Handle missing api key gracefully 2023-05-27 06:35:50 -07:00
Paul Gauthier
b0d860bcf4 Handle missing api key gracefully 2023-05-27 06:35:37 -07:00
Paul Gauthier
3f5e4130ea fixed test 2023-05-27 06:25:16 -07:00
Paul Gauthier
82e7dcb7ba updated usage 2023-05-27 06:24:22 -07:00
Paul Gauthier
9832807814 aider: Added custom exception MissingAPIKeyError to Coder class to raise an error when no OpenAI API key is provided.
# Context:
USER: what's a good exception to raise in coder if no api key
ASSISTANT: A good exception to raise in this case would be a custom exception, such as `MissingAPIKeyError`. You can define this custom exception by subclassing the built-in `ValueError` class. Here's how to define and raise the custom exception:

```python
aider/coder.py
<<<<<<< ORIGINAL
class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            io.tool_error('No OpenAI API key provided.')
=======
class MissingAPIKeyError(ValueError):
    pass

class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            raise MissingAPIKeyError('No OpenAI API key provided.')
>>>>>>> UPDATED
```

This custom exception `MissingAPIKeyError` will provide a more specific and informative error message when the API key is not provided.
2023-05-27 06:21:06 -07:00
Paul Gauthier
abf73d00a2 aider: Added --openai-api-key argument to the command-line parser, passed it to the Coder class, and set the openai.api_key accordingly.
# Context:
USER: add a new arg --openai-api-key. pass it to Coder
ASSISTANT: I will add a new argument `--openai-api-key` and pass it to the `Coder` class. Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
openai.api_key = os.getenv("OPENAI_API_KEY")

class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
=======
class Coder:
    abs_fnames = None
    repo = None
    last_aider_commit_hash = None
    last_asked_for_commit_time = 0

    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
        openai_api_key=None,
    ):
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            openai.api_key = os.getenv("OPENAI_API_KEY")
>>>>>>> UPDATED
```

These changes add the `--openai-api-key` argument to the command-line parser, pass it to the `Coder` class, and set the `openai.api_key` accordingly.
2023-05-27 06:17:11 -07:00
Paul Gauthier
139a141be9 removed dotenv 2023-05-27 06:13:34 -07:00
Paul Gauthier
1fb1765b38 drop dotenv 2023-05-27 06:06:51 -07:00
Paul Gauthier
3e99b4f45c moved test_main_pretty_from_env to end of file 2023-05-27 05:20:10 -07:00
Paul Gauthier
89c412ccfe aider: Added a new test method test_main_pretty_from_env to check if the pretty option is set to False by creating a temporary directory, writing a .env file with AIDER_PRETTY=false, and then calling main with no arguments.
# Context:
USER: add a test like test_main_args. it should test pretty by making a .env file with AIDER_PRETTY=false and then call main with no args.
ASSISTANT: To add a new test for the `pretty` option, you can create a new test method in the `TestMain` class in the `tests/test_main.py` file. Here's the code for the new test:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_args(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)

            with patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"])
                _, kwargs = MockCoder.call_args
                assert kwargs["auto_commits"] is False
=======
    def test_main_args(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)

            with patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"])
                _, kwargs = MockCoder.call_args
                assert kwargs["auto_commits"] is False

    def test_main_pretty_from_env(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            with open(".env", "w") as env_file:
                env_file.write("AIDER_PRETTY=false\n")

            with patch("aider.main.Coder") as MockCoder:
                main([])
                _, kwargs = MockCoder.call_args
                assert kwargs["pretty"] is False
>>>>>>> UPDATED
```

This new test method, `test_main_pretty_from_env`, creates a temporary directory, writes a `.env` file with `AIDER_PRETTY=false`, and then calls `main` with no arguments. It checks if the `pretty` option is set to `False` as expected.
2023-05-27 05:18:26 -07:00
Paul Gauthier
e02b612126 aider: Added functionality to load .env file from git_root if available.
# Context:
USER: load_dotenv from the git_root if avail
ASSISTANT: To load the `.env` file from the `git_root` if available, you can modify the `load_dotenv()` function call in `aider/main.py`. Here's the change:

```python
aider/main.py
<<<<<<< ORIGINAL
    load_dotenv()
=======
    if git_root:
        load_dotenv(os.path.join(git_root, ".env"))
    else:
        load_dotenv()
>>>>>>> UPDATED
```

This change checks if `git_root` is available and loads the `.env` file from the `git_root` directory. If `git_root` is not available, it falls back to the default behavior of loading the `.env` file from the current working directory.
2023-05-27 05:15:05 -07:00
Paul Gauthier
a1ff34d084 updated usage 2023-05-27 05:13:27 -07:00
Paul Gauthier
4c76a8a242 Added --dirty-commits 2023-05-27 05:12:50 -07:00
Paul Gauthier
a2fa4f2929 aider: Added --dirty-commits argument to the argument parser in aider/main.py.
# Context:
USER: add --dirty-commits too
ASSISTANT: To add the `--dirty-commits` argument, we need to modify the `aider/main.py` file. Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
=======
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
    parser.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable dirty commit of changes",
    )
>>>>>>> UPDATED
```

These changes add the `--dirty-commits` argument to the argument parser in `aider/main.py`.
2023-05-27 05:10:23 -07:00
Paul Gauthier
ed1a886a4f aider: Added --no-dirty-commits argument to the argument parser in aider/main.py, passed it to the Coder class, and set the self.dirty_commits attribute in the Coder class in aider/coder.py.
# Context:
USER: add a new arg like --no-auto-commits, but called --no-dirty-commits. pass it to Coder and set self.dirty_commits
ASSISTANT: To add the `--no-dirty-commits` argument, we need to modify the `aider/main.py` file and pass the new argument to the `Coder` class in the `aider/coder.py` file.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of changes",
    )
=======
    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of changes",
    )
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable dirty commit of changes",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        use_ctags=args.ctags,
        verbose=args.verbose,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
        self.verbose = verbose
        self.abs_fnames = set()
        self.cur_messages = []
        self.done_messages = []

        self.io = io
        self.auto_commits = auto_commits
        self.dry_run = dry_run
=======
    def __init__(
        self,
        io,
        main_model="gpt-4",
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        use_ctags=False,
        verbose=False,
    ):
        self.verbose = verbose
        self.abs_fnames = set()
        self.cur_messages = []
        self.done_messages = []

        self.io = io
        self.auto_commits = auto_commits
        self.dirty_commits = dirty_commits
        self.dry_run = dry_run
>>>>>>> UPDATED
```

These changes add the `--no-dirty-commits` argument to the argument parser in `aider/main.py`, pass it to the `Coder` class, and set the `self.dirty_commits` attribute in the `Coder` class in `aider/coder.py`.
2023-05-27 05:09:28 -07:00
Paul Gauthier
a24e150e49 more tests, including --pretty 2023-05-27 05:06:36 -07:00
Paul Gauthier
24e78229b2 cleaned up --no-autocommit test 2023-05-27 05:03:30 -07:00
Paul Gauthier
2bb1c34bd5 aider: Updated test_main_with_no_auto_commits to only check if auto_commits is set to False.
# Context:
USER: in test_main_with_empty_dir_new_file can we *just* check the auto_commits=False?
ASSISTANT: Sure, I'll update the `test_main_with_empty_dir_new_file` test to check if `auto_commits` is set to `False`.

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_empty_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            main(["foo.txt"], input=pipe_input, output=DummyOutput())
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
=======
    def test_main_with_empty_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["foo.txt"], input=pipe_input, output=DummyOutput())
                MockCoder.assert_called_with(
                    unittest.mock.ANY,
                    main_model=unittest.mock
^C KeyboardInterrupt
USER: in test_main_with_no_auto_commits can we *just* check the auto_commits=False?
ASSISTANT: Sure, I'll update the `test_main_with_no_auto_commits` test to only check if `auto_commits` is set to `False`.

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_no_auto_commits(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                MockCoder.assert_called_with(
                    unittest.mock.ANY,
                    main_model=unittest.mock.ANY,
                    fnames=unittest.mock.ANY,
                    pretty=unittest.mock.ANY,
                    show_diffs=unittest.mock.ANY,
                    auto_commits=False,
                    dry_run=unittest.mock.ANY,
                    use_ctags=unittest.mock.ANY,
                    verbose=unittest.mock.ANY,
                )
            pipe_input.close()
=======
    def test_main_with_no_auto_commits(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                MockCoder.assert_called_with(
                    unittest.mock.ANY,
                    main_model=unittest.mock.ANY,
                    fnames=unittest.mock.ANY,
                    pretty=unittest.mock.ANY,
                    show_diffs=unittest.mock.ANY,
                    auto_commits=False,
                    dry_run=unittest.mock.ANY,
                    use_ctags=unittest.mock.ANY,

^C KeyboardInterrupt
USER: i want to avoid listing all the other args and ANY
ASSISTANT: I understand. I'll update the `test_main_with_no_auto_commits` test to only check if `auto_commits` is set to `False` without listing all the other arguments.

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_no_auto_commits(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                MockCoder.assert_called_with(
                    unittest.mock.ANY,
                    main_model=unittest.mock.ANY,
                    fnames=unittest.mock.ANY,
                    pretty=unittest.mock.ANY,
                    show_diffs=unittest.mock.ANY,
                    auto_commits=False,
                    dry_run=unittest.mock.ANY,
                    use_ctags=unittest.mock.ANY,
                    verbose=unittest.mock.ANY,
                )
            pipe_input.close()
=======
    def test_main_with_no_auto_commits(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                _, kwargs = MockCoder.call_args
                assert kwargs["auto_commits"] is False
            pipe_input.close()
>>>>>>> UPDATED
```

This change will make the test only check if `auto_commits` is set to `False` without listing all the other arguments.
2023-05-27 05:00:50 -07:00
Paul Gauthier
01963c28f8 aider: Added a test which runs main with --no-auto-commits and patches Coder with a mock to see that it gets called with auto_commits=False.
# Context:
USER: add a test which runs main with --no-auto-commits and patches Coder with a mock to see that it gets called with auto_commits=False
ASSISTANT: To add the test, you need to modify the `tests/test_main.py` file. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
class TestMain(TestCase):
    def test_main_with_empty_dir_no_files_on_command(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            main([], input=pipe_input, output=DummyOutput())
            pipe_input.close()

    def test_main_with_empty_dir_new_file(self):
=======
class TestMain(TestCase):
    def test_main_with_empty_dir_no_files_on_command(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            main([], input=pipe_input, output=DummyOutput())
            pipe_input.close()

    def test_main_with_no_auto_commits(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            pipe_input = create_input(StringIO(""))
            with unittest.mock.patch("aider.main.Coder") as MockCoder:
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                MockCoder.assert_called_with(
                    unittest.mock.ANY,
                    main_model=unittest.mock.ANY,
                    fnames=unittest.mock.ANY,
                    pretty=unittest.mock.ANY,
                    show_diffs=unittest.mock.ANY,
                    auto_commits=False,
                    dry_run=unittest.mock.ANY,
                    use_ctags=unittest.mock.ANY,
                    verbose=unittest.mock.ANY,
                )
            pipe_input.close()

    def test_main_with_empty_dir_new_file(self):
>>>>>>> UPDATED
```

This new test case `test_main_with_no_auto_commits` creates a temporary directory, changes the current working directory to it, and then runs the `main` function with the `--no-auto-commits` flag. It also patches the `Coder` class with a mock to check if it gets called with `auto_commits=False`.
2023-05-27 04:56:32 -07:00
Paul Gauthier
a9cc332e2d Removed test for disabling auto commits. 2023-05-27 04:54:55 -07:00
Paul Gauthier
d240e5ebc0 Show options on -v 2023-05-27 04:49:16 -07:00
Paul Gauthier
ed70a32671 Added import for MagicMock in test_main.py. 2023-05-27 04:39:47 -07:00
Paul Gauthier
10dc4f6557 aider: Replaced unittest.mock with MagicMock in test_main_no_auto_commits.
# Context:
USER: I ran this command:

 pytest tests/test_main.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 4 items

tests/test_main.py F...                                                  [100%]

=================================== FAILURES ===================================
______________________ TestMain.test_main_no_auto_commits ______________________

self = <tests.test_main.TestMain testMethod=test_main_no_auto_commits>

    def test_main_no_auto_commits(self):
>       with unittest.mock.patch("aider.main.Coder") as MockCoder:
E       AttributeError: module 'unittest' has no attribute 'mock'

tests/test_main.py:38: AttributeError
=========================== short test summary info ============================
FAILED tests/test_main.py::TestMain::test_main_no_auto_commits - AttributeErr...
========================= 1 failed, 3 passed in 1.32s ==========================

ASSISTANT: Apologies for the oversight. It seems that the `unittest.mock` module is not available in your Python version. You can use the `mock` module instead, which is available as a separate package. First, you need to install the `mock` package using pip:

```
pip install mock
```

Then, update the import statement in the `tests/test_main.py` file to use the `mock` package:

```python
tests/test_main.py
<<<<<<< ORIGINAL
import os
import tempfile
import unittest
from unittest import TestCase
from aider.main import main
=======

^C KeyboardInterrupt
USER: would magicmock work?
ASSISTANT: Yes, `MagicMock` can be used in this case. It is a part of the `unittest.mock` module in Python 3.3 and later. Since you are using Python 3.11.3, you can use `MagicMock` directly from the `unittest.mock` module.

First, update the import statement in the `tests/test_main.py` file to import `MagicMock`:

```python
tests/test_main.py
<<<<<<< ORIGINAL
import os
import tempfile
import unittest
from unittest import TestCase
from aider.main import main
=======
import os
import tempfile
import unittest
from unittest import TestCase, MagicMock
from aider.main import main
>>>>>>> UPDATED
```

Then, update the test function `test_main_no_auto_commits` to use `MagicMock` instead of `unittest.mock.patch`:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_no_auto_commits(self):
        with unittest.mock.patch("aider.main.Coder") as MockCoder:
            with tempfile.TemporaryDirectory() as temp_dir:
                os.chdir(temp_dir)
                subprocess.run(["git", "init"], cwd=temp_dir)
                pipe_input = create_input(StringIO(""))
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                pipe_input.close()

            mock_coder_instance = MockCoder.return_value
            self.assertFalse(mock_coder_instance.auto_commits)
=======
    def test_main_no_auto_commits(self):
        with MagicMock() as MockCoder:
            with tempfile.TemporaryDirectory() as temp_dir:
                os.chdir(temp_dir)
                subprocess.run(["git", "init"], cwd=temp_dir)
                pipe_input = create_input(StringIO(""))
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                pipe_input.close()

            mock_coder_instance = MockCoder.return_value
            self.assertFalse(mock_coder_instance.auto_commits)
>>>>>>> UPDATED
```

This should resolve the issue with the test.
2023-05-27 04:38:32 -07:00
Paul Gauthier
ca752f37af aider: Import unittest module in tests/test_main.py.
# Context:
USER: I ran this command:

 pytest tests/test_main.py

And got this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 4 items

tests/test_main.py F...                                                  [100%]

=================================== FAILURES ===================================
______________________ TestMain.test_main_no_auto_commits ______________________

self = <tests.test_main.TestMain testMethod=test_main_no_auto_commits>

    def test_main_no_auto_commits(self):
>       with unittest.mock.patch("aider.main.Coder") as MockCoder:
E       NameError: name 'unittest' is not defined

tests/test_main.py:37: NameError
=========================== short test summary info ============================
FAILED tests/test_main.py::TestMain::test_main_no_auto_commits - NameError: n...
========================= 1 failed, 3 passed in 1.29s ==========================

ASSISTANT: It looks like the `unittest` module is not imported in the `tests/test_main.py` file. To fix this issue, you need to add the import statement for the `unittest` module at the beginning of the file.

Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
import os
import tempfile
from unittest import TestCase
from aider.main import main
=======
import os
import tempfile
import unittest
from unittest import TestCase
from aider.main import main
>>>>>>> UPDATED
```

This will import the `unittest` module and resolve the `NameError`.
2023-05-27 04:36:54 -07:00
Paul Gauthier
22482deedf aider: Added a new test to check if the --no-auto-commits flag is passed correctly to the Coder class.
# Context:
USER: add a test which runs main with --no-auto-commits and mocks Coder to see that it gets passed in correctly
ASSISTANT: To add the test, we'll modify the `tests/test_main.py` file. We'll create a new test function called `test_main_no_auto_commits` and use the `unittest.mock.patch` to mock the `Coder` class. Inside the test function, we'll run the `main` function with the `--no-auto-commits` flag and check if the `auto_commits` attribute of the mocked `Coder` instance is set to `False`.

Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"], cwd=temp_dir)
            pipe_input = create_input(StringIO(""))
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
=======
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"], cwd=temp_dir)
            pipe_input = create_input(StringIO(""))
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))

    def test_main_no_auto_commits(self):
        with unittest.mock.patch("aider.main.Coder") as MockCoder:
            with tempfile.TemporaryDirectory() as temp_dir:
                os.chdir(temp_dir)
                subprocess.run(["git", "init"], cwd=temp_dir)
                pipe_input = create_input(StringIO(""))
                main(["--no-auto-commits"], input=pipe_input, output=DummyOutput())
                pipe_input.close()

            mock_coder_instance = MockCoder.return_value
            self.assertFalse(mock_coder_instance.auto_commits)
>>>>>>> UPDATED
```

This will add the new test to check if the `--no-auto-commits` flag is passed correctly to the `Coder` class.
2023-05-27 04:36:14 -07:00
Paul Gauthier
065388eb0f wip 2023-05-27 04:34:12 -07:00
Paul Gauthier
316c11465b aider: Added fontcolor to dot.edge label.
# Context:
USER: set the dot.edge label color to color
ASSISTANT: ```python
aider/repomap.py
<<<<<<< ORIGINAL
        dot.edge(refs, defs, penwidth=str(weight), color=color, label=label)
=======
        dot.edge(refs, defs, penwidth=str(weight), color=color, label=label, fontcolor=color)
>>>>>>> UPDATED
```
2023-05-26 18:53:18 -07:00
Paul Gauthier
0ab7d0c1f1 wip 2023-05-26 18:52:41 -07:00
Paul Gauthier
2a28c9453c aider: Added fontsize attribute to dot.node function call in call_map() function in aider/repomap.py to make the font size of the node label scale with the size of the node.
# Context:
USER: make the dot.node font scale with size
ASSISTANT: To make the font scale with the size of the node, we need to modify the `dot.node` function call in the `call_map()` function in the `aider/repomap.py` file. We will add the `fontsize` attribute and set it proportional to the `size`.

Here's the change:

```python
aider/repomap.py
<<<<<<< ORIGINAL
        dot.node(fname, penwidth=str(pen), width=str(size), height=str(size))
=======
        fontsize = str(10 * size)
        dot.node(fname, penwidth=str(pen), width=str(size), height=str(size), fontsize=fontsize)
>>>>>>> UPDATED
```

This will make the font size of the node label scale with the size of the node.
2023-05-26 18:44:31 -07:00
Paul Gauthier
dc1c3e467d Changed graphviz.Graph() to graphviz.Digraph() with a graph_attr ratio of .5. 2023-05-26 18:43:46 -07:00
Paul Gauthier
349bcf6973 aider: Removed all the G nodes except the top 10 based on their PageRank.
# Context:
USER: do the todo
ASSISTANT: I see a "todo" comment in the `call_map()` function. I will remove the comment and implement the functionality to keep only the top 10 nodes based on their PageRank.

```python
aider/repomap.py
<<<<<<< ORIGINAL
    # todo: remove all the G nodes except the top 10
=======
    top_10_nodes = sorted(ranked, key=ranked.get, reverse=True)[:10]
    nodes_to_remove = [node for node in G.nodes if node not in top_10_nodes]
    G.remove_nodes_from(nodes_to_remove)
>>>>>>> UPDATED
```

This change will keep only the top 10 nodes in the graph based on their PageRank and remove the rest.
2023-05-26 18:40:41 -07:00
Paul Gauthier
f46feda846 cleap up edge logic 2023-05-26 18:37:59 -07:00
Paul Gauthier
9e40898226 node size 2023-05-26 18:26:34 -07:00