Skip to content

Commit 2e082f9

Browse files
committed
Limit support for directories as PEP508 dependencies
1 parent 31c1f4f commit 2e082f9

File tree

3 files changed

+14
-73
lines changed

3 files changed

+14
-73
lines changed

src/pip/_internal/req/constructors.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,20 @@ def install_req_from_req_string(
435435
)
436436

437437
if req.url:
438-
# Create an InstallRequirement for a PEP 508 URL with the same behavior
439-
# as 'pip install req.url'
440-
parts = parse_req_from_line(req.url, None)
441-
constraint = False
442-
443-
return InstallRequirement(
444-
parts.requirement,
445-
comes_from,
446-
link=parts.link,
447-
markers=parts.markers,
448-
use_pep517=use_pep517,
449-
isolated=isolated,
450-
constraint=constraint,
451-
extras=req.extras,
452-
)
438+
# Create an InstallRequirement for a wheel-like PEP 508 URL with the
439+
# same behavior as 'pip install req.url'
440+
parts = parse_req_from_line(req.url, comes_from)
441+
link = Link(req.url)
442+
if link.is_wheel:
443+
return InstallRequirement(
444+
parts.requirement,
445+
comes_from=comes_from,
446+
link=parts.link,
447+
markers=parts.markers,
448+
use_pep517=use_pep517,
449+
isolated=isolated,
450+
extras=req.extras,
451+
)
453452
return InstallRequirement(
454453
req, comes_from, isolated=isolated, use_pep517=use_pep517
455454
)

tests/functional/test_install.py

-38
Original file line numberDiff line numberDiff line change
@@ -1623,44 +1623,6 @@ def test_install_pep508_with_url_in_install_requires_url_change_wheel(script):
16231623
assert "Requirement already satisfied: dep==2.0" in str(res), str(res)
16241624

16251625

1626-
def test_install_pep508_with_url_in_install_requires_url_change_directory(
1627-
script):
1628-
dep_v1_path = create_test_package_with_setup(
1629-
script, name='dep', version='1.0',
1630-
)
1631-
1632-
# Rename the package directory so it doesn't get overwritten when
1633-
# creating the package for dep_v2
1634-
dep_v1_path.rename(dep_v1_path.parent / 'dep_v1')
1635-
dep_v1_path = dep_v1_path.parent / 'dep_v1'
1636-
1637-
dep_v2_path = create_test_package_with_setup(
1638-
script, name='dep', version='2.0',
1639-
)
1640-
1641-
pkga_path = create_basic_wheel_for_package(
1642-
script, name='pkga', version='1.0',
1643-
depends=['dep@' + path_to_url(dep_v1_path)],
1644-
)
1645-
res = script.pip('install', pkga_path)
1646-
assert "Successfully installed dep-1.0" in str(res), str(res)
1647-
1648-
pkga_path.unlink()
1649-
1650-
# Updating the URL to the dependency installs the updated dependency
1651-
pkga_path = create_basic_wheel_for_package(
1652-
script, name='pkga', version='2.0',
1653-
depends=['dep@' + path_to_url(dep_v2_path)],
1654-
)
1655-
res = script.pip('install', pkga_path)
1656-
assert "Successfully installed dep-2.0" in str(res), str(res)
1657-
1658-
res = script.pip('install', pkga_path)
1659-
# pip can't determine versions from a directory name, so it will always
1660-
# reinstall the dependency
1661-
assert "Successfully installed dep-2.0" in str(res), str(res)
1662-
1663-
16641626
@pytest.mark.network
16651627
@pytest.mark.parametrize('index', (PyPI.simple_url, TestPyPI.simple_url))
16661628
def test_install_from_test_pypi_with_ext_url_dep_is_blocked(script, index):

tests/unit/test_req_install.py

-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pip._internal.req.constructors import (
99
install_req_from_line,
1010
install_req_from_req_string,
11-
path_to_url,
1211
)
1312
from pip._internal.req.req_install import InstallRequirement
1413

@@ -151,22 +150,3 @@ def test_install_req_from_string_pep508_url_wheel_extras(self, use_pep517):
151150
assert install_req.is_wheel
152151
assert install_req.use_pep517 == use_pep517
153152
assert install_req.extras == {"security"}
154-
155-
@pytest.mark.parametrize("use_pep517", [None, True, False])
156-
def test_install_req_from_string_pep508_url_not_a_wheel(
157-
self, use_pep517, tmpdir):
158-
"""
159-
install_req_from_string returns an InstallRequirement() with
160-
``.req = None`` so that the package is always reinstalled.
161-
"""
162-
file_url = path_to_url(tmpdir / "fake_torch_package")
163-
install_str = "torch@ " + file_url
164-
install_req = install_req_from_req_string(
165-
install_str, use_pep517=use_pep517
166-
)
167-
168-
assert isinstance(install_req, InstallRequirement)
169-
assert install_req.req is None
170-
assert install_req.link.url == file_url
171-
assert not install_req.is_wheel
172-
assert install_req.use_pep517 == use_pep517

0 commit comments

Comments
 (0)