Skip to content

Commit

Permalink
Allow and warn on RECORD lines with more than three elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Jan 24, 2019
1 parent 8074db8 commit 7f25059
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/6165.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow ``RECORD`` lines with more than three elements, and display a warning.
15 changes: 11 additions & 4 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,24 @@ def sorted_outrows(outrows):
def get_csv_rows_for_installed(
old_csv_rows, # type: Iterable[List[str]]
installed, # type: Dict[str, str]
changed, # set
changed, # type: set
generated, # type: List[str]
lib_dir,
lib_dir, # type: str
):
# type: (...) -> List[InstalledCSVRow]
installed_rows = [] # type: List[InstalledCSVRow]
for fpath, digest, length in old_csv_rows:
for row in old_csv_rows:
if len(row) > 3:
logger.warning(
'RECORD line has more than three elements: {}'.format(row)
)
fpath = row[0]
fpath = installed.pop(fpath, fpath)
if fpath in changed:
digest, length = rehash(fpath)
installed_rows.append((fpath, digest, str(length)))
row[1] = digest
row[2] = length
installed_rows.append(tuple(row))
for f in generated:
digest, length = rehash(f)
installed_rows.append((normpath(f, lib_dir), digest, str(length)))
Expand Down
23 changes: 20 additions & 3 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def call_get_csv_rows_for_installed(tmpdir, text):
return outrows


def test_get_csv_rows_for_installed(tmpdir):
def test_get_csv_rows_for_installed(tmpdir, caplog):
text = textwrap.dedent("""\
a,b,c
d,e,f
Expand All @@ -108,15 +108,32 @@ def test_get_csv_rows_for_installed(tmpdir):
('d', 'e', 'f'),
]
assert outrows == expected
# Check there were no warnings.
assert len(caplog.records) == 0


def test_get_csv_rows_for_installed__long_lines(tmpdir):
def test_get_csv_rows_for_installed__long_lines(tmpdir, caplog):
text = textwrap.dedent("""\
a,b,c,d
e,f,g,h
e,f,g
h,i,j,k
""")
outrows = call_get_csv_rows_for_installed(tmpdir, text)

expected = [
('a', 'b', 'c', 'd'),
('e', 'f', 'g'),
('h', 'i', 'j', 'k'),
]
assert outrows == expected

messages = [rec.message for rec in caplog.records]
expected = [
"RECORD line has more than three elements: ['a', 'b', 'c', 'd']",
"RECORD line has more than three elements: ['h', 'i', 'j', 'k']"
]
assert messages == expected


def test_wheel_version(tmpdir, data):
future_wheel = 'futurewheel-1.9-py2.py3-none-any.whl'
Expand Down

0 comments on commit 7f25059

Please sign in to comment.