Skip to content

Commit

Permalink
Fixed CRLF being used when generating WHEEL files on Windows (#383)
Browse files Browse the repository at this point in the history
Fixes #378.
  • Loading branch information
agronholm authored Nov 29, 2020
1 parent e8cff0b commit b3ae92c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Release Notes

- Added official Python 3.9 support
- Updated vendored ``packaging`` library to v20.7
- Switched to always using LF as line separator when generating ``WHEEL`` files
(on Windows, CRLF was being used instead)

**0.35.1 (2020-08-14)**

Expand Down
12 changes: 9 additions & 3 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import re
import warnings
from collections import OrderedDict
from email.generator import Generator
from distutils.core import Command
from distutils import log as logger
from io import BytesIO
from glob import iglob
from shutil import rmtree
from sysconfig import get_config_var
Expand All @@ -29,6 +29,10 @@
from .wheelfile import WheelFile
from . import __version__ as wheel_version

if sys.version_info < (3,):
from email.generator import Generator as BytesGenerator
else:
from email.generator import BytesGenerator

safe_name = pkg_resources.safe_name
safe_version = pkg_resources.safe_version
Expand Down Expand Up @@ -381,8 +385,10 @@ def write_wheelfile(self, wheelfile_base, generator='bdist_wheel (' + wheel_vers

wheelfile_path = os.path.join(wheelfile_base, 'WHEEL')
logger.info('creating %s', wheelfile_path)
with open(wheelfile_path, 'w') as f:
Generator(f, maxheaderlen=0).flatten(msg)
buffer = BytesIO()
BytesGenerator(buffer, maxheaderlen=0).flatten(msg)
with open(wheelfile_path, 'wb') as f:
f.write(buffer.getvalue().replace(b'\r\n', b'\r'))

def _ensure_relative(self, path):
# copied from dir_util, deleted
Expand Down
8 changes: 8 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,11 @@ def test_compression(dummy_dist, monkeypatch, tmpdir, option, compress_type):
assert 'dummy_dist-1.0.dist-info/METADATA' in filenames
for zinfo in wf.filelist:
assert zinfo.compress_type == compress_type


def test_wheelfile_line_endings(wheel_paths):
for path in wheel_paths:
with WheelFile(path) as wf:
wheelfile = next(fn for fn in wf.filelist if fn.filename.endswith('WHEEL'))
wheelfile_contents = wf.read(wheelfile)
assert b'\r' not in wheelfile_contents

0 comments on commit b3ae92c

Please sign in to comment.