Skip to content

Commit

Permalink
Fix issue pypa#5868: TypeError in move_wheel_files().
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Oct 14, 2018
1 parent 1228f64 commit e90246b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/5868.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix sorting `TypeError` in `move_wheel_files()` when installing some packages.
10 changes: 9 additions & 1 deletion src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def message_about_scripts_not_on_PATH(scripts):
return "\n".join(msg_lines)


# We need this to avoid TypeError because values at a given tuple index
# can be strings in some rows and integers in others.
def sorted_outrows(outrows):
"""Return the given "outrows" in sorted order."""
return sorted(outrows, key=lambda row: tuple(str(x) for x in row))


def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
pycompile=True, scheme=None, isolated=False, prefix=None,
warn_script_location=True):
Expand Down Expand Up @@ -511,7 +518,8 @@ def _get_script_text(entry):
outrows.append((normpath(f, lib_dir), digest, length))
for f in installed:
outrows.append((installed[f], '', ''))
for row in sorted(outrows):
# Sort to simplify testing.
for row in sorted_outrows(outrows):
writer.writerow(row)
shutil.move(temp_record, record)

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ def test_get_entrypoints(tmpdir, console_scripts):
)


@pytest.mark.parametrize("outrows, expected", [
([
('', '', 'a'),
('', '', ''),
], [
('', '', ''),
('', '', 'a'),
]),
([
# Include an int to check avoiding the following error:
# > TypeError: '<' not supported between instances of 'str' and 'int'
('', '', 1),
('', '', ''),
], [
('', '', ''),
('', '', 1),
]),
])
def test_sorted_outrows(outrows, expected):
actual = wheel.sorted_outrows(outrows)
assert actual == expected


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

0 comments on commit e90246b

Please sign in to comment.