do not try pexpect on windows; fix time.clock error on windows

This commit is contained in:
Paul Gauthier 2024-08-28 22:26:48 -07:00
parent bcb3fa1b47
commit ce397b71e8
4 changed files with 5 additions and 23 deletions

View file

@ -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(

View file

@ -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))

View file

@ -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)

View file

@ -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()