diff --git a/aider/utils.py b/aider/utils.py index 828e708b0..34bd73d21 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -302,7 +302,7 @@ def touch_file(fname): return False -def check_pip_install_extra(io, module, prompt, pip_install_cmd): +def check_pip_install_extra(io, module, prompt, pip_install_cmd, self_update=False): if module: try: __import__(module) @@ -315,6 +315,11 @@ def check_pip_install_extra(io, module, prompt, pip_install_cmd): if prompt: io.tool_error(prompt) + if self_update and platform.system() == "Windows": + io.tool_output("Run this command to update:") + io.tool_output(printable_shell_command(cmd)) + return + if not io.confirm_ask("Run pip install?", default="y", subject=printable_shell_command(cmd)): return diff --git a/aider/versioncheck.py b/aider/versioncheck.py index 86c5e9b45..d4fcbd484 100644 --- a/aider/versioncheck.py +++ b/aider/versioncheck.py @@ -22,20 +22,44 @@ def install_from_main_branch(io): None, "Install the development version of aider from the main branch?", ["--upgrade", "git+https://github.com/paul-gauthier/aider.git"], + self_update=True, ) -def install_upgrade(io): +def install_upgrade(io, latest_version=None): """ Install the latest version of aider from PyPI. """ - return utils.check_pip_install_extra( + + if latest_version: + new_ver_text = f"Newer aider version v{latest_version} is available." + else: + new_ver_text = f"Install latest version of aider from PyPI?" + + docker_image = os.environ.get("AIDER_DOCKER_IMAGE") + if docker_image: + text = f""" +{new_ver_text} To upgrade, run: + + docker pull {docker_image} +""" + io.tool_error(text) + return True + + success = utils.check_pip_install_extra( io, None, - "Install the latest version of aider from PyPI?", + new_ver_text, ["--upgrade", "aider-chat"], + self_update=True, ) + if success: + io.tool_output("Re-run aider to use new version.") + sys.exit() + + return + def check_version(io, just_check=False, verbose=False): if not just_check and VERSION_CHECK_FNAME.exists(): @@ -85,25 +109,5 @@ def check_version(io, just_check=False, verbose=False): if not is_update_available: return False - docker_image = os.environ.get("AIDER_DOCKER_IMAGE") - if docker_image: - text = f""" -Newer aider version v{latest_version} is available. To upgrade, run: - - docker pull {docker_image} -""" - io.tool_error(text) - return True - - success = utils.check_pip_install_extra( - io, - None, - f"Newer aider version v{latest_version} is available.", - ["--upgrade", "aider-chat"], - ) - - if success: - io.tool_output("Re-run aider to use new version.") - sys.exit() - + install_upgrade(io, latest_version) return True