Skip to content

Commit

Permalink
PR feedback and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rouge8 committed Apr 18, 2019
1 parent 62a7ecc commit e2bbd12
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def install_req_from_req_string(
)

if req.url:
# Create an InstallRequirement for a PEP 508 URL with the same behavior
# as 'pip install req.url'
return install_req_from_line(
req.url, comes_from=comes_from, isolated=isolated,
wheel_cache=wheel_cache, use_pep517=use_pep517
Expand Down
36 changes: 25 additions & 11 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,17 +1391,25 @@ def test_install_pep508_with_url_in_install_requires(script):
assert "Successfully installed packaging-15.3" in str(res), str(res)


def test_install_pep508_with_url_in_install_requires_url_change(script):
dep_v1_path = create_basic_wheel_for_package(
script, name='dep', version='1.0',
)
dep_v2_path = create_basic_wheel_for_package(
script, name='dep', version='2.0',
)
@pytest.mark.parametrize('create_dep, format', [
(create_test_package_with_setup, 'directory'),
(create_basic_wheel_for_package, 'wheel'),
])
def test_install_pep508_with_url_in_install_requires_url_change(
create_dep, format, script):
dep_v1_path = create_dep(script, name='dep', version='1.0')

if format == 'directory':
# Rename the package directory so it doesn't get overwritten when
# creating the package for dep_v2
dep_v1_path.move(dep_v1_path.folder / 'dep_v1')
dep_v1_path = dep_v1_path.folder / 'dep_v1'

dep_v2_path = create_dep(script, name='dep', version='2.0')

pkga_path = create_basic_wheel_for_package(
script, name='pkga', version='1.0',
depends=['dep @ file://%s' % dep_v1_path],
depends=['dep @ ' + path_to_url(dep_v1_path)],
)
res = script.pip('install', pkga_path)
assert "Successfully installed dep-1.0" in str(res), str(res)
Expand All @@ -1411,14 +1419,20 @@ def test_install_pep508_with_url_in_install_requires_url_change(script):
# Updating the URL to the dependency installs the updated dependency
pkga_path = create_basic_wheel_for_package(
script, name='pkga', version='2.0',
depends=['dep @ file://%s' % dep_v2_path],
depends=['dep @ ' + path_to_url(dep_v2_path)],
)
res = script.pip('install', pkga_path)
assert "Successfully installed dep-2.0" in str(res), str(res)

# The dependency is not reinstalled if the URL doesn't change
res = script.pip('install', pkga_path)
assert "Requirement already satisfied: dep==2.0" in str(res), str(res)
if format == 'directory':
# pip can't determine versions from a directory name, so it will always
# reinstall the dependency
assert "Successfully installed dep-2.0" in str(res), str(res)
else:
# pip can determine the version from a wheel's filename, so the
# dependency is not reinstalled if the URL doesn't change
assert "Requirement already satisfied: dep==2.0" in str(res), str(res)


@pytest.mark.network
Expand Down
40 changes: 39 additions & 1 deletion tests/unit/test_req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pip._vendor.packaging.requirements import Requirement

from pip._internal.req.constructors import (
install_req_from_line, install_req_from_req_string,
install_req_from_line, install_req_from_req_string, path_to_url,
)
from pip._internal.req.req_install import InstallRequirement

Expand Down Expand Up @@ -92,3 +92,41 @@ def test_install_req_from_string_with_comes_from_without_link(self):
assert install_req.link.url == wheel_url
assert install_req.req.url is None
assert install_req.is_wheel

@pytest.mark.parametrize("use_pep517", [None, True, False])
def test_install_req_from_string_pep508_url_wheel(self, use_pep517):
"""
install_req_from_string parses the version from PEP 508 URLs that point
to wheels so that updating the URL reinstalls the package.
"""
wheel_url = ("https://download.pytorch.org/whl/cu90/"
"torch-1.0.0-cp36-cp36m-win_amd64.whl")
install_str = "torch@ " + wheel_url
install_req = install_req_from_req_string(
install_str, use_pep517=use_pep517
)

assert isinstance(install_req, InstallRequirement)
assert str(install_req.req) == "torch==1.0.0"
assert install_req.link.url == wheel_url
assert install_req.is_wheel
assert install_req.use_pep517 == use_pep517

@pytest.mark.parametrize("use_pep517", [None, True, False])
def test_install_req_from_string_pep508_url_not_a_wheel(
self, use_pep517, tmpdir):
"""
install_req_from_string returns an InstallRequirement() with
``.req = None`` so that the package is always reinstalled.
"""
file_url = path_to_url(tmpdir / "fake_torch_package")
install_str = "torch@ " + file_url
install_req = install_req_from_req_string(
install_str, use_pep517=use_pep517
)

assert isinstance(install_req, InstallRequirement)
assert install_req.req is None
assert install_req.link.url == file_url
assert not install_req.is_wheel
assert install_req.use_pep517 == use_pep517

0 comments on commit e2bbd12

Please sign in to comment.