diff --git a/poetry/installation/executor.py b/poetry/installation/executor.py index 79bf4e34a49..d90895db551 100644 --- a/poetry/installation/executor.py +++ b/poetry/installation/executor.py @@ -11,6 +11,7 @@ from poetry.core.packages.file_dependency import FileDependency from poetry.core.packages.utils.link import Link +from poetry.core.packages.utils.utils import url_to_path from poetry.core.pyproject.toml import PyProjectTOML from poetry.io.null_io import NullIO from poetry.utils._compat import PY2 @@ -611,16 +612,14 @@ def _download_link(self, operation, link): hashes = {f["hash"] for f in package.files} hash_types = {h.split(":")[0] for h in hashes} archive_hashes = set() + archive_path = ( + url_to_path(archive.url) if isinstance(archive, Link) else archive + ) for hash_type in hash_types: archive_hashes.add( "{}:{}".format( hash_type, - FileDependency( - package.name, - Path(archive.path) - if isinstance(archive, Link) - else archive, - ).hash(hash_type), + FileDependency(package.name, archive_path).hash(hash_type), ) ) @@ -629,7 +628,7 @@ def _download_link(self, operation, link): "Invalid hashes ({}) for {} using archive {}. Expected one of {}.".format( ", ".join(sorted(archive_hashes)), package, - archive.name, + archive_path.name, ", ".join(sorted(hashes)), ) ) diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index c892b92ee3e..fb504dbcb8b 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -327,3 +327,34 @@ def test_executor_should_check_every_possible_hash_types_before_failing( Install(package), Link("https://example.com/demo-0.1.0-py2.py3-none-any.whl"), ) + + +def test_executor_should_use_cached_link_and_hash( + config, io, pool, mocker, fixture_dir, tmp_dir +): + # Produce a file:/// URI that is a valid link + link_cached = Link( + fixture_dir("distributions") + .joinpath("demo-0.1.0-py2.py3-none-any.whl") + .as_uri() + ) + mocker.patch.object( + Chef, "get_cached_archive_for_link", side_effect=lambda _: link_cached + ) + + env = MockEnv(path=Path(tmp_dir)) + executor = Executor(env, pool, config, io) + + package = Package("demo", "0.1.0") + package.files = [ + { + "file": "demo-0.1.0-py2.py3-none-any.whl", + "hash": "md5:15507846fd4299596661d0197bfb4f90", + } + ] + + archive = executor._download_link( + Install(package), Link("https://example.com/demo-0.1.0-py2.py3-none-any.whl") + ) + + assert archive == link_cached