Skip to content

Commit bf1d21e

Browse files
mprpicclaude
authored andcommitted
feat: log existing SBOM files found in wheels
Log any existing SBOM files in .dist-info/sboms/ at INFO level during wheel metadata injection. This provides visibility into upstream SBOMs (e.g. from maturin) before Fromager generates its own. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Martin Prpič <mprpic@redhat.com>
1 parent dc9de54 commit bf1d21e

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/fromager/wheels.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@
4444
FROMAGER_BUILD_REQ_PREFIX = "fromager"
4545

4646

47+
def _log_existing_sboms(
48+
req: Requirement,
49+
dist_info_dir: pathlib.Path,
50+
) -> None:
51+
"""Log any existing SBOM files found in the wheel's .dist-info/sboms/ directory."""
52+
sboms_dir = dist_info_dir / "sboms"
53+
if not sboms_dir.is_dir():
54+
return
55+
sbom_files = sorted(sboms_dir.iterdir())
56+
if sbom_files:
57+
names = [f.name for f in sbom_files]
58+
logger.info(
59+
"%s: found existing SBOM files in wheel: %s",
60+
req.name,
61+
", ".join(names),
62+
)
63+
64+
4765
def _extra_metadata_elfdeps(
4866
ctx: context.WorkContext,
4967
req: Requirement,
@@ -182,6 +200,8 @@ def add_extra_metadata_to_wheels(
182200
if not dist_info_dir.is_dir():
183201
raise ValueError(f"{wheel_file} does not contain {dist_info_dir.name}")
184202

203+
_log_existing_sboms(req, dist_info_dir)
204+
185205
data_to_add = overrides.find_and_invoke(
186206
req.name,
187207
"add_extra_metadata_to_wheels",

tests/test_wheels.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,40 @@ def test_add_extra_metadata_allows_legitimate_double_dots(
110110
mock_run.assert_called_once()
111111

112112

113+
def test_log_existing_sboms_when_present(
114+
tmp_path: pathlib.Path, caplog: pytest.LogCaptureFixture
115+
) -> None:
116+
"""Verify that existing SBOM files in .dist-info/sboms/ are logged."""
117+
req = Requirement("test_pkg==1.0.0")
118+
dist_info_dir = tmp_path / "test_pkg-1.0.0.dist-info"
119+
dist_info_dir.mkdir()
120+
sboms_dir = dist_info_dir / "sboms"
121+
sboms_dir.mkdir()
122+
(sboms_dir / "cyclonedx.json").write_text("{}")
123+
(sboms_dir / "other.spdx.json").write_text("{}")
124+
125+
with caplog.at_level("INFO", logger="fromager.wheels"):
126+
wheels._log_existing_sboms(req, dist_info_dir)
127+
128+
assert "found existing SBOM files in wheel" in caplog.text
129+
assert "cyclonedx.json" in caplog.text
130+
assert "other.spdx.json" in caplog.text
131+
132+
133+
def test_log_existing_sboms_when_absent(
134+
tmp_path: pathlib.Path, caplog: pytest.LogCaptureFixture
135+
) -> None:
136+
"""Verify no log output when .dist-info/sboms/ does not exist."""
137+
req = Requirement("test_pkg==1.0.0")
138+
dist_info_dir = tmp_path / "test_pkg-1.0.0.dist-info"
139+
dist_info_dir.mkdir()
140+
141+
with caplog.at_level("INFO", logger="fromager.wheels"):
142+
wheels._log_existing_sboms(req, dist_info_dir)
143+
144+
assert "SBOM" not in caplog.text
145+
146+
113147
def test_download_wheel_unquotes_url_encoded_filenames(tmp_path: pathlib.Path) -> None:
114148
"""Test that download_wheel properly unquotes URL-encoded characters in filenames."""
115149
req = Requirement("test_pkg")

0 commit comments

Comments
 (0)