From f9c2926c7ae15bd98a0ea3d006f98d3a76a3ab0e Mon Sep 17 00:00:00 2001 From: aseembits93 Date: Fri, 30 May 2025 19:39:18 -0700 Subject: [PATCH 1/4] quick fix --- codeflash/code_utils/env_utils.py | 2 +- codeflash/code_utils/formatter.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index 8bf8a506c..541c03e40 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -22,7 +22,7 @@ def check_formatter_installed(formatter_cmds: list[str], exit_on_failure: bool = f.flush() tmp_file = Path(f.name) try: - format_code(formatter_cmds, tmp_file) + format_code(formatter_cmds, tmp_file, capture_output=False) except Exception: print( "⚠️ Codeflash requires a code formatter to be installed in your environment, but none was found. Please install a supported formatter, verify the formatter-cmds in your codeflash pyproject.toml config and try again." diff --git a/codeflash/code_utils/formatter.py b/codeflash/code_utils/formatter.py index 77d7d6cb8..68a66d5bc 100644 --- a/codeflash/code_utils/formatter.py +++ b/codeflash/code_utils/formatter.py @@ -13,7 +13,7 @@ from pathlib import Path -def format_code(formatter_cmds: list[str], path: Path) -> str: +def format_code(formatter_cmds: list[str], path: Path, capture_output: bool = True) -> str: # noqa # TODO: Only allow a particular whitelist of formatters here to prevent arbitrary code execution formatter_name = formatter_cmds[0].lower() if not path.exists(): @@ -26,7 +26,7 @@ def format_code(formatter_cmds: list[str], path: Path) -> str: formatter_cmd_list = shlex.split(command, posix=os.name != "nt") formatter_cmd_list = [path.as_posix() if chunk == file_token else chunk for chunk in formatter_cmd_list] try: - result = subprocess.run(formatter_cmd_list, capture_output=True, check=False) + result = subprocess.run(formatter_cmd_list, capture_output=capture_output, check=False) if result.returncode == 0: console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}") else: From 1dcc49f88630dc9ecbbd3e438cc051825c73293c Mon Sep 17 00:00:00 2001 From: aseembits93 Date: Fri, 30 May 2025 19:42:02 -0700 Subject: [PATCH 2/4] quick fix --- codeflash/code_utils/formatter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeflash/code_utils/formatter.py b/codeflash/code_utils/formatter.py index 68a66d5bc..bbf088191 100644 --- a/codeflash/code_utils/formatter.py +++ b/codeflash/code_utils/formatter.py @@ -26,8 +26,8 @@ def format_code(formatter_cmds: list[str], path: Path, capture_output: bool = Tr formatter_cmd_list = shlex.split(command, posix=os.name != "nt") formatter_cmd_list = [path.as_posix() if chunk == file_token else chunk for chunk in formatter_cmd_list] try: - result = subprocess.run(formatter_cmd_list, capture_output=capture_output, check=False) - if result.returncode == 0: + result = subprocess.run(formatter_cmd_list, capture_output=True, check=False) + if result.returncode == 0 and capture_output: console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}") else: logger.error(f"Failed to format code with {' '.join(formatter_cmd_list)}") From 4c751169fd7a10585a42647c3addd20bc487a93b Mon Sep 17 00:00:00 2001 From: aseembits93 Date: Fri, 30 May 2025 19:43:09 -0700 Subject: [PATCH 3/4] quick fix --- codeflash/code_utils/formatter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codeflash/code_utils/formatter.py b/codeflash/code_utils/formatter.py index bbf088191..beaa395f1 100644 --- a/codeflash/code_utils/formatter.py +++ b/codeflash/code_utils/formatter.py @@ -27,8 +27,9 @@ def format_code(formatter_cmds: list[str], path: Path, capture_output: bool = Tr formatter_cmd_list = [path.as_posix() if chunk == file_token else chunk for chunk in formatter_cmd_list] try: result = subprocess.run(formatter_cmd_list, capture_output=True, check=False) - if result.returncode == 0 and capture_output: - console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}") + if result.returncode == 0: + if capture_output: + console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}") else: logger.error(f"Failed to format code with {' '.join(formatter_cmd_list)}") except FileNotFoundError as e: From 9ab37a7b178b0d8a92ce633d5befc00719cd41e9 Mon Sep 17 00:00:00 2001 From: Aseem Saxena Date: Fri, 30 May 2025 20:39:53 -0700 Subject: [PATCH 4/4] fixed --- codeflash/code_utils/env_utils.py | 2 +- codeflash/code_utils/formatter.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index 541c03e40..26528439b 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -22,7 +22,7 @@ def check_formatter_installed(formatter_cmds: list[str], exit_on_failure: bool = f.flush() tmp_file = Path(f.name) try: - format_code(formatter_cmds, tmp_file, capture_output=False) + format_code(formatter_cmds, tmp_file, print_status=False) except Exception: print( "⚠️ Codeflash requires a code formatter to be installed in your environment, but none was found. Please install a supported formatter, verify the formatter-cmds in your codeflash pyproject.toml config and try again." diff --git a/codeflash/code_utils/formatter.py b/codeflash/code_utils/formatter.py index beaa395f1..927a4d4cb 100644 --- a/codeflash/code_utils/formatter.py +++ b/codeflash/code_utils/formatter.py @@ -13,7 +13,7 @@ from pathlib import Path -def format_code(formatter_cmds: list[str], path: Path, capture_output: bool = True) -> str: # noqa +def format_code(formatter_cmds: list[str], path: Path, print_status: bool = True) -> str: # noqa # TODO: Only allow a particular whitelist of formatters here to prevent arbitrary code execution formatter_name = formatter_cmds[0].lower() if not path.exists(): @@ -28,7 +28,7 @@ def format_code(formatter_cmds: list[str], path: Path, capture_output: bool = Tr try: result = subprocess.run(formatter_cmd_list, capture_output=True, check=False) if result.returncode == 0: - if capture_output: + if print_status: console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}") else: logger.error(f"Failed to format code with {' '.join(formatter_cmd_list)}")