Skip to content

Commit e3a93f3

Browse files
authored
feat(whlmaker): introduce an internal _WhlFile class and stop sorting RECORD (bazel-contrib#1488)
This class is for being able to more easily recreate a wheel file after extracting it. This is not intended for usage outside the rules_python project. Also stop sorting the entries when writing a RECORD file making the order of the RECORD file to be the same as the order the files to the zip file are added. Towards bazel-contrib#1076
1 parent 915d7a0 commit e3a93f3

File tree

3 files changed

+153
-121
lines changed

3 files changed

+153
-121
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ A brief description of the categories of changes:
3131
* Skip aliases for unloaded toolchains. Some Python versions that don't have full
3232
platform support, and referencing their undefined repositories can break operations
3333
like `bazel query rdeps(...)`.
34+
3435
* Python code generated from `proto_library` with `strip_import_prefix` can be imported now.
3536

37+
* (py_wheel) Produce deterministic wheel files and make `RECORD` file entries
38+
follow the order of files written to the `.whl` archive.
39+
3640
## [0.26.0] - 2023-10-06
3741

3842
### Changed
@@ -106,8 +110,6 @@ A brief description of the categories of changes:
106110

107111
* (gazelle) Improve runfiles lookup hermeticity.
108112

109-
* (py_wheel) Produce deterministic wheel files
110-
111113
## [0.25.0] - 2023-08-22
112114

113115
### Changed

examples/wheel/wheel_test.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ def _get_path(self, filename):
4444
else:
4545
return path
4646

47-
def assertFileSha256Equal(self, filename, sha):
47+
def assertFileSha256Equal(self, filename, want):
4848
hash = hashlib.sha256()
4949
with open(filename, "rb") as f:
5050
while True:
5151
buf = f.read(2**20)
5252
if not buf:
5353
break
5454
hash.update(buf)
55-
self.assertEqual(hash.hexdigest(), sha)
55+
self.assertEqual(want, hash.hexdigest())
5656

5757
def assertAllEntriesHasReproducibleMetadata(self, zf):
5858
for zinfo in zf.infolist():
@@ -78,7 +78,7 @@ def test_py_library_wheel(self):
7878
],
7979
)
8080
self.assertFileSha256Equal(
81-
filename, "6da8e06a3fdd9ae5ee9fa8f796610723c05a4b0d7fde0ec5179401e956204139"
81+
filename, "2818e70fdebd148934f41820f8c54d5d7676d783c0d66c7c8af2ee9141e7ddc7"
8282
)
8383

8484
def test_py_package_wheel(self):
@@ -100,7 +100,7 @@ def test_py_package_wheel(self):
100100
],
101101
)
102102
self.assertFileSha256Equal(
103-
filename, "2948b0b5e0aa421e0b40f78b74018bbc2f218165f211da0a4609e431e8e52bee"
103+
filename, "273e27adf9bf90287a42ac911dcece8aa95f2905c37d786725477b26de23627c"
104104
)
105105

