From e9e2afe39fcc37dbb9e09fec23991b11d006d183 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 31 Aug 2024 15:51:04 -0700 Subject: [PATCH] refactor: improve pip install error handling and messaging --- aider/utils.py | 5 +++-- aider/versioncheck.py | 20 +++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 858c57649..c44987438 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -206,7 +206,7 @@ def get_pip_install(args): def run_install(cmd): print() - print("Installing: ", " ".join(cmd)) + print("Installing:", shlex.join(cmd)) try: output = [] @@ -332,7 +332,8 @@ def check_pip_install_extra(io, module, prompt, pip_install_cmd): io.tool_error(output) print() - print(f"Failed to install {pip_install_cmd[0]}") + print("Install failed, try running this command manually:") + print(shlex.join(cmd)) if __name__ == "__main__": diff --git a/aider/versioncheck.py b/aider/versioncheck.py index 83221139a..a9ed3142e 100644 --- a/aider/versioncheck.py +++ b/aider/versioncheck.py @@ -92,17 +92,15 @@ Newer aider version v{latest_version} is available. To upgrade, run: io.tool_error(text) return True - cmd = utils.get_pip_install(["--upgrade", "aider-chat"]) + success = utils.check_pip_install_extra( + io, + None, + f"Newer aider version v{latest_version} is available. To upgrade, run:", + ["--upgrade", "aider-chat"], + ) - text = f"Newer aider version v{latest_version} is available. To upgrade, run:" - - io.tool_error(text) - if io.confirm_ask("Run pip install?", subject=shlex.join(cmd)): - success, output = utils.run_install(cmd) - if success: - io.tool_output("Re-run aider to use new version.") - sys.exit() - else: - io.tool_error(output) + if success: + io.tool_output("Re-run aider to use new version.") + sys.exit() return True