Skip to content

Commit 3f1a73a

Browse files
committed
Fixed wheel pack duplicating WHEEL contents on build number change
Fixes #415.
1 parent b8c4aa0 commit 3f1a73a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/news.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Release Notes
22
=============
33

4+
**UNRELEASED**
5+
6+
- Fixed ``wheel pack`` duplicating the ``WHEEL`` contents when the build number has changed (#415)
7+
48
**0.37.0 (2021-08-09)**
59

610
- Added official Python 3.10 support

src/wheel/cli/pack.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ def pack(directory, dest_dir, build_number):
5757
replacement = ('Build: %s\r\n' % build_number).encode('ascii') if build_number else b''
5858
with open(wheel_file_path, 'rb+') as f:
5959
wheel_file_content = f.read()
60-
if not BUILD_NUM_RE.subn(replacement, wheel_file_content)[1]:
60+
wheel_file_content, num_replaced = BUILD_NUM_RE.subn(replacement,
61+
wheel_file_content)
62+
if not num_replaced:
6163
wheel_file_content += replacement
6264

65+
f.seek(0)
6366
f.truncate()
6467
f.write(wheel_file_content)
6568

tests/cli/test_pack.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from textwrap import dedent
23
from zipfile import ZipFile
34

45
import pytest
@@ -47,7 +48,15 @@ def test_pack(tmpdir_factory, tmpdir, build_tag_arg, existing_build_tag, filenam
4748
assert new_record_lines == old_record_lines
4849

4950
expected_build_num = build_tag_arg or existing_build_tag
51+
expected_wheel_content = dedent("""\
52+
Wheel-Version: 1.0
53+
Generator: bdist_wheel (0.30.0)
54+
Root-Is-Purelib: false
55+
Tag: py2-none-any
56+
Tag: py3-none-any
57+
""".replace('\n', '\r\n'))
5058
if expected_build_num:
51-
assert ('Build: %s\r\n' % expected_build_num).encode() in new_wheel_file_content
52-
else:
53-
assert b'Build: ' not in new_wheel_file_content
59+
expected_wheel_content += 'Build: %s\r\n' % expected_build_num
60+
61+
expected_wheel_content = expected_wheel_content.encode('ascii')
62+
assert new_wheel_file_content == expected_wheel_content

0 commit comments

Comments
 (0)