Merge branch 'main' into litellm-prefill

This commit is contained in:
Paul Gauthier 2024-08-13 05:54:45 -07:00
commit 62fc417655
3 changed files with 19 additions and 5 deletions

View file

@ -416,11 +416,11 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
return main(argv, input, output, right_repo_root, return_coder=return_coder)
if args.just_check_update:
update_available = check_version(io, just_check=True)
update_available = check_version(io, just_check=True, verbose=args.verbose)
return 0 if not update_available else 1
if args.check_update:
check_version(io)
check_version(io, verbose=args.verbose)
if args.models:
models.print_matching_models(io, args.models)

View file

@ -10,12 +10,15 @@ from aider import utils
from aider.dump import dump # noqa: F401
def check_version(io, just_check=False):
def check_version(io, just_check=False, verbose=False):
fname = Path.home() / ".aider" / "caches" / "versioncheck"
if not just_check and fname.exists():
day = 60 * 60 * 24
since = time.time() - fname.stat().st_mtime
if since < day:
if verbose:
hours = since / 60 / 60
io.tool_output(f"Too soon to check version: {hours:.1f} hours")
return
# To keep startup fast, avoid importing this unless needed
@ -27,7 +30,7 @@ def check_version(io, just_check=False):
latest_version = data["info"]["version"]
current_version = aider.__version__
if just_check:
if just_check or verbose:
io.tool_output(f"Current version: {current_version}")
io.tool_output(f"Latest version: {latest_version}")
@ -41,11 +44,13 @@ def check_version(io, just_check=False):
fname.parent.mkdir(parents=True, exist_ok=True)
fname.touch()
if just_check:
if just_check or verbose:
if is_update_available:
io.tool_output("Update available")
else:
io.tool_output("No update available")
if just_check:
return is_update_available
if not is_update_available:

View file

@ -224,6 +224,15 @@ class TestMain(TestCase):
main(["--yes", fname, "--encoding", "iso-8859-15"])
def test_main_exit_calls_version_check(self):
with GitTemporaryDirectory():
with patch("aider.main.check_version") as mock_check_version, patch(
"aider.main.InputOutput"
) as mock_input_output:
main(["--exit"], input=DummyInput(), output=DummyOutput())
mock_check_version.assert_called_once()
mock_input_output.assert_called_once()
@patch("aider.main.InputOutput")
@patch("aider.coders.base_coder.Coder.run")
def test_main_message_adds_to_input_history(self, mock_run, MockInputOutput):