check_version shows output for --just-check-update

This commit is contained in:
Paul Gauthier 2024-07-17 15:19:23 +01:00
parent dadfb464c4
commit cd86354f12

View file

@ -6,13 +6,16 @@ import packaging.version
import aider
from aider import utils
from aider.dump import dump # noqa: F401
def check_version(io, just_check=False):
fname = Path.home() / ".aider" / "caches" / "versioncheck"
day = 60 * 60 * 24
if fname.exists() and time.time() - fname.stat().st_mtime < day:
return
if not just_check and fname.exists():
day = 60 * 60 * 24
since = time.time() - fname.stat().st_mtime
if since < day:
return
# To keep startup fast, avoid importing this unless needed
import requests
@ -23,6 +26,10 @@ def check_version(io, just_check=False):
latest_version = data["info"]["version"]
current_version = aider.__version__
if just_check:
io.tool_output(f"Current version: {current_version}")
io.tool_output(f"Latest version: {latest_version}")
is_update_available = packaging.version.parse(latest_version) > packaging.version.parse(
current_version
)
@ -34,6 +41,10 @@ def check_version(io, just_check=False):
fname.touch()
if just_check:
if is_update_available:
io.tool_output("Update available")
else:
io.tool_output("No update available")
return is_update_available
if not is_update_available: