From ce397b71e8d4efdbef469d9190591c06305c10fc Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 28 Aug 2024 22:26:48 -0700 Subject: [PATCH] do not try pexpect on windows; fix time.clock error on windows --- aider/io.py | 3 +-- aider/repomap.py | 3 +-- aider/run_cmd.py | 6 +++--- tests/basic/test_run_cmd.py | 16 ---------------- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/aider/io.py b/aider/io.py index 37b1e13fe..2942e047e 100644 --- a/aider/io.py +++ b/aider/io.py @@ -15,7 +15,6 @@ from prompt_toolkit.shortcuts import CompleteStyle, PromptSession from prompt_toolkit.styles import Style from pygments.lexers import MarkdownLexer, guess_lexer_for_filename from pygments.token import Token -from pygments.util import ClassNotFound from rich.console import Console from rich.style import Style as RichStyle from rich.text import Text @@ -83,7 +82,7 @@ class AutoCompleter(Completer): continue try: lexer = guess_lexer_for_filename(fname, content) - except ClassNotFound: + except Exception: # On Windows, bad ref to time.clock which is deprecated continue tokens = list(lexer.get_tokens(content)) self.words.update( diff --git a/aider/repomap.py b/aider/repomap.py index 40c4d055f..d04f2a11b 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -14,7 +14,6 @@ from diskcache import Cache from grep_ast import TreeContext, filename_to_lang from pygments.lexers import guess_lexer_for_filename from pygments.token import Token -from pygments.util import ClassNotFound from tqdm import tqdm from aider.dump import dump @@ -253,7 +252,7 @@ class RepoMap: try: lexer = guess_lexer_for_filename(fname, code) - except ClassNotFound: + except Exception: # On Windows, bad ref to time.clock which is deprecated return tokens = list(lexer.get_tokens(code)) diff --git a/aider/run_cmd.py b/aider/run_cmd.py index 72c8c6287..003727ea1 100644 --- a/aider/run_cmd.py +++ b/aider/run_cmd.py @@ -3,6 +3,8 @@ import subprocess import sys from io import BytesIO +import pexpect + def run_cmd(command): import sys @@ -10,9 +12,7 @@ def run_cmd(command): if not sys.stdin.isatty(): return run_cmd_subprocess(command) - try: - import pexpect # noqa: F401 - except ImportError: + if hasattr(pexpect, "spawn"): return run_cmd_subprocess(command) return run_cmd_pexpect(command) diff --git a/tests/basic/test_run_cmd.py b/tests/basic/test_run_cmd.py index f2b574c1c..f42094e07 100644 --- a/tests/basic/test_run_cmd.py +++ b/tests/basic/test_run_cmd.py @@ -9,19 +9,3 @@ def test_run_cmd_echo(): assert exit_code == 0 assert output.strip() == "Hello, World!" - - -def test_run_cmd_echo_with_quotes(): - command = 'echo "Hello, World!"' - exit_code, output = run_cmd(command) - - assert exit_code == 0 - assert output.strip() == "Hello, World!" - - -def test_run_cmd_invalid_command(): - command = "invalid_command_that_does_not_exist" - exit_code, output = run_cmd(command) - - assert exit_code != 0 - assert "command not found" in output.lower() or "is not recognized" in output.lower()