Skip to content

Commit 9972074

Browse files
committed
Use locally cached wheels during install
1 parent 84b7571 commit 9972074

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/poetry/installation/chef.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,10 @@ def should_prepare(self, archive: Path) -> bool:
4141
def is_wheel(self, archive: Path) -> bool:
4242
return archive.suffix == ".whl"
4343

44-
def get_cached_archive_for_link(self, link: Link) -> Link:
45-
# If the archive is already a wheel, there is no need to cache it.
46-
if link.is_wheel:
47-
return link
48-
44+
def get_cached_archive_for_link(self, link: Link) -> Link | None:
4945
archives = self.get_cached_archives_for_link(link)
50-
5146
if not archives:
52-
return link
47+
return None
5348

5449
candidates: list[tuple[float | None, Link]] = []
5550
for archive in archives:
@@ -70,7 +65,7 @@ def get_cached_archive_for_link(self, link: Link) -> Link:
7065
)
7166

7267
if not candidates:
73-
return link
68+
return None
7469

7570
return min(candidates)[1]
7671

src/poetry/installation/executor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@ def _download(self, operation: Install | Update) -> Link | Path:
616616
def _download_link(self, operation: Install | Update, link: Link) -> Link | Path:
617617
package = operation.package
618618

619-
archive: Link | Path
619+
archive: Link | Path | None
620620
archive = self._chef.get_cached_archive_for_link(link)
621-
if archive is link:
621+
if archive is None:
622622
# No cached distributions was found, so we download and prepare it
623623
try:
624624
archive = self._download_archive(operation, link)

tests/installation/test_chef.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING
55

6+
import pytest
7+
68
from packaging.tags import Tag
79
from poetry.core.packages.utils.link import Link
810

@@ -16,7 +18,22 @@
1618
from tests.conftest import Config
1719

1820

19-
def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture):
21+
@pytest.mark.parametrize(
22+
("link", "cached"),
23+
[
24+
(
25+
"https://files.python-poetry.org/demo-0.1.0.tar.gz",
26+
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
27+
),
28+
(
29+
"https://example.com/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
30+
"file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl",
31+
),
32+
],
33+
)
34+
def test_get_cached_archive_for_link(
35+
config: Config, mocker: MockerFixture, link: str, cached: str
36+
):
2037
chef = Chef(
2138
config,
2239
MockEnv(
@@ -40,11 +57,9 @@ def test_get_cached_archive_for_link(config: Config, mocker: MockerFixture):
4057
],
4158
)
4259

43-
archive = chef.get_cached_archive_for_link(
44-
Link("https://files.python-poetry.org/demo-0.1.0.tar.gz")
45-
)
60+
archive = chef.get_cached_archive_for_link(Link(link))
4661

47-
assert Link("file:///foo/demo-0.1.0-cp38-cp38-macosx_10_15_x86_64.whl") == archive
62+
assert Link(cached) == archive
4863

4964

5065
def test_get_cached_archives_for_link(config: Config, mocker: MockerFixture):

tests/installation/test_executor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def test_executor_should_delete_incomplete_downloads(
369369
)
370370
mocker.patch(
371371
"poetry.installation.chef.Chef.get_cached_archive_for_link",
372-
side_effect=lambda link: link,
372+
side_effect=lambda link: None,
373373
)
374374
mocker.patch(
375375
"poetry.installation.chef.Chef.get_cache_directory_for_link",

0 commit comments

Comments
 (0)