Skip to content

Commit

Permalink
[1.1] fix: Broken cache on Windows (#4549)
Browse files Browse the repository at this point in the history
Backport of #4531, fixes #4163 and #4535.
  • Loading branch information
serverwentdown authored Nov 12, 2021
1 parent fe59f68 commit 3dcbb76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
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

0 comments on commit 3dcbb76

Please sign in to comment.