Skip to content

Commit

Permalink
fix: lint command with nested spaced strings
Browse files Browse the repository at this point in the history
  • Loading branch information
aweis89 committed Jan 2, 2025
1 parent f292e01 commit a7ea1b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions aider/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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)
Expand Down Expand Up @@ -44,26 +45,21 @@ def get_rel_fname(self, fname):

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

Expand Down
4 changes: 2 additions & 2 deletions aider/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down

0 comments on commit a7ea1b2

Please sign in to comment.