mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 10:45:00 +00:00
fix: Implement portable way to run interactive subprocesses
This commit is contained in:
parent
15ebdcc45c
commit
4917054518
1 changed files with 14 additions and 11 deletions
|
@ -13,6 +13,8 @@ from .base_coder import Coder
|
||||||
from .editblock_prompts import EditBlockPrompts
|
from .editblock_prompts import EditBlockPrompts
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
class EditBlockCoder(Coder):
|
class EditBlockCoder(Coder):
|
||||||
"""A coder that uses search/replace blocks for code modifications."""
|
"""A coder that uses search/replace blocks for code modifications."""
|
||||||
|
|
||||||
|
@ -27,6 +29,15 @@ class EditBlockCoder(Coder):
|
||||||
|
|
||||||
return edits
|
return edits
|
||||||
|
|
||||||
|
def run_interactive_subprocess(self, command):
|
||||||
|
if os.name == 'posix': # Unix-like systems (Linux, macOS)
|
||||||
|
import pty
|
||||||
|
return pty.spawn(command)
|
||||||
|
elif os.name == 'nt': # Windows
|
||||||
|
return subprocess.run(command, shell=True)
|
||||||
|
else:
|
||||||
|
raise OSError("Unsupported operating system")
|
||||||
|
|
||||||
def apply_edits(self, edits):
|
def apply_edits(self, edits):
|
||||||
failed = []
|
failed = []
|
||||||
passed = []
|
passed = []
|
||||||
|
@ -39,17 +50,9 @@ class EditBlockCoder(Coder):
|
||||||
self.io.tool_output(f"{edit.strip()}", bold=True)
|
self.io.tool_output(f"{edit.strip()}", bold=True)
|
||||||
if self.io.confirm_ask("Do you want to run this suggested shell command?"):
|
if self.io.confirm_ask("Do you want to run this suggested shell command?"):
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
self.run_interactive_subprocess(edit.split())
|
||||||
edit,
|
except Exception as e:
|
||||||
shell=True,
|
self.io.tool_error(str(e))
|
||||||
text=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
stdin=subprocess.DEVNULL,
|
|
||||||
)
|
|
||||||
self.io.tool_output(result.stdout)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
self.io.tool_error(e.output)
|
|
||||||
else:
|
else:
|
||||||
path, original, updated = edit
|
path, original, updated = edit
|
||||||
full_path = self.abs_root_path(path)
|
full_path = self.abs_root_path(path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue