Skip to content
Closed
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
4 changes: 4 additions & 0 deletions weco/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@

# API timeout configuration (connect_timeout, read_timeout) in seconds
DEFAULT_API_TIMEOUT = (10, 800)

# Default max lines and chars for output truncation
DEFAULT_MAX_LINES = 50
DEFAULT_MAX_CHARS = 2500
22 changes: 15 additions & 7 deletions weco/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pathlib
import requests
from packaging.version import parse as parse_version
from .constants import DEFAULT_MAX_LINES, DEFAULT_MAX_CHARS


# Env/arg helper functions
Expand Down Expand Up @@ -124,10 +125,6 @@ def smooth_update(


# Other helper functions
DEFAULT_MAX_LINES = 50
DEFAULT_MAX_CHARS = 5000


def truncate_output(output: str, max_lines: int = DEFAULT_MAX_LINES, max_chars: int = DEFAULT_MAX_CHARS) -> str:
"""Truncate the output to a reasonable size."""
lines = output.splitlines()
Expand All @@ -137,10 +134,21 @@ def truncate_output(output: str, max_lines: int = DEFAULT_MAX_LINES, max_chars:
chars_truncated = len(output) > max_chars

# Apply truncations to the original output
if lines_truncated:
# When both limits apply, use the one that results in smaller output
if lines_truncated and chars_truncated:
lines_output = "\n".join(lines[-max_lines:])
chars_output = output[-max_chars:]

# Use whichever produces smaller result
if len(lines_output) <= len(chars_output):
output = lines_output
chars_truncated = False # Only show line truncation message
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting flags to False to control message display creates confusing logic. Consider using a separate variable to track which truncation method was applied instead of modifying the original detection flags.

Copilot uses AI. Check for mistakes.
else:
output = chars_output
lines_truncated = False # Only show char truncation message
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting flags to False to control message display creates confusing logic. Consider using a separate variable to track which truncation method was applied instead of modifying the original detection flags.

Copilot uses AI. Check for mistakes.
elif lines_truncated:
output = "\n".join(lines[-max_lines:])

if chars_truncated:
elif chars_truncated:
output = output[-max_chars:]

# Add prefixes for truncations that were applied
Expand Down