mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Raise UnsupportedWheel when .dist-info doesn't match name
This aligns with the previous behavior that would have enforced the found .dist-info directory starting with the name of the package. We raise UnsupportedWheel because it looks better in output than the AssertionError (which includes traceback).
This commit is contained in:
parent
0d865d8fe3
commit
e5495cf6a1
|
@ -22,6 +22,7 @@ from email.parser import Parser
|
|||
from pip._vendor import pkg_resources
|
||||
from pip._vendor.distlib.scripts import ScriptMaker
|
||||
from pip._vendor.distlib.util import get_export_entry
|
||||
from pip._vendor.packaging.utils import canonicalize_name
|
||||
from pip._vendor.six import StringIO
|
||||
|
||||
from pip._internal.exceptions import InstallationError, UnsupportedWheel
|
||||
|
@ -314,8 +315,10 @@ def install_unpacked_wheel(
|
|||
:param pycompile: Whether to byte-compile installed Python files
|
||||
:param warn_script_location: Whether to check that scripts are installed
|
||||
into a directory on PATH
|
||||
:raises UnsupportedWheel: when the directory holds an unpacked wheel with
|
||||
incompatible Wheel-Version
|
||||
:raises UnsupportedWheel:
|
||||
* when the directory holds an unpacked wheel with incompatible
|
||||
Wheel-Version
|
||||
* when the .dist-info dir does not match the wheel
|
||||
"""
|
||||
# TODO: Investigate and break this up.
|
||||
# TODO: Look into moving this into a dedicated class for representing an
|
||||
|
@ -443,6 +446,15 @@ def install_unpacked_wheel(
|
|||
req_description
|
||||
)
|
||||
|
||||
info_dir_name = canonicalize_name(os.path.basename(info_dir[0]))
|
||||
canonical_name = canonicalize_name(name)
|
||||
if not info_dir_name.startswith(canonical_name):
|
||||
raise UnsupportedWheel(
|
||||
"{} .dist-info directory {!r} does not start with {!r}".format(
|
||||
req_description, os.path.basename(info_dir[0]), canonical_name
|
||||
)
|
||||
)
|
||||
|
||||
# Get the defined entry points
|
||||
ep_file = os.path.join(info_dir[0], 'entry_points.txt')
|
||||
console, gui = get_entrypoints(ep_file)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import distutils
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -451,3 +452,23 @@ def test_wheel_install_fails_with_extra_dist_info(script):
|
|||
"install", "--no-cache-dir", "--no-index", package, expect_error=True
|
||||
)
|
||||
assert "Multiple .dist-info directories" in result.stderr
|
||||
|
||||
|
||||
def test_wheel_install_fails_with_unrelated_dist_info(script):
|
||||
package = create_basic_wheel_for_package(script, "simple", "0.1.0")
|
||||
new_name = "unrelated-2.0.0-py2.py3-none-any.whl"
|
||||
new_package = os.path.join(os.path.dirname(package), new_name)
|
||||
shutil.move(package, new_package)
|
||||
|
||||
result = script.pip(
|
||||
"install",
|
||||
"--no-cache-dir",
|
||||
"--no-index",
|
||||
new_package,
|
||||
expect_error=True,
|
||||
)
|
||||
|
||||
assert (
|
||||
"'simple-0.1.0.dist-info' does not start with 'unrelated'"
|
||||
in result.stderr
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue