From cdf35cd12238f6bde68a2fa1269be1660627a2dc Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:02:35 -0300 Subject: [PATCH 1/8] refac --- tests/test_repomap.py | 15 +-------------- tests/utils.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 tests/utils.py diff --git a/tests/test_repomap.py b/tests/test_repomap.py index dc68a4d9d..b34593221 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -1,24 +1,11 @@ import os -import tempfile import unittest from unittest.mock import patch from aider.io import InputOutput from aider.repomap import RepoMap - -class IgnorantTemporaryDirectory: - def __init__(self): - self.temp_dir = tempfile.TemporaryDirectory() - - def __enter__(self): - return self.temp_dir.__enter__() - - def __exit__(self, exc_type, exc_val, exc_tb): - try: - self.temp_dir.__exit__(exc_type, exc_val, exc_tb) - except OSError: - pass # Ignore errors (Windows) +from .utils import IgnorantTemporaryDirectory class TestRepoMap(unittest.TestCase): diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 000000000..1629c4425 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,15 @@ +import tempfile + + +class IgnorantTemporaryDirectory: + def __init__(self): + self.temp_dir = tempfile.TemporaryDirectory() + + def __enter__(self): + return self.temp_dir.__enter__() + + def __exit__(self, exc_type, exc_val, exc_tb): + try: + self.temp_dir.__exit__(exc_type, exc_val, exc_tb) + except OSError: + pass # Ignore errors (Windows) From 86cea0143486a1a062cbad94b0ed29f88de8155e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:05:18 -0300 Subject: [PATCH 2/8] aider: Change the relative import to an absolute import for the `IgnorantTemporaryDirectory` class in `test_repomap.py`. # Aider chat conversation: USER: ImportError: Failed to import test module: test_repomap Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 436, in _find_test_path module = self._get_module_from_name(name) File "/opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name __import__(name) File "/home/runner/work/aider/aider/tests/test_repomap.py", line 8, in from .utils import IgnorantTemporaryDirectory ImportError: attempted relative import with no known parent package ASSISTANT: The error message indicates that Python is unable to find the `utils` module when it's being imported in `test_repomap.py`. This is because the import statement is using a relative import with the dot (`.`) prefix, which is not working in this context. To fix this, we need to change the relative import to an absolute import. This means we need to specify the full path to the `utils` module from the project's root directory. Here is the change you need to make: ```python tests/test_repomap.py <<<<<<< ORIGINAL from .utils import IgnorantTemporaryDirectory ======= from tests.utils import IgnorantTemporaryDirectory >>>>>>> UPDATED ``` This change tells Python to import the `IgnorantTemporaryDirectory` class from the `utils` module located in the `tests` directory, which is an absolute path from the project's root directory. --- tests/test_repomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_repomap.py b/tests/test_repomap.py index b34593221..1ecc951b2 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -5,7 +5,7 @@ from unittest.mock import patch from aider.io import InputOutput from aider.repomap import RepoMap -from .utils import IgnorantTemporaryDirectory +from tests.utils import IgnorantTemporaryDirectory class TestRepoMap(unittest.TestCase): From a9cca05680d867ec8c3c6663acd11be6e160660b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:39:07 -0300 Subject: [PATCH 3/8] Added GitTemporaryDirectory --- tests/test_coder.py | 58 ++++++++++++++++++++++----------------------- tests/utils.py | 31 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 30 deletions(-) diff --git a/tests/test_coder.py b/tests/test_coder.py index 445aab345..80a92f902 100644 --- a/tests/test_coder.py +++ b/tests/test_coder.py @@ -12,6 +12,7 @@ from aider import models from aider.coders import Coder from aider.dump import dump # noqa: F401 from aider.io import InputOutput +from tests.utils import GitTemporaryDirectory class TestCoder(unittest.TestCase): @@ -95,47 +96,44 @@ class TestCoder(unittest.TestCase): self.assertEqual(coder.abs_fnames, expected_files) def test_check_for_ambiguous_filename_mentions_of_longer_paths(self): - # Mock the IO object - mock_io = MagicMock() + with GitTemporaryDirectory(): + io = InputOutput(pretty=False, yes=True) + coder = Coder.create(models.GPT4, None, io) - # Initialize the Coder object with the mocked IO and mocked repo - coder = Coder.create(models.GPT4, None, mock_io) + fname = Path("file1.txt") + fname.touch() - fname = Path("file1.txt") - fname.touch() + other_fname = Path("other") / "file1.txt" + other_fname.parent.mkdir(parents=True, exist_ok=True) + other_fname.touch() - other_fname = Path("other") / "file1.txt" - other_fname.parent.mkdir(parents=True, exist_ok=True) - other_fname.touch() + mock = MagicMock() + mock.return_value = set([str(fname), str(other_fname)]) + coder.get_tracked_files = mock - mock = MagicMock() - mock.return_value = set([str(fname), str(other_fname)]) - coder.get_tracked_files = mock + # Call the check_for_file_mentions method + coder.check_for_file_mentions(f"Please check {fname}!") - # Call the check_for_file_mentions method - coder.check_for_file_mentions(f"Please check {fname}!") - - self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) + self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) def test_check_for_subdir_mention(self): - # Mock the IO object - mock_io = MagicMock() + with GitTemporaryDirectory(): + io = InputOutput(pretty=False, yes=True) + coder = Coder.create(models.GPT4, None, io) - # Initialize the Coder object with the mocked IO and mocked repo - coder = Coder.create(models.GPT4, None, mock_io) + fname = Path("other") / "file1.txt" + fname.parent.mkdir(parents=True, exist_ok=True) + fname.touch() - fname = Path("other") / "file1.txt" - fname.parent.mkdir(parents=True, exist_ok=True) - fname.touch() + mock = MagicMock() + mock.return_value = set([str(fname)]) + coder.get_tracked_files = mock - mock = MagicMock() - mock.return_value = set([str(fname)]) - coder.get_tracked_files = mock + dump(fname) + # Call the check_for_file_mentions method + coder.check_for_file_mentions(f"Please check `{fname}`") - # Call the check_for_file_mentions method - coder.check_for_file_mentions(f"Please check `{fname}`") - - self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) + self.assertEqual(coder.abs_fnames, set([str(fname.resolve())])) def test_get_commit_message(self): # Mock the IO object diff --git a/tests/utils.py b/tests/utils.py index 1629c4425..c1b589eea 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,5 +1,10 @@ +import os import tempfile +import git + +from aider.dump import dump # noqa: F401 + class IgnorantTemporaryDirectory: def __init__(self): @@ -13,3 +18,29 @@ class IgnorantTemporaryDirectory: self.temp_dir.__exit__(exc_type, exc_val, exc_tb) except OSError: pass # Ignore errors (Windows) + + +class ChdirTemporaryDirectory(IgnorantTemporaryDirectory): + def __init__(self): + self.cwd = os.getcwd() + super().__init__() + + def __enter__(self): + res = super().__enter__() + os.chdir(self.temp_dir.name) + return res + + def __exit__(self, exc_type, exc_val, exc_tb): + os.chdir(self.cwd) + super().__exit__(exc_type, exc_val, exc_tb) + + +class GitTemporaryDirectory(ChdirTemporaryDirectory): + def __enter__(self): + res = super().__enter__() + + repo = git.Repo.init() + repo.config_writer().set_value("user", "name", "Test User").release() + repo.config_writer().set_value("user", "email", "testuser@example.com").release() + + return res From a3f3a18ee0be5402feb83b04129595466aaa4c78 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:47:03 -0300 Subject: [PATCH 4/8] Updated HISTORY --- HISTORY.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 22b4ee8ba..94b5fefa5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,12 +1,13 @@ # Release history -### Next release +### v0.9.0 - Support for the OpenAI models in [Azure](https://aider.chat/docs/faq.html#azure) - Added `--show-repo-map` - Improved output when retrying connections to the OpenAI API - Redacted api key from `--verbose` output - Bugfix: recognize and add files in subdirectories mentioned by user or GPT +- [Benchmarked](https://aider.chat/docs/benchmarks.html) at 53.8% for gpt-3.5-turbo/whole ### v0.8.3 From a57c651c054effcee175037153978afac566aa9c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:47:24 -0300 Subject: [PATCH 5/8] version bump to 0.9.0 --- aider/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/__init__.py b/aider/__init__.py index 21c382240..3e2f46a3a 100644 --- a/aider/__init__.py +++ b/aider/__init__.py @@ -1 +1 @@ -__version__ = "0.8.3-dev" +__version__ = "0.9.0" From 4b8211554a38a8063bbf797567c8dfb5b8a1519f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 09:47:35 -0300 Subject: [PATCH 6/8] set version to 0.9.0-dev --- aider/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/__init__.py b/aider/__init__.py index 3e2f46a3a..8ea1e3450 100644 --- a/aider/__init__.py +++ b/aider/__init__.py @@ -1 +1 @@ -__version__ = "0.9.0" +__version__ = "0.9.0-dev" From bcbfa0babd19f94e182e2a456c7e3e651fcbcd3e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 12:20:03 -0300 Subject: [PATCH 7/8] copy --- docs/faq.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index 8bcd28a59..784800409 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -78,6 +78,9 @@ This minimizes your use of the context window, as well as costs. ## Aider isn't editing my files? +Sometimes GPT will reply with some code changes that won't get applied to your local files. +In these cases, aider might say something like "Failed to apply edit to *filename*". + This usually happens because GPT is not specifying the edits to make in the format that aider expects. GPT-3.5 is especially prone to disobeying the system prompt instructions in this manner, but it also happens with GPT-4. From 10b327d4875f09a18da13966cc901c2954c3df0f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 16 Jul 2023 12:21:01 -0300 Subject: [PATCH 8/8] copy --- docs/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/faq.md b/docs/faq.md index 784800409..0bacf5dd3 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -78,7 +78,7 @@ This minimizes your use of the context window, as well as costs. ## Aider isn't editing my files? -Sometimes GPT will reply with some code changes that won't get applied to your local files. +Sometimes GPT will reply with some code changes that don't get applied to your local files. In these cases, aider might say something like "Failed to apply edit to *filename*". This usually happens because GPT is not specifying the edits