mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-03 19:24:59 +00:00
merging from upstream main
This commit is contained in:
commit
179b648864
29 changed files with 3810 additions and 114 deletions
|
@ -1,9 +1,69 @@
|
|||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import git
|
||||
|
||||
# Set of image file extensions
|
||||
IMAGE_EXTENSIONS = {'.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff', '.webp'}
|
||||
|
||||
from .dump import dump # noqa: F401
|
||||
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, PermissionError):
|
||||
pass # Ignore errors (Windows)
|
||||
|
||||
|
||||
class ChdirTemporaryDirectory(IgnorantTemporaryDirectory):
|
||||
def __init__(self):
|
||||
try:
|
||||
self.cwd = os.getcwd()
|
||||
except FileNotFoundError:
|
||||
self.cwd = None
|
||||
|
||||
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):
|
||||
if self.cwd:
|
||||
try:
|
||||
os.chdir(self.cwd)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
super().__exit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
|
||||
class GitTemporaryDirectory(ChdirTemporaryDirectory):
|
||||
def __enter__(self):
|
||||
dname = super().__enter__()
|
||||
self.repo = make_repo(dname)
|
||||
return dname
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
del self.repo
|
||||
super().__exit__(exc_type, exc_val, exc_tb)
|
||||
|
||||
|
||||
def make_repo(path=None):
|
||||
if not path:
|
||||
path = "."
|
||||
repo = git.Repo.init(path)
|
||||
repo.config_writer().set_value("user", "name", "Test User").release()
|
||||
repo.config_writer().set_value("user", "email", "testuser@example.com").release()
|
||||
|
||||
return repo
|
||||
|
||||
def is_image_file(file_name):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue