mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
Merge branch 'main' into swe-bench
This commit is contained in:
commit
fa0aa60c97
8 changed files with 72 additions and 40 deletions
|
@ -313,7 +313,7 @@ def get_parser(default_config_files, git_root):
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--lint",
|
"--lint",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Run the linter on all dirty files, fix problems and commit",
|
help="Lint and fix provided files, or dirty files if none provided",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
|
|
|
@ -84,10 +84,19 @@ class Coder:
|
||||||
)
|
)
|
||||||
|
|
||||||
if not main_model:
|
if not main_model:
|
||||||
main_model = models.Model(models.DEFAULT_MODEL_NAME)
|
if from_coder:
|
||||||
|
main_model = from_coder.main_model
|
||||||
|
else:
|
||||||
|
main_model = models.Model(models.DEFAULT_MODEL_NAME)
|
||||||
|
|
||||||
if edit_format is None:
|
if edit_format is None:
|
||||||
edit_format = main_model.edit_format
|
if from_coder:
|
||||||
|
edit_format = from_coder.edit_format
|
||||||
|
else:
|
||||||
|
edit_format = main_model.edit_format
|
||||||
|
|
||||||
|
if not io and from_coder:
|
||||||
|
io = from_coder.io
|
||||||
|
|
||||||
if from_coder:
|
if from_coder:
|
||||||
use_kwargs = dict(from_coder.original_kwargs) # copy orig kwargs
|
use_kwargs = dict(from_coder.original_kwargs) # copy orig kwargs
|
||||||
|
@ -127,6 +136,9 @@ class Coder:
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def clone(self, **kwargs):
|
||||||
|
return Coder.create(from_coder=self, **kwargs)
|
||||||
|
|
||||||
def get_announcements(self):
|
def get_announcements(self):
|
||||||
lines = []
|
lines = []
|
||||||
lines.append(f"Aider v{__version__}")
|
lines.append(f"Aider v{__version__}")
|
||||||
|
|
|
@ -153,40 +153,51 @@ class Commands:
|
||||||
commit_message = args.strip()
|
commit_message = args.strip()
|
||||||
self.coder.repo.commit(message=commit_message)
|
self.coder.repo.commit(message=commit_message)
|
||||||
|
|
||||||
def cmd_lint(self, args):
|
def cmd_lint(self, args="", fnames=None):
|
||||||
"Commit, run the linter on all dirty files, fix problems and commit again"
|
"Lint and fix provided files or in-chat files if none provided"
|
||||||
|
|
||||||
if not self.coder.repo:
|
if not self.coder.repo:
|
||||||
self.io.tool_error("No git repository found.")
|
self.io.tool_error("No git repository found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.coder.repo.is_dirty():
|
if not fnames:
|
||||||
self.io.tool_error("No more changes to commit.")
|
fnames = self.coder.get_inchat_relative_files()
|
||||||
return
|
|
||||||
|
|
||||||
fnames = self.coder.repo.get_dirty_files()
|
if not fnames:
|
||||||
linted = False
|
self.io.tool_error("No dirty files to lint.")
|
||||||
|
return
|
||||||
|
|
||||||
|
lint_coder = None
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
try:
|
try:
|
||||||
errors = self.coder.linter.lint(fname, cmd=args)
|
errors = self.coder.linter.lint(fname)
|
||||||
linted = True
|
|
||||||
except FileNotFoundError as err:
|
except FileNotFoundError as err:
|
||||||
self.io.tool_error(f"Unable to lint {fname}")
|
self.io.tool_error(f"Unable to lint {fname}")
|
||||||
self.io.tool_error(str(err))
|
self.io.tool_error(str(err))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if errors:
|
if not errors:
|
||||||
# Commit everything before we start fixing lint errors
|
continue
|
||||||
if self.coder.repo.is_dirty():
|
|
||||||
self.cmd_commit("")
|
|
||||||
|
|
||||||
self.io.tool_error(errors)
|
# Commit everything before we start fixing lint errors
|
||||||
|
if self.coder.repo.is_dirty():
|
||||||
|
self.cmd_commit("")
|
||||||
|
|
||||||
abs_file_path = self.coder.abs_root_path(fname)
|
self.io.tool_error(errors)
|
||||||
self.coder.abs_fnames.add(abs_file_path)
|
|
||||||
self.coder.run(errors)
|
|
||||||
|
|
||||||
if linted and self.coder.repo.is_dirty():
|
if not lint_coder:
|
||||||
|
lint_coder = self.coder.clone(
|
||||||
|
# Clear the chat history, fnames
|
||||||
|
cur_messages=[],
|
||||||
|
done_messages=[],
|
||||||
|
fnames=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
lint_coder.add_rel_fname(fname)
|
||||||
|
lint_coder.run(errors)
|
||||||
|
lint_coder.abs_fnames = set()
|
||||||
|
|
||||||
|
if lint_coder and self.coder.repo.is_dirty():
|
||||||
self.cmd_commit("")
|
self.cmd_commit("")
|
||||||
|
|
||||||
def cmd_clear(self, args):
|
def cmd_clear(self, args):
|
||||||
|
|
|
@ -325,7 +325,7 @@ class InputOutput:
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def tool_error(self, message, strip=True):
|
def tool_error(self, message="", strip=True):
|
||||||
self.num_error_outputs += 1
|
self.num_error_outputs += 1
|
||||||
|
|
||||||
if message.strip():
|
if message.strip():
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -13,7 +14,6 @@ from tree_sitter_languages import get_parser # noqa: E402
|
||||||
warnings.simplefilter("ignore", category=FutureWarning)
|
warnings.simplefilter("ignore", category=FutureWarning)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Linter:
|
class Linter:
|
||||||
def __init__(self, encoding="utf-8", root=None):
|
def __init__(self, encoding="utf-8", root=None):
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
@ -22,9 +22,14 @@ class Linter:
|
||||||
self.languages = dict(
|
self.languages = dict(
|
||||||
python=self.py_lint,
|
python=self.py_lint,
|
||||||
)
|
)
|
||||||
|
self.all_lint_cmd = None
|
||||||
|
|
||||||
def set_linter(self, lang, cmd):
|
def set_linter(self, lang, cmd):
|
||||||
self.languages[lang] = cmd
|
if lang:
|
||||||
|
self.languages[lang] = cmd
|
||||||
|
return
|
||||||
|
|
||||||
|
self.all_lint_cmd = cmd
|
||||||
|
|
||||||
def get_rel_fname(self, fname):
|
def get_rel_fname(self, fname):
|
||||||
if self.root:
|
if self.root:
|
||||||
|
@ -66,7 +71,10 @@ class Linter:
|
||||||
lang = filename_to_lang(fname)
|
lang = filename_to_lang(fname)
|
||||||
if not lang:
|
if not lang:
|
||||||
return
|
return
|
||||||
cmd = self.languages.get(lang)
|
if self.all_lint_cmd:
|
||||||
|
cmd = self.all_lint_cmd
|
||||||
|
else:
|
||||||
|
cmd = self.languages.get(lang)
|
||||||
|
|
||||||
if callable(cmd):
|
if callable(cmd):
|
||||||
linkres = cmd(fname, rel_fname, code)
|
linkres = cmd(fname, rel_fname, code)
|
||||||
|
@ -86,7 +94,6 @@ class Linter:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def py_lint(self, fname, rel_fname, code):
|
def py_lint(self, fname, rel_fname, code):
|
||||||
result = ""
|
|
||||||
basic_res = basic_lint(rel_fname, code)
|
basic_res = basic_lint(rel_fname, code)
|
||||||
compile_res = lint_python_compile(fname, code)
|
compile_res = lint_python_compile(fname, code)
|
||||||
|
|
||||||
|
@ -198,12 +205,9 @@ def traverse_tree(node):
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
def find_filenames_and_linenums(text, fnames):
|
def find_filenames_and_linenums(text, fnames):
|
||||||
"""
|
"""
|
||||||
Search text for all occurrences of <filename>:\d+ and make a list of them
|
Search text for all occurrences of <filename>:\\d+ and make a list of them
|
||||||
where <filename> is one of the filenames in the list `fnames`.
|
where <filename> is one of the filenames in the list `fnames`.
|
||||||
"""
|
"""
|
||||||
pattern = re.compile(r"(\b(?:" + "|".join(re.escape(fname) for fname in fnames) + r"):\d+\b)")
|
pattern = re.compile(r"(\b(?:" + "|".join(re.escape(fname) for fname in fnames) + r"):\d+\b)")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -181,14 +182,18 @@ def parse_lint_cmds(lint_cmds, io):
|
||||||
err = False
|
err = False
|
||||||
res = dict()
|
res = dict()
|
||||||
for lint_cmd in lint_cmds:
|
for lint_cmd in lint_cmds:
|
||||||
pieces = lint_cmd.split(":")
|
if re.match(r"^[a-z]+:.*", lint_cmd):
|
||||||
lang = pieces[0]
|
pieces = lint_cmd.split(":")
|
||||||
cmd = lint_cmd[len(lang) + 1 :]
|
lang = pieces[0]
|
||||||
|
cmd = lint_cmd[len(lang) + 1 :]
|
||||||
|
lang = lang.strip()
|
||||||
|
else:
|
||||||
|
lang = None
|
||||||
|
cmd = lint_cmd
|
||||||
|
|
||||||
lang = lang.strip()
|
|
||||||
cmd = cmd.strip()
|
cmd = cmd.strip()
|
||||||
|
|
||||||
if lang and cmd:
|
if cmd:
|
||||||
res[lang] = cmd
|
res[lang] = cmd
|
||||||
else:
|
else:
|
||||||
io.tool_error(f'Unable to parse --lint-cmd "{lint_cmd}"')
|
io.tool_error(f'Unable to parse --lint-cmd "{lint_cmd}"')
|
||||||
|
@ -383,11 +388,11 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.commit:
|
if args.commit:
|
||||||
coder.commands.cmd_commit("")
|
coder.commands.cmd_commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.lint:
|
if args.lint:
|
||||||
coder.commands.cmd_lint("")
|
coder.commands.cmd_lint(fnames=fnames)
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.test:
|
if args.test:
|
||||||
|
|
|
@ -105,7 +105,7 @@ pyproject-hooks==1.1.0
|
||||||
# via
|
# via
|
||||||
# build
|
# build
|
||||||
# pip-tools
|
# pip-tools
|
||||||
pytest==8.2.0
|
pytest==8.2.1
|
||||||
# via -r dev-requirements.in
|
# via -r dev-requirements.in
|
||||||
python-dateutil==2.9.0.post0
|
python-dateutil==2.9.0.post0
|
||||||
# via
|
# via
|
||||||
|
@ -115,7 +115,7 @@ pytz==2024.1
|
||||||
# via pandas
|
# via pandas
|
||||||
pyyaml==6.0.1
|
pyyaml==6.0.1
|
||||||
# via pre-commit
|
# via pre-commit
|
||||||
requests==2.31.0
|
requests==2.32.0
|
||||||
# via sphinx
|
# via sphinx
|
||||||
rich==13.7.1
|
rich==13.7.1
|
||||||
# via typer
|
# via typer
|
||||||
|
|
|
@ -96,7 +96,7 @@ googleapis-common-protos==1.63.0
|
||||||
# grpcio-status
|
# grpcio-status
|
||||||
greenlet==3.0.3
|
greenlet==3.0.3
|
||||||
# via playwright
|
# via playwright
|
||||||
grep-ast==0.3.1
|
grep-ast==0.3.2
|
||||||
# via -r requirements.in
|
# via -r requirements.in
|
||||||
grpcio==1.63.0
|
grpcio==1.63.0
|
||||||
# via
|
# via
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue