Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.1] fix: Broken cache on Windows #4549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
)

Expand All @@ -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)),
)
)
Expand Down
31 changes: 31 additions & 0 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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