Skip to content

fix for #1825 #1831

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 10 additions & 8 deletions pip/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,29 @@ def from_line(cls, name, comes_from=None, prereleases=None):
)
link = Link(path_to_url(name))

# If the line has an egg= definition, but isn't editable, pull the
# requirement out. Otherwise, assume the name is the req for the non
# URL/path/archive case.
if link and req is None:
url = link.url_without_fragment
# when fragment is None, this will become an 'unnamed' requirement
req = link.egg_fragment
# it's a local file, dir, or url
if link:

url = link.url_without_fragment
# Handle relative file URLs
if link.scheme == 'file' and re.search(r'\.\./', url):
url = path_to_url(os.path.normpath(os.path.abspath(link.path)))

# fail early for invalid or unsupported wheels
# wheel file
if link.ext == wheel_ext:
wheel = Wheel(link.filename) # can raise InvalidWheelFilename
if not wheel.supported():
raise UnsupportedWheel(
"%s is not a supported wheel on this platform." %
wheel.filename
)
req = "%s==%s" % (wheel.name, wheel.version)
else:
# set the req to the egg fragment. when it's not there, this
# will become an 'unnamed' requirement
req = link.egg_fragment

# a requirement specifier
else:
req = name

Expand Down
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/data/src/simplewheel-1.0/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

7 changes: 7 additions & 0 deletions tests/data/src/simplewheel-1.0/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
from setuptools import setup, find_packages

setup(name='simplewheel',
version='1.0',
packages=find_packages()
)
1 change: 1 addition & 0 deletions tests/data/src/simplewheel-1.0/simple/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#dummy
5 changes: 5 additions & 0 deletions tests/data/src/simplewheel-2.0/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0

7 changes: 7 additions & 0 deletions tests/data/src/simplewheel-2.0/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python
from setuptools import setup, find_packages

setup(name='simplewheel',
version='2.0',
packages=find_packages()
)
1 change: 1 addition & 0 deletions tests/data/src/simplewheel-2.0/simple/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#dummy
12 changes: 12 additions & 0 deletions tests/functional/test_install_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,15 @@ def test_wheel_no_compiles_pyc(script, data):
)

assert not any(exists)


def test_install_from_wheel_uninstalls_old_version(script, data):
# regression test for https://github.com/pypa/pip/issues/1825
package = data.packages.join("simplewheel-1.0-py2.py3-none-any.whl")
result = script.pip('install', package, '--no-index', expect_error=True)
package = data.packages.join("simplewheel-2.0-py2.py3-none-any.whl")
result = script.pip('install', package, '--no-index', expect_error=False)
dist_info_folder = script.site_packages / 'simplewheel-2.0.dist-info'
assert dist_info_folder in result.files_created
dist_info_folder = script.site_packages / 'simplewheel-1.0.dist-info'
assert dist_info_folder not in result.files_created
5 changes: 5 additions & 0 deletions tests/unit/test_req.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pip.exceptions import (
PreviousBuildDirError, InvalidWheelFilename, UnsupportedWheel,
)
from pip._vendor import pkg_resources
from pip.download import PipSession
from pip.index import PackageFinder
from pip.log import logger
Expand Down Expand Up @@ -90,6 +91,10 @@ def test_invalid_wheel_requirement_raises(self):
with pytest.raises(InvalidWheelFilename):
InstallRequirement.from_line('invalid.whl')

def test_wheel_requirement_sets_req_attribute(self):
req = InstallRequirement.from_line('simple-0.1-py2.py3-none-any.whl')
assert req.req == pkg_resources.Requirement.parse('simple==0.1')


def test_requirements_data_structure_keeps_order():
requirements = Requirements()
Expand Down