mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 01:04:59 +00:00
fix: lint command with nested spaced strings
This commit is contained in:
parent
f292e01980
commit
acf654c984
3 changed files with 10 additions and 13 deletions
|
@ -11,6 +11,7 @@ from grep_ast import TreeContext, filename_to_lang
|
|||
from tree_sitter_languages import get_parser # noqa: E402
|
||||
|
||||
from aider.dump import dump # noqa: F401
|
||||
from aider.run_cmd import run_cmd_subprocess # noqa: F401
|
||||
|
||||
# tree_sitter is throwing a FutureWarning
|
||||
warnings.simplefilter("ignore", category=FutureWarning)
|
||||
|
@ -44,26 +45,22 @@ class Linter:
|
|||
|
||||
def run_cmd(self, cmd, rel_fname, code):
|
||||
cmd += " " + rel_fname
|
||||
cmd = cmd.split()
|
||||
|
||||
returncode = 0
|
||||
stdout = ""
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
returncode, stdout = run_cmd_subprocess(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
encoding=self.encoding,
|
||||
errors="replace",
|
||||
cwd=self.root,
|
||||
encoding=self.encoding,
|
||||
)
|
||||
except OSError as err:
|
||||
print(f"Unable to execute lint command: {err}")
|
||||
return
|
||||
stdout, _ = process.communicate()
|
||||
errors = stdout
|
||||
if process.returncode == 0:
|
||||
if returncode == 0:
|
||||
return # zero exit status
|
||||
|
||||
cmd = " ".join(cmd)
|
||||
res = f"## Running: {cmd}\n\n"
|
||||
res += errors
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ def get_windows_parent_process_name():
|
|||
return None
|
||||
|
||||
|
||||
def run_cmd_subprocess(command, verbose=False, cwd=None):
|
||||
def run_cmd_subprocess(command, verbose=False, cwd=None, encoding=sys.stdout.encoding):
|
||||
if verbose:
|
||||
print("Using run_cmd_subprocess:", command)
|
||||
|
||||
|
@ -65,7 +65,7 @@ def run_cmd_subprocess(command, verbose=False, cwd=None):
|
|||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
shell=True,
|
||||
encoding=sys.stdout.encoding,
|
||||
encoding=encoding,
|
||||
errors="replace",
|
||||
bufsize=0, # Set bufsize to 0 for unbuffered output
|
||||
universal_newlines=True,
|
||||
|
|
|
@ -30,7 +30,7 @@ class TestLinter(unittest.TestCase):
|
|||
def test_run_cmd(self, mock_popen):
|
||||
mock_process = MagicMock()
|
||||
mock_process.returncode = 0
|
||||
mock_process.communicate.return_value = ("", None)
|
||||
mock_process.stdout.read.side_effect = ("", None)
|
||||
mock_popen.return_value = mock_process
|
||||
|
||||
result = self.linter.run_cmd("test_cmd", "test_file.py", "code")
|
||||
|
@ -40,7 +40,7 @@ class TestLinter(unittest.TestCase):
|
|||
def test_run_cmd_with_errors(self, mock_popen):
|
||||
mock_process = MagicMock()
|
||||
mock_process.returncode = 1
|
||||
mock_process.communicate.return_value = ("Error message", None)
|
||||
mock_process.stdout.read.side_effect = ("Error message", None)
|
||||
mock_popen.return_value = mock_process
|
||||
|
||||
result = self.linter.run_cmd("test_cmd", "test_file.py", "code")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue