Skip to content

Commit

Permalink
Fixed wheel pack duplicating WHEEL contents on build number change
Browse files Browse the repository at this point in the history
Fixes #415.
  • Loading branch information
agronholm committed Aug 15, 2021
1 parent b8c4aa0 commit 3f1a73a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/news.rst
@@ -1,6 +1,10 @@
Release Notes
=============

**UNRELEASED**

- Fixed ``wheel pack`` duplicating the ``WHEEL`` contents when the build number has changed (#415)

**0.37.0 (2021-08-09)**

- Added official Python 3.10 support
Expand Down
5 changes: 4 additions & 1 deletion src/wheel/cli/pack.py
Expand Up @@ -57,9 +57,12 @@ def pack(directory, dest_dir, build_number):
replacement = ('Build: %s\r\n' % build_number).encode('ascii') if build_number else b''
with open(wheel_file_path, 'rb+') as f:
wheel_file_content = f.read()
if not BUILD_NUM_RE.subn(replacement, wheel_file_content)[1]:
wheel_file_content, num_replaced = BUILD_NUM_RE.subn(replacement,
wheel_file_content)
if not num_replaced:
wheel_file_content += replacement

f.seek(0)
f.truncate()
f.write(wheel_file_content)

Expand Down
15 changes: 12 additions & 3 deletions tests/cli/test_pack.py
@@ -1,4 +1,5 @@
import os
from textwrap import dedent
from zipfile import ZipFile

import pytest
Expand Down Expand Up @@ -47,7 +48,15 @@ def test_pack(tmpdir_factory, tmpdir, build_tag_arg, existing_build_tag, filenam
assert new_record_lines == old_record_lines

expected_build_num = build_tag_arg or existing_build_tag
expected_wheel_content = dedent("""\
Wheel-Version: 1.0
Generator: bdist_wheel (0.30.0)
Root-Is-Purelib: false
Tag: py2-none-any
Tag: py3-none-any
""".replace('\n', '\r\n'))
if expected_build_num:
assert ('Build: %s\r\n' % expected_build_num).encode() in new_wheel_file_content
else:
assert b'Build: ' not in new_wheel_file_content
expected_wheel_content += 'Build: %s\r\n' % expected_build_num

expected_wheel_content = expected_wheel_content.encode('ascii')
assert new_wheel_file_content == expected_wheel_content

0 comments on commit 3f1a73a

Please sign in to comment.