# HG changeset patch # Parent 000a50c88013c6a0d5ef6ea55e94f0a612f43161 Fix issue 13175 - _write_record_file now opens the file with newline='' diff -r 000a50c88013 Lib/packaging/tests/test_util.py --- a/Lib/packaging/tests/test_util.py Sun Oct 16 14:51:24 2011 +0100 +++ b/Lib/packaging/tests/test_util.py Sun Oct 16 15:22:43 2011 +0100 @@ -770,6 +770,24 @@ for mfile in metadata_file_paths: self.assertTrue(os.path.isfile(mfile)) + def test_issue_13175(self): + # RECORD file must have correct line endings + # This test will probably only fail on Windows even if the bug is + # still present... + distinfo = 'hello-0.1.1-py3.3.dist-info' + egginfo = 'hello-0.1.1-py3.3.egg-info' + # egginfo is a file in distutils which contains the metadata + files = ['hello.py', 'hello.pyc', egginfo] + + tempdir, record_file = self.build_dist_tree(files, dirs=[]) + record_path = os.path.join(tempdir, distinfo, 'RECORD') + + egginfo_to_distinfo(record_file) + + # test that the record file has correct line endings + with open(record_path, 'rb') as rec: + self.assertTrue(b'\r\r\n' not in rec.read()) + def build_dist_tree(self, files, dirs): tempdir = self.mkdtemp() record_file_path = os.path.join(tempdir, 'RECORD') diff -r 000a50c88013 Lib/packaging/util.py --- a/Lib/packaging/util.py Sun Oct 16 14:51:24 2011 +0100 +++ b/Lib/packaging/util.py Sun Oct 16 15:22:43 2011 +0100 @@ -1092,7 +1092,7 @@ def _write_record_file(record_path, installed_files): - with open(record_path, 'w', encoding='utf-8') as f: + with open(record_path, 'w', newline='', encoding='utf-8') as f: writer = csv.writer(f, delimiter=',', lineterminator=os.linesep, quotechar='"')