106106
def test_customized_wheel(self):
@@ -135,16 +135,16 @@ def test_customized_wheel(self):
135135
record_contents,
136136
# The entries are guaranteed to be sorted.
137137
b"""\
138-
example_customized-0.0.1.dist-info/METADATA,sha256=QYQcDJFQSIqan8eiXqL67bqsUfgEAwf2hoK_Lgi1S-0,559
139-
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
140-
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
141-
example_customized-0.0.1.dist-info/RECORD,,
142-
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
143-
example_customized-0.0.1.dist-info/entry_points.txt,sha256=pqzpbQ8MMorrJ3Jp0ntmpZcuvfByyqzMXXi2UujuXD0,137
144138
examples/wheel/lib/data.txt,sha256=9vJKEdfLu8bZRArKLroPZJh1XKkK3qFMXiM79MBL2Sg,12
145139
examples/wheel/lib/module_with_data.py,sha256=8s0Khhcqz3yVsBKv2IB5u4l4TMKh7-c_V6p65WVHPms,637
146140
examples/wheel/lib/simple_module.py,sha256=z2hwciab_XPNIBNH8B1Q5fYgnJvQTeYf0ZQJpY8yLLY,637
147141
examples/wheel/main.py,sha256=sgg5iWN_9inYBjm6_Zw27hYdmo-l24fA-2rfphT-IlY,909
142+
example_customized-0.0.1.dist-info/WHEEL,sha256=sobxWSyDDkdg_rinUth-jxhXHqoNqlmNMJY3aTZn2Us,91
143+
example_customized-0.0.1.dist-info/METADATA,sha256=QYQcDJFQSIqan8eiXqL67bqsUfgEAwf2hoK_Lgi1S-0,559
144+
example_customized-0.0.1.dist-info/entry_points.txt,sha256=pqzpbQ8MMorrJ3Jp0ntmpZcuvfByyqzMXXi2UujuXD0,137
145+
example_customized-0.0.1.dist-info/NOTICE,sha256=Xpdw-FXET1IRgZ_wTkx1YQfo1-alET0FVf6V1LXO4js,76
146+
example_customized-0.0.1.dist-info/README,sha256=WmOFwZ3Jga1bHG3JiGRsUheb4UbLffUxyTdHczS27-o,40
147+
example_customized-0.0.1.dist-info/RECORD,,
148148
""",
149149
)
150150
self.assertEqual(
@@ -189,7 +189,7 @@ def test_customized_wheel(self):
189189
second = second.main:s""",
190190
)
191191
self.assertFileSha256Equal(
192-
filename, "66f0c1bfe2cedb2f4cf08d4fe955096860186c0a2f3524e0cb02387a55ac3e63"
192+
filename, "48eed93258bba0bb366c879b77917d947267d89e7e60005d1766d844fb909118"
193193
)
194194

195195
def test_legacy_filename_escaping(self):
@@ -227,7 +227,7 @@ def test_legacy_filename_escaping(self):
227227
""",
228228
)
229229
self.assertFileSha256Equal(
230-
filename, "593c6ab58627f2446d0f1ef2956fd6d42104eedce4493c72d462f7ebf8cb74fa"
230+
filename, "ace5fab6458f8c3b4b50801b8e8214288bba786472e81547fced743a67531312"
231231
)
232232

233233
def test_filename_escaping(self):
@@ -293,7 +293,7 @@ def test_custom_package_root_wheel(self):
293293
for line in record_contents.splitlines():
294294
self.assertFalse(line.startswith("/"))
295295
self.assertFileSha256Equal(
296-
filename, "1b1fa3a4e840211084ef80049d07947b845c99bedb2778496d30e0c1524686ac"
296+
filename, "16e0345c102c6866fed34999d8de5aed7f351adbf372b27adef3bc15161db65e"
297297
)
298298

299299
def test_custom_package_root_multi_prefix_wheel(self):
@@ -324,7 +324,7 @@ def test_custom_package_root_multi_prefix_wheel(self):
324324
for line in record_contents.splitlines():
325325
self.assertFalse(line.startswith("/"))
326326
self.assertFileSha256Equal(
327-
filename, "f0422d7a338de3c76bf2525927fd93c0f47f2e9c60ecc0944e3e32b642c28137"
327+
filename, "d2031eb21c69e290db5eac76b0dc026858e9dbdb3da2dc0314e4e9f69eab2e1a"
328328
)
329329

330330
def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
@@ -355,7 +355,7 @@ def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
355355
for line in record_contents.splitlines():
356356
self.assertFalse(line.startswith("/"))
357357
self.assertFileSha256Equal(
358-
filename, "4f9e8c917b4050f121ac81e9a2bb65723ef09a1b90b35d93792ac3a62a60efa3"
358+
filename, "a37b90685600ccfa56cc5405d1e9a3729ed21dfb31c76fd356e491e2af989566"
359359
)
360360

361361
def test_python_requires_wheel(self):
@@ -380,7 +380,7 @@ def test_python_requires_wheel(self):
380380
""",
381381
)
382382
self.assertFileSha256Equal(
383-
filename, "9bfe8197d379f88715458a75e45c1f521a8b9d3cc43fe19b407c4ab207228b7c"
383+
filename, "529afa454113572e6cd91f069cc9cfe5c28369f29cd495fff19d0ecce389d8e4"
384384
)
385385

386386
def test_python_abi3_binary_wheel(self):
@@ -445,7 +445,7 @@ def test_rule_creates_directory_and_is_included_in_wheel(self):
445445
],
446446
)
447447
self.assertFileSha256Equal(
448-
filename, "8ad5f639cc41ac6ac67eb70f6553a7fdecabaf3a1b952c3134eaea59610c2a64"
448+
filename, "cc9484d527075f07651ca0e7dff4a185c1314020726bcad55fe28d1bba0fec2e"
449449
)
450450

451451
def test_rule_expands_workspace_status_keys_in_wheel_metadata(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy