Merge branch 'main' into gitignore

This commit is contained in:
Paul Gauthier 2023-07-16 12:21:16 -03:00
commit 67554196f3
6 changed files with 81 additions and 46 deletions

View file

@ -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

View file

@ -1 +1 @@
__version__ = "0.8.3-dev"
__version__ = "0.9.0-dev"

View file

@ -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 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
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.

View file

@ -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

View file

@ -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 tests.utils import IgnorantTemporaryDirectory
class TestRepoMap(unittest.TestCase):

46
tests/utils.py Normal file
View file

@ -0,0 +1,46 @@
import os
import tempfile
import git
from aider.dump import dump # noqa: F401
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)
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