diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index bc10760077f..052ac2cabba 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -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 ) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index b74a9abf709..4d03ced5be2 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -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): diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index 309370326b2..ef0ab68858a 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -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 @@ -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