Skip to content

Commit a5d4f3d

Browse files
hugovkradarhere
andauthored
Apply suggestions from code review
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
1 parent b2c4126 commit a5d4f3d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

.github/embed-sbom.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def embed(wheel: Path, sbom: Path) -> None:
3737
for name in contents
3838
if name.endswith(".dist-info/RECORD") and name.count("/") == 1
3939
)
40-
dist_info = record_name.rsplit("/", 1)[0]
40+
dist_info = record_name.split("/", 1)[0]
4141

4242
sbom_bytes = sbom.read_bytes()
4343
sbom_path = f"{dist_info}/sboms/{sbom.name}"
@@ -47,14 +47,12 @@ def embed(wheel: Path, sbom: Path) -> None:
4747
lines.append(record_entry(sbom_path, sbom_bytes))
4848
contents[record_name] = b"\n".join(lines) + b"\n"
4949

50-
tmp = wheel.with_name(wheel.name + ".tmp")
51-
with zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) as zf:
52-
# Re-use each original ZipInfo to preserve timestamps, mode bits and
53-
# compression; only RECORD's contents change.
54-
for info in infos:
55-
zf.writestr(info, contents[info.filename])
56-
zf.writestr(sbom_path, sbom_bytes)
57-
tmp.replace(wheel)
50+
with zipfile.ZipFile(wheel, "w", zipfile.ZIP_DEFLATED) as zf:
51+
# Re-use each original ZipInfo to preserve timestamps, mode bits and
52+
# compression; only RECORD's contents change
53+
for info in infos:
54+
zf.writestr(info, contents[info.filename])
55+
zf.writestr(sbom_path, sbom_bytes)
5856

5957
print(f"Embedded {sbom.name} in {wheel.name}")
6058

0 commit comments

Comments
 (0)