Skip to content

Commit 7f25059

Browse files
committed
Allow and warn on RECORD lines with more than three elements.
1 parent 8074db8 commit 7f25059

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

news/6165.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow ``RECORD`` lines with more than three elements, and display a warning.

src/pip/_internal/wheel.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,24 @@ def sorted_outrows(outrows):
262262
def get_csv_rows_for_installed(
263263
old_csv_rows, # type: Iterable[List[str]]
264264
installed, # type: Dict[str, str]
265-
changed, # set
265+
changed, # type: set
266266
generated, # type: List[str]
267-
lib_dir,
267+
lib_dir, # type: str
268268
):
269269
# type: (...) -> List[InstalledCSVRow]
270270
installed_rows = [] # type: List[InstalledCSVRow]
271-
for fpath, digest, length in old_csv_rows:
271+
for row in old_csv_rows:
272+
if len(row) > 3:
273+
logger.warning(
274+
'RECORD line has more than three elements: {}'.format(row)
275+
)
276+
fpath = row[0]
272277
fpath = installed.pop(fpath, fpath)
273278
if fpath in changed:
274279
digest, length = rehash(fpath)
275-
installed_rows.append((fpath, digest, str(length)))
280+
row[1] = digest
281+
row[2] = length
282+
installed_rows.append(tuple(row))
276283
for f in generated:
277284
digest, length = rehash(f)
278285
installed_rows.append((normpath(f, lib_dir), digest, str(length)))

tests/unit/test_wheel.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def call_get_csv_rows_for_installed(tmpdir, text):
9696
return outrows
9797

9898

99-
def test_get_csv_rows_for_installed(tmpdir):
99+
def test_get_csv_rows_for_installed(tmpdir, caplog):
100100
text = textwrap.dedent("""\
101101
a,b,c
102102
d,e,f
@@ -108,15 +108,32 @@ def test_get_csv_rows_for_installed(tmpdir):
108108
('d', 'e', 'f'),
109109
]
110110
assert outrows == expected
111+
# Check there were no warnings.
112+
assert len(caplog.records) == 0
111113

112114

113-
def test_get_csv_rows_for_installed__long_lines(tmpdir):
115+
def test_get_csv_rows_for_installed__long_lines(tmpdir, caplog):
114116
text = textwrap.dedent("""\
115117
a,b,c,d
116-
e,f,g,h
118+
e,f,g
119+
h,i,j,k
117120
""")
118121
outrows = call_get_csv_rows_for_installed(tmpdir, text)
119122

123+
expected = [
124+
('a', 'b', 'c', 'd'),
125+
('e', 'f', 'g'),
126+
('h', 'i', 'j', 'k'),
127+
]
128+
assert outrows == expected
129+
130+
messages = [rec.message for rec in caplog.records]
131+
expected = [
132+
"RECORD line has more than three elements: ['a', 'b', 'c', 'd']",
133+
"RECORD line has more than three elements: ['h', 'i', 'j', 'k']"
134+
]
135+
assert messages == expected
136+
120137

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

0 commit comments

Comments
 (0)