Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make sure filenames containing commas are quoted when writing RECORD file for wheel #61

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
use csv writer to write RECORD file for wheel package
  • Loading branch information
finswimmer committed Aug 13, 2020
commit ab636c37699191dfcb770c9b4ab0a1f34ebe6f79
12 changes: 9 additions & 3 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import contextlib
import csv
import hashlib
import logging
import os
@@ -37,7 +38,6 @@


class WheelBuilder(Builder):

format = "wheel"

def __init__(self, poetry, target_dir=None, original=None):
@@ -179,10 +179,16 @@ def _write_metadata(self, wheel):
def _write_record(self, wheel):
# Write a record of the files in the wheel
with self._write_to_zip(wheel, self.dist_info + "/RECORD") as f:
record = StringIO()
csv_writer = csv.writer(
record, delimiter=",", quotechar='"', lineterminator="\n"
)
for path, hash, size in self._records:
f.write("{},sha256={},{}\n".format(path, hash, size))
csv_writer.writerow((path, "sha256={}".format(hash), size))

# RECORD itself is recorded with no hash or size
f.write(self.dist_info + "/RECORD,,\n")
csv_writer.writerow((self.dist_info + "/RECORD", "", ""))
f.write(record.getvalue())

@property
def dist_info(self): # type: () -> str
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions tests/masonry/builders/fixtures/comma_file/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.poetry]
name = "comma-file"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]

13 changes: 13 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
@@ -198,3 +198,16 @@ def test_wheel_package_pep_561_stub_only_includes_typed_marker():

with zipfile.ZipFile(str(whl)) as z:
assert "pkg-stubs/py.typed" in z.namelist()


def test_wheel_with_file_with_comma():
root = fixtures_dir / "comma_file"
WheelBuilder.make(Factory().create_poetry(root))

whl = root / "dist" / "comma_file-1.2.3-py3-none-any.whl"

assert whl.exists()

with zipfile.ZipFile(str(whl)) as z:
records = z.read("comma_file-1.2.3.dist-info/RECORD")
assert '\n"comma_file/a,b.py"' in records.decode()