Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codeflash/code_utils/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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."
Expand Down
5 changes: 3 additions & 2 deletions codeflash/code_utils/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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():
Expand All @@ -28,7 +28,8 @@ def format_code(formatter_cmds: list[str], path: Path) -> str:
try:
result = subprocess.run(formatter_cmd_list, capture_output=True, check=False)
if result.returncode == 0:
console.rule(f"Formatted Successfully with: {formatter_name.replace('$file', path.name)}")
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)}")
except FileNotFoundError as e:
Expand Down
Loading