From b44141f1790b5cc82c6900a944b3cc62311823b5 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 27 Aug 2024 05:47:02 -0700 Subject: [PATCH] add --install-main-branch --- aider/main.py | 4 +--- aider/utils.py | 18 ++++++++++++------ aider/versioncheck.py | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/aider/main.py b/aider/main.py index 3959a6bab..5bda6c520 100644 --- a/aider/main.py +++ b/aider/main.py @@ -17,7 +17,7 @@ from aider.history import ChatSummary from aider.io import InputOutput from aider.llm import litellm # noqa: F401; properly init litellm on launch from aider.repo import GitRepo -from aider.versioncheck import check_version +from aider.versioncheck import check_version, install_from_main_branch from .dump import dump # noqa: F401 @@ -431,8 +431,6 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F return 0 if not update_available else 1 if args.install_main_branch: - from aider.versioncheck import install_from_main_branch - success = install_from_main_branch(io) return 0 if success else 1 diff --git a/aider/utils.py b/aider/utils.py index 3647e0aac..ce520552c 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -280,6 +280,7 @@ def find_common_root(abs_fnames): else: return safe_abs_path(os.getcwd()) + def format_tokens(count): if count < 1000: return f"{count}" @@ -290,20 +291,25 @@ def format_tokens(count): def check_pip_install_extra(io, module, prompt, pip_install_cmd): - try: - __import__(module) - return True - except (ImportError, ModuleNotFoundError): - pass + if module: + try: + __import__(module) + return True + except (ImportError, ModuleNotFoundError): + pass cmd = get_pip_install(pip_install_cmd) - io.tool_error(prompt) + if prompt: + io.tool_error(prompt) + if not io.confirm_ask("Run pip install?", default="y", subject=" ".join(cmd)): return success, output = run_install(cmd) if success: + if not module: + return try: __import__(module) return True diff --git a/aider/versioncheck.py b/aider/versioncheck.py index 38c91c20c..e83732c69 100644 --- a/aider/versioncheck.py +++ b/aider/versioncheck.py @@ -16,8 +16,8 @@ def install_from_main_branch(io): """ return utils.check_pip_install_extra( io, - "aider", - "Installing the latest version from the main branch...", + None, + "Install the development version of aider from the main branch?", ["--upgrade", "git+https://github.com/paul-gauthier/aider.git"], )