Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions aider/versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
VERSION_CHECK_FNAME = Path.home() / ".aider" / "caches" / "versioncheck"


def _touch_version_check_file(io=None, verbose=False):
try:
VERSION_CHECK_FNAME.parent.mkdir(parents=True, exist_ok=True)
VERSION_CHECK_FNAME.touch()
except OSError as err:
if verbose and io:
io.tool_warning(f"Unable to write version check cache: {err}")


def install_from_main_branch(io):
"""
Install the latest version of aider from the main branch of the GitHub repository.
Expand Down Expand Up @@ -84,15 +93,14 @@ def check_version(io, just_check=False, verbose=False):
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
)
is_update_available = packaging.version.parse(
latest_version
) > packaging.version.parse(current_version)
except Exception as err:
io.tool_error(f"Error checking pypi for new version: {err}")
return False
finally:
VERSION_CHECK_FNAME.parent.mkdir(parents=True, exist_ok=True)
VERSION_CHECK_FNAME.touch()
_touch_version_check_file(io, verbose)

###
# is_update_available = True
Expand Down
19 changes: 19 additions & 0 deletions tests/basic/test_versioncheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from unittest.mock import Mock, patch

from aider import versioncheck


def test_check_version_ignores_unwritable_cache_path(tmp_path, monkeypatch):
blocked_parent = tmp_path / "blocked"
blocked_parent.write_text("", encoding="utf-8")
monkeypatch.setattr(
versioncheck, "VERSION_CHECK_FNAME", blocked_parent / "versioncheck"
)

io = Mock()
with patch("requests.get", side_effect=RuntimeError("offline")):
assert versioncheck.check_version(io) is False

io.tool_error.assert_called_once_with(
"Error checking pypi for new version: offline"
)