@@ -386,29 +386,23 @@ def apply_ruff_formatter(self, code: str) -> str:
386386 return result .stdout .decode (self .encoding )
387387
388388 def apply_ruff_check_and_format (self , code : str ) -> str :
389- """Run ruff check and format in a single pipeline for better performance ."""
389+ """Run ruff check and format sequentially for reliable processing ."""
390390 ruff_path = self ._find_ruff_path ()
391- check_proc = subprocess .Popen ( # noqa: S603
392- [ ruff_path , "check" , "--fix" , "--unsafe-fixes" , "-" ] ,
393- stdin = subprocess . PIPE ,
394- stdout = subprocess . PIPE ,
395- stderr = subprocess . PIPE ,
391+ check_result = subprocess .run ( # noqa: S603
392+ ( ruff_path , "check" , "--fix" , "--unsafe-fixes" , "-" ) ,
393+ input = code . encode ( self . encoding ) ,
394+ capture_output = True ,
395+ check = False ,
396396 cwd = self .settings_path ,
397397 )
398- format_proc = subprocess .Popen ( # noqa: S603
399- [ ruff_path , "format" , "-" ] ,
400- stdin = check_proc .stdout ,
401- stdout = subprocess . PIPE ,
402- stderr = subprocess . PIPE ,
398+ format_result = subprocess .run ( # noqa: S603
399+ ( ruff_path , "format" , "-" ) ,
400+ input = check_result .stdout ,
401+ capture_output = True ,
402+ check = False ,
403403 cwd = self .settings_path ,
404404 )
405- if check_proc .stdout : # pragma: no branch
406- check_proc .stdout .close ()
407- check_proc .stdin .write (code .encode (self .encoding )) # type: ignore[union-attr]
408- check_proc .stdin .close () # type: ignore[union-attr]
409- stdout , _ = format_proc .communicate ()
410- check_proc .wait ()
411- return stdout .decode (self .encoding )
405+ return format_result .stdout .decode (self .encoding )
412406
413407 @staticmethod
414408 def _find_ruff_path () -> str :
0 commit comments