Skip to content

Commit f791867

Browse files
committed
fix: Add package prefix to uv output
Most log output uses the package name as a prefix (via FromagerLogRecord) so it is possible to tell which package is being processed when a message is logged. This was not true when dumping the output of UV and other external commands to the log, where the entire multi-line output was logged in a single call. This fix logs each line of output separately so the package name prefix is applied to every line, making it much easier to identify which package is being processed, especially when building multiple packages in parallel or when reviewing logs. Changes: - Log command output line-by-line instead of as a single block - Skip empty lines to keep logs cleaner - Apply same pattern to both error and debug output - Update mock test to provide stdout for proper testing Fixes: #753 Co-authored-by: Claude <claude@anthropic.com> Signed-off-by: Ioannis Angelakopoulos <iangelak@redhat.com>
1 parent a098d3c commit f791867

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/fromager/external_commands.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ def run(
9999
)
100100
output = completed.stdout.decode("utf-8") if completed.stdout else ""
101101
if completed.returncode != 0:
102-
logger.error("%s failed with %s", cmd, output)
102+
# Log the command failure first
103+
logger.error(
104+
"command failed with exit code %d: %s",
105+
completed.returncode,
106+
" ".join(shlex.quote(str(s)) for s in cmd),
107+
)
108+
# Then log each line of output separately so package name prefix is applied
109+
for line in output.splitlines():
110+
if line.strip(): # Skip empty lines
111+
logger.error(line)
112+
103113
err_type = subprocess.CalledProcessError
104114
if network_isolation:
105115
# Look for a few common messages that mean there is a network
@@ -113,5 +123,10 @@ def run(
113123
if substr in output:
114124
err_type = NetworkIsolationError
115125
raise err_type(completed.returncode, cmd, output)
116-
logger.debug("output: %s", output)
126+
127+
# Log each line of output separately for successful commands too
128+
for line in output.splitlines():
129+
if line.strip(): # Skip empty lines
130+
logger.debug(line)
131+
117132
return output

tests/test_external_commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def test_external_commands_log_file(tmp_path):
2929
assert "test\n" == file_contents
3030

3131

32-
@mock.patch("subprocess.run", return_value=mock.Mock(returncode=0))
32+
@mock.patch(
33+
"subprocess.run",
34+
return_value=mock.Mock(returncode=0, stdout=b"test output\n"),
35+
)
3336
@mock.patch(
3437
"fromager.external_commands.network_isolation_cmd",
3538
return_value=["/bin/unshare", "--net", "--map-current-user"],

0 commit comments

Comments
 (0)