Skip to content

Commit

Permalink
src/installer/utils.py: sort entries before writing out RECORD file
Browse files Browse the repository at this point in the history
This helps build reproducibility by ensuring the RECORD file
is the same regardless of the order of the input files.
  • Loading branch information
Alexander Kanavin committed Oct 15, 2024
1 parent 05c87b2 commit 32210b1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/installer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def construct_record_file(
io.BytesIO(), encoding="utf-8", write_through=True, newline=""
)
writer = csv.writer(stream, delimiter=",", quotechar='"', lineterminator="\n")
for scheme, record in records:
for scheme, record in sorted(records, key=lambda x: x[1].path):
writer.writerow(record.to_row(prefix_for_scheme(scheme)))
stream.seek(0)
return stream.detach()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ def test_finalize_write_record(self, destination):
data = f.read()

assert data == (
b"RECORD,,\n"
b"../data/my_data1.bin,sha256=NV0A-M4OPuqTsHjeD6Wth_-UqrpAAAdyplcustFZ8s4,9\n"
b"../data/my_data2.bin,sha256=lP7V8oWLqgyXCbdASNiPdsUogzPUZhht_7F8T5bC3eQ,9\n"
b'"../data/my_data3,my_data4.bin",sha256=18krruu1gr01x-WM_9ChSASoHv0mfRAV6-B2bd9sxpo,9\n'
b"../scripts/my_entrypoint,sha256=_p_9nwmeIeoMBfQ0akhr1KbKn3laDydg0J7cy0Fs6JI,216\n"
b"../scripts/my_script,sha256=M60fWvUSMJkPtw2apUvjWWwOcnRPcVy_zO4-4lpH08o,9\n"
b"../scripts/my_script2,sha256=k9_997kTbTYQm7EXFLclVZL1m2N98rU90QX46XeMvjY,22\n"
b"../scripts/my_entrypoint,sha256=_p_9nwmeIeoMBfQ0akhr1KbKn3laDydg0J7cy0Fs6JI,216\n"
b"RECORD,,\n"
)

0 comments on commit 32210b1

Please sign in to comment.