Skip to content

Commit

Permalink
req: fix possible exception in install_req_from_req
Browse files Browse the repository at this point in the history
* allow calling it with `comes_from=None` (easier for testing)
* handle the case where `comes_from.link is None` (which can happen
  if a package using a PEP 508 URL requirement is already installed)
  • Loading branch information
benoit-pierre authored and ircwaves committed Dec 12, 2018
1 parent 5e5904e commit 590fdba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/5889.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix exception when installing a package depending on an already installed dependency using a PEP 508 requirement.
3 changes: 2 additions & 1 deletion src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def install_req_from_req(
PyPI.file_storage_domain,
TestPyPI.file_storage_domain,
]
if req.url and comes_from.link.netloc in domains_not_allowed:
if req.url and comes_from and comes_from.link \
and comes_from.link.netloc in domains_not_allowed:
# Explicitly disallow pypi packages that depend on external urls
raise InstallationError(
"Packages installed from PyPI cannot depend on packages "
Expand Down
31 changes: 31 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,37 @@ def test_install_pep508_with_url_in_install_requires(script):
assert "Successfully installed packaging-15.3" in str(res), str(res)


def test_pep508_url_already_installed(script):
pkgA_path = create_basic_wheel_for_package(
script,
name='pkgA', version='1.0',
depends=[], extras={},
)
pkgA_file_url = path_to_url(pkgA_path)
assert pkgA_file_url.startswith('file:///')
pkgA_file_url = 'file://localhost/' + pkgA_file_url[8:]
pkgB_path = create_basic_wheel_for_package(
script,
name='pkgB', version='2.0',
depends=['pkgA @ %s' % pkgA_file_url],
extras={},
)
pkgC_path = create_basic_wheel_for_package(
script,
name='pkgC', version='3.0',
depends=['pkgB'],
extras={},
)
r = script.pip_install_local(
'-v', pkgB_path
)
assert "Successfully installed pkgA-1.0 pkgB-2.0" in r.stdout, str(r)
r = script.pip_install_local(
'-v', pkgC_path
)
assert "Successfully installed pkgC-3.0" in r.stdout, str(r)


@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

0 comments on commit 590fdba

Please sign in to comment.