Skip to content

Commit a352374

Browse files
committed
fix: reduce exec output size
1 parent fe105d6 commit a352374

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

weco/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55

66
# API timeout configuration (connect_timeout, read_timeout) in seconds
77
DEFAULT_API_TIMEOUT = (10, 800)
8+
9+
# Default max lines and chars for output truncation
10+
DEFAULT_MAX_LINES = 50
11+
DEFAULT_MAX_CHARS = 2500

weco/utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pathlib
1010
import requests
1111
from packaging.version import parse as parse_version
12+
from .constants import DEFAULT_MAX_LINES, DEFAULT_MAX_CHARS
1213

1314

1415
# Env/arg helper functions
@@ -124,10 +125,6 @@ def smooth_update(
124125

125126

126127
# Other helper functions
127-
DEFAULT_MAX_LINES = 50
128-
DEFAULT_MAX_CHARS = 5000
129-
130-
131128
def truncate_output(output: str, max_lines: int = DEFAULT_MAX_LINES, max_chars: int = DEFAULT_MAX_CHARS) -> str:
132129
"""Truncate the output to a reasonable size."""
133130
lines = output.splitlines()
@@ -137,10 +134,21 @@ def truncate_output(output: str, max_lines: int = DEFAULT_MAX_LINES, max_chars:
137134
chars_truncated = len(output) > max_chars
138135

139136
# Apply truncations to the original output
140-
if lines_truncated:
137+
# When both limits apply, use the one that results in smaller output
138+
if lines_truncated and chars_truncated:
139+
lines_output = "\n".join(lines[-max_lines:])
140+
chars_output = output[-max_chars:]
141+
142+
# Use whichever produces smaller result
143+
if len(lines_output) <= len(chars_output):
144+
output = lines_output
145+
chars_truncated = False # Only show line truncation message
146+
else:
147+
output = chars_output
148+
lines_truncated = False # Only show char truncation message
149+
elif lines_truncated:
141150
output = "\n".join(lines[-max_lines:])
142-
143-
if chars_truncated:
151+
elif chars_truncated:
144152
output = output[-max_chars:]
145153

146154
# Add prefixes for truncations that were applied

0 commit comments

Comments
 (0)