Skip to content

Commit

Permalink
Limit support for directories as PEP508 dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rouge8 committed Apr 9, 2020
1 parent 31c1f4f commit 2e082f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 73 deletions.
29 changes: 14 additions & 15 deletions src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,20 @@ 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'
parts = parse_req_from_line(req.url, None)
constraint = False

return InstallRequirement(
parts.requirement,
comes_from,
link=parts.link,
markers=parts.markers,
use_pep517=use_pep517,
isolated=isolated,
constraint=constraint,
extras=req.extras,
)
# Create an InstallRequirement for a wheel-like PEP 508 URL with the
# same behavior as 'pip install req.url'
parts = parse_req_from_line(req.url, comes_from)
link = Link(req.url)
if link.is_wheel:
return InstallRequirement(
parts.requirement,
comes_from=comes_from,
link=parts.link,
markers=parts.markers,
use_pep517=use_pep517,
isolated=isolated,
extras=req.extras,
)
return InstallRequirement(
req, comes_from, isolated=isolated, use_pep517=use_pep517
)
Expand Down
38 changes: 0 additions & 38 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,44 +1623,6 @@ def test_install_pep508_with_url_in_install_requires_url_change_wheel(script):
assert "Requirement already satisfied: dep==2.0" in str(res), str(res)


def test_install_pep508_with_url_in_install_requires_url_change_directory(
script):
dep_v1_path = create_test_package_with_setup(
script, name='dep', version='1.0',
)

# Rename the package directory so it doesn't get overwritten when
# creating the package for dep_v2
dep_v1_path.rename(dep_v1_path.parent / 'dep_v1')
dep_v1_path = dep_v1_path.parent / 'dep_v1'

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

pkga_path = create_basic_wheel_for_package(
script, name='pkga', version='1.0',
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)

pkga_path.unlink()

# 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@' + path_to_url(dep_v2_path)],
)
res = script.pip('install', pkga_path)
assert "Successfully installed dep-2.0" in str(res), str(res)

res = script.pip('install', pkga_path)
# 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)


@pytest.mark.network
@pytest.mark.parametrize('index', (PyPI.simple_url, TestPyPI.simple_url))
def test_install_from_test_pypi_with_ext_url_dep_is_blocked(script, index):
Expand Down
20 changes: 0 additions & 20 deletions tests/unit/test_req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pip._internal.req.constructors import (
install_req_from_line,
install_req_from_req_string,
path_to_url,
)
from pip._internal.req.req_install import InstallRequirement

Expand Down Expand Up @@ -151,22 +150,3 @@ def test_install_req_from_string_pep508_url_wheel_extras(self, use_pep517):
assert install_req.is_wheel
assert install_req.use_pep517 == use_pep517
assert install_req.extras == {"security"}

@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 2e082f9

Please sign in to comment.