8000 Fix leading forward slashes in RECORD files produced by `py_wheel`. (… · uventura/rules_python@599ddb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 599ddb8

Browse files
authored
Fix leading forward slashes in RECORD files produced by py_wheel. (bazel-contrib#789)
1 parent d7ae311 commit 599ddb8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

examples/wheel/wheel_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ def test_custom_package_root_wheel(self):
238238
],
239239
)
240240

241+
record_contents = zf.read(
242+
"examples_custom_package_root-0.0.1.dist-info/RECORD"
243+
).decode("utf-8")
244+
245+
# Ensure RECORD files do not have leading forward slashes
246+
for line in record_contents.splitlines():
247+
self.assertFalse(line.startswith("/"))
248+
241249
def test_custom_package_root_multi_prefix_wheel(self):
242250
filename = os.path.join(
243251
os.environ["TEST_SRCDIR"],
@@ -261,6 +269,14 @@ def test_custom_package_root_multi_prefix_wheel(self):
261269
],
262270
)
263271

272+
record_contents = zf.read(
273+
"example_custom_package_root_multi_prefix-0.0.1.dist-info/RECORD"
274+
).decode("utf-8")
275+
276+
# Ensure RECORD files do not have leading forward slashes
277+
for line in record_contents.splitlines():
278+
self.assertFalse(line.startswith("/"))
279+
264280
def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
265281
filename = os.path.join(
266282
os.environ["TEST_SRCDIR"],
@@ -284,6 +300,14 @@ def test_custom_package_root_multi_prefix_reverse_order_wheel(self):
284300
],
285301
)
286302

303+
record_contents = zf.read(
304+
"example_custom_package_root_multi_prefix_reverse_order-0.0.1.dist-info/RECORD"
305+
).decode("utf-8")
306+
307+
# Ensure RECORD files do not have leading forward slashes
308+
for line in record_contents.splitlines():
309+
self.assertFalse(line.startswith("/"))
310+
287311
def test_python_requires_wheel(self):
288312
filename = os.path.join(
289313
os.environ["TEST_SRCDIR"],

tools/wheelmaker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def add_recordfile(self):
214214
contents = b""
215215
for filename, digest, size in entries:
216216
if sys.version_info[0] > 2 and isinstance(filename, str):
217-
filename = filename.encode("utf-8", "surrogateescape")
217+
filename = filename.lstrip("/").encode("utf-8", "surrogateescape")
218218
contents += b"%s,%s,%s\n" % (filename, digest, size)
219219
self.add_string(record_path, contents)
220220

0 commit comments

Comments
 (0)
